I'm going to do this without passing any parameter to attribute! Is it possible?
class MyAtt : Attribute { string NameOfSettedProperty() { //How do this? (Would be MyProp for example) } } class MyCls { [MyAtt] int MyProp { get { return 10; } } }
In C#, you specify an attribute by placing the name of the attribute enclosed in square brackets ([]) above the declaration of the entity to which it applies. [Serializable] public class SampleClass { // Objects of this type can be serialized. }
The same you would normally check for an attribute on a class. Here's some sample code. typeof(ScheduleController) . IsDefined(typeof(SubControllerActionToViewDataAttribute), false);
Advertisements. An attribute is a declarative tag that is used to convey information to runtime about the behaviors of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. You can add declarative information to a program by using an attribute.
Using CallerMemberNameAttribute from .NET 4.5:
public CustomAttribute([CallerMemberName] string propertyName = null) { // ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With