.net-attributes

displayname attribute vs display attribute

独自空忆成欢 提交于 2020-01-08 15:40:30
问题 What is difference between DisplayName attribute and Display attribute in ASP.NET MVC? 回答1: They both give you the same results but the key difference I see is that you cannot specify a ResourceType in DisplayName attribute. For an example in MVC 2, you had to subclass the DisplayName attribute to provide resource via localization. Display attribute (new in MVC3 and .NET4) supports ResourceType overload as an "out of the box" property. 回答2: DisplayName sets the DisplayName in the model

displayname attribute vs display attribute

青春壹個敷衍的年華 提交于 2020-01-08 15:39:57
问题 What is difference between DisplayName attribute and Display attribute in ASP.NET MVC? 回答1: They both give you the same results but the key difference I see is that you cannot specify a ResourceType in DisplayName attribute. For an example in MVC 2, you had to subclass the DisplayName attribute to provide resource via localization. Display attribute (new in MVC3 and .NET4) supports ResourceType overload as an "out of the box" property. 回答2: DisplayName sets the DisplayName in the model

What does [STAThread] do?

大憨熊 提交于 2019-12-17 02:34:09
问题 I am learning C# 3.5 and I want to know what [STAThread] does in our programs? 回答1: The STAThreadAttribute is essentially a requirement for the Windows message pump to communicate with COM components. Although core Windows Forms does not use COM, many components of the OS such as system dialogs do use this technology. MSDN explains the reason in slightly more detail: STAThreadAttribute indicates that the COM threading model for the application is single-threaded apartment. This attribute must

Name of a property as input to attribute constructor

我是研究僧i 提交于 2019-12-11 03:37:41
问题 I have a custom attribute and I would like it to have the name of a property as input. Because the name is a string it is a valid input type (as attributes are quite limited as to what they can have as input to their constructors). But how can I accomplish this? Take this example code: public class MyCustomAttribute : Attribute { public MyCustomAttribute(string propertyName) {} } public class Foo { public bool MyCustomProperty { get; set; } [MyCustom(SomeMagicAppliedToMyCustomProperty)] // I

Simple Injector inject dependency into custom global authentication filters and OWIN middle ware OAuthAuthorizationServerProvider

被刻印的时光 ゝ 提交于 2019-12-08 09:01:26
问题 I used Simple Injector as our Ioc container; we have two problems. We want to inject into our custom authentication filter; we read the post of converting attribute to a passive attribute: Convert Attribute into a passive. But we can't convert custom authentication filter attribute into a passive. public class BearerAuthentication : Attribute, IAuthenticationFilter { public async Task AuthenticateAsync( HttpAuthenticationContext context, CancellationToken cancellationToken) { } public Task

Attribute with params object[] constructor gives inconsistent compiler errors

谁都会走 提交于 2019-12-04 00:57:55
问题 I am getting the error An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type Notice the screenshot below: Notice that if I use the DataRow attribute with one or three parameters, I don't get a compile error. But if I use two parameters and the second parameter is an array of strings, then I do get a compile error. The signatures for DataRowAttribute are public DataRowAttribute (object data1); and public

What's the difference between [Something] and [SomethingAttribute] [duplicate]

≡放荡痞女 提交于 2019-12-01 20:12:48
问题 This question already has answers here : Why can I use the shorthand `[Authorize]` instead of the name of the actual class, `[AuthorizeAttribute]`? [duplicate] (4 answers) Closed 4 years ago . This has probably been already asked but it's hard to search for. What is the difference between [Something] and [SomethingAttribute] ? Both of the following compile: [DefaultValue(false)] public bool Something { get; set; } [DefaultValueAttribute(false)] public bool SomethingElse { get; set; } Are

Attribute with params object[] constructor gives inconsistent compiler errors

谁说胖子不能爱 提交于 2019-12-01 03:41:02
I am getting the error An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type Notice the screenshot below: Notice that if I use the DataRow attribute with one or three parameters, I don't get a compile error. But if I use two parameters and the second parameter is an array of strings, then I do get a compile error. The signatures for DataRowAttribute are public DataRowAttribute (object data1); and public DataRowAttribute (object data1, params object[] moreData); The first one gives me no problem, but the second one

Real world use of custom .NET attributes

萝らか妹 提交于 2019-11-27 16:34:28
问题 What kind of things have you used custom .NET attributes for in the real world? I've read several articles about them, but I have never used custom attributes. I feel like I might be overlooking them when they could be useful. I am talking about attributes that you create, not ones that are already included in the framework. 回答1: I've used them "custom" attributes for validation (ie. marking a field to be validated with my own "credit card validation") and custom LinqToLucene analyzers I've

Enforce Attribute Decoration of Classes/Methods

大城市里の小女人 提交于 2019-11-27 15:56:27
问题 Following on from my recent question on Large, Complex Objects as a Web Service Result. I have been thinking about how I can ensure all future child classes are serializable to XML. Now, obviously I could implement the IXmlSerializable interface and then chuck a reader/writer to it but I would like to avoid that since it then means I need to instantiate a reader/writer whenever I want to do it, and 99.99% of the time I am going to be working with a string so I may just write my own. However,