Thursday 15 May 2014

c# - How do I call GetCustomAttributes from a Base Class? -


I should be able to get the custom attribute in any of its bases in the class. Right now I am doing this with a static static method in the base class (with multiple examples of the same attribute being applied to the class) with the following implementation:

  // A 'base Define 'Category Protected Static CustomAttribute GetCustomAttribute (int n) {New StackFrame (1, False) Return) // Get the last frame in the stack and thus the previous method. .GetMethod (). Disclaimer type. GetCustomAttributes (typeof (CustomAttribute), false). Choose (o => CustomAttribute) o List () [n]; } [Custom properties] [custom properties] [custom properties] category created: base { Fixed Zero main (string) [] Args) {var attribute = GetCustomAttribute (2); }}  

Ideally I'm able to call it with the controller and cache the results.

Thank you.

PS

I have realized that GetCustomAttributes are not guaranteed to give them back in regards to the Order of Reshma.

If you use example methods instead of static methods, you also call it. Gate type (), even from the base class. AttributeUsage (AttributeTargets.Class, AllowMultiple = true, Inherited = true)] Class custom attribute: attribute {} abstract class base {secure base} {this.Attributes = Attribute.GetCustomAttributes (this.GetType ()), typef (Custom-made) .stat & lt; Custom Authorship & gt; () .oerere (); } Protected custom attribute [] attributes {get; Private set; }} [Custom] [custom] [custom] category created: base {static zero major () {var derived = new derived (); Var attribute = derived. Properties [2]; }}

It's easy, and that caching is completed in that constructor you were hoping for.


No comments:

Post a Comment