custom-attributes

Does using custom data attributes produce browser compatibility issues?

℡╲_俬逩灬. 提交于 2019-12-05 20:25:59
问题 I have to choose between custom data tags or ids. I would like to choose custom data tags, but I want to be sure that they do not cause browser compatibility issues for the most widely used browsers today. I'm using jQuery 1.6 and my particular scenario involves a situation where I need to reference a commentId for several actions. <div data-comment-id="comment-1" id="comment-1"> <a class="foo"></a> </div> It's easier to extract data tags in jQueryin: $('foo').data('commentId'); Extract a

ASP.NET Core Filters - ignore for defined methods

别等时光非礼了梦想. 提交于 2019-12-05 19:23:38
We implement a log information to our database. I will use a Filters (IActionFilter) functionality for it. I wrote the following class: public class ActionFilter: Attribute, IActionFilter { DateTime start; public void OnActionExecuting(ActionExecutingContext context) { start = DateTime.Now; } public void OnActionExecuted(ActionExecutedContext context) { DateTime end = DateTime.Now; double processTime = end.Subtract(start).TotalMilliseconds; ... some log actions } } Then I have added the following code to the Startup.cs: services.AddMvc(options => { options.Filters.Add(typeof(ActionFilter)); })

C# .NET CORE how to get the value of a custom attribute?

∥☆過路亽.° 提交于 2019-12-05 07:56:24
I have a custom attribute class defined as follows. [AttributeUsage(AttributeTargets.Property, Inherited = false)] internal class EncryptedAttribute : System.Attribute { private bool _encrypted; public EncryptedAttribute(bool encrypted) { _encrypted = encrypted; } public virtual bool Encrypted { get { return _encrypted; } } } I applied the above attribute to another class as follows. public class KeyVaultConfiguration { [Encrypted(true)] public string AuthClientId { get; set; } = ""; public string AuthClientCertThumbprint { get; set; } = ""; } How do I get the value of Encrypted=True on

Advantage of using CustomAttributes vs GetCustomAttributes()

我与影子孤独终老i 提交于 2019-12-05 07:13:42
I noticed today that some new properties had appeared in my intellisense on the System.Type object for my .NET 4.5 projects. Among these was one called CustomAttributes . I was intrigued by this since I previously had understood that GetCustomAttributes was one of the most expensive reflection calls ( DynamicInvoke and the like aside, of course). As I understand it, every call to GetCustomAttributes results in calling the constructors for the attributes (and thus a memory allocation). I've often resorted to caching the custom attributes separately to avoid performance bottlenecks when

Passing a type as parameter to an attribute

二次信任 提交于 2019-12-05 04:09:46
I wrote a somewhat generic deserialization mechanism that allows me to construct objects from a binary file format used by a C++ application. To keep things clean and easy to change, I made a Field class that extends Attribute , is constructed with Field(int offset, string type, int length, int padding) and is applied to the class attributes I wish to deserialize. This is how it looks like : [Field(0x04, "int")] public int ID = 0; [Field(0x08, "string", 0x48)] public string Name = "0"; [Field(0x6C, "byte", 3)] public byte[] Color = { 0, 0, 0 }; [Field(0x70, "int")] public int

Execution Priority in custom Attributes in asp.net mvc

你离开我真会死。 提交于 2019-12-05 01:33:50
I have two custom attributes in my asp.net mvc(C#) application. [CustAttribute1()] [CustAttribute2()] When I use those attributes to my actions, which will get executed first? [CustAttribute1()] [CustAttribute2()] public ActionResult Index() { Can I use more than one custom attributes for my actions? If so, in the above Action, which custom attribute will execute first? Set the Order property. [CustAttribute1(Order=2)] [CustAttribute2(Order=1)] public ActionResult Index() { return View(); } 来源: https://stackoverflow.com/questions/1770550/execution-priority-in-custom-attributes-in-asp-net-mvc

MVC3 - Where to place custom attribute classes

别说谁变了你拦得住时间么 提交于 2019-12-05 01:25:17
I am delving into custom validation attributes and am curious to know how others structure the projects. Where do you typically store custom attributes? My first thought was to simply create a new folder and be done with it. Any suggestions? I use 2 different approaches. Set up a common Class Library to store common validation that will be used on many MVC applications. Then reference this library from your MVC application. You can use http://dataannotationsextensions.org/ to view the source code on how to setup this project. Place them in folders as suggested by Darin. This folder would be

Building CustomAuthorization in ASP.NET MVC

旧街凉风 提交于 2019-12-04 22:37:06
In the DB i have Role and User entities with one to many relationship. What i am trying to do is to build custom authorization filter. All the tutorials that i have seen are using default ASP.NET membership. All i know is that i need to inherit AuthorizationAttribute but do not know which methods do i need to override and how to implement them. public class UserAuth : AuthorizeAttribute { } In the DB : Role public class Role { [Key] public int RoleID { get; set; } [Required] public int RolenameValue { get; set; } [MaxLength(100)] public string Description { get; set; } // // // // // public

TypeBuilder - Adding attributes

坚强是说给别人听的谎言 提交于 2019-12-04 20:18:22
I have a helper class that uses a TypeBuilder to construct a dynamic type. It is used as follows : var tbh = new TypeBuilderHelper("MyType"); tbh.AddProperty<float>("Number", 0.0f); tbh.AddProperty<string>("String", "defaultStringValue"); tbh.Close(); var i1 = tbh.CreateInstance(); var i2 = tbh.CreateInstance(); I now want to add support for property attributes (existing attribute types, not dynamically generated types), along the lines of : public class TypeBuilderHelper { public void AddProperty<T>(string name, T defaultValue, params Attribute[] attributes) { // ... } } public class

Custom section/collection in Web.Config [duplicate]

喜欢而已 提交于 2019-12-04 19:46:57
问题 This question already has answers here : How do I define custom web.config sections with potential child elements and attributes for the properties? (6 answers) Closed 11 hours ago . I've got a bunch of routes that I want to be able to throw in my Web.Config file. I need one key and two value fields for each section/item in the collection. Something along the lines of this... <routes> <add key="AdministrationDefault" url="Administration/" file="~Administration/Default.aspx" /> <add key=