c# - Custom Attribute that uses Type as a property -


i have following custom attribute have type name property. however, not want have use string representation of type when using attribute. example:

public class helpmeattribute : attribute {     public string typename { get; set; } } 

and use it, thought this

[helpme(typename = typeof(myclass2).fullname] public class myclass1 { }  public class myclass2 { } 

i error: "an attribute must constant expression, typeof expression or array creation expression of attribute parameter type."

i prefer not do:

[helpme(typename = "myclass2"] 

because seems bad have type in string. better let compiler check type putting in attribute exists.

can point me down path of enlightenment fix this?

attribute initializers can use compile-time constants or system.type properties.

so why not use type?

public class helpmeattribute : attribute {     public type type { get; set; }     ...      public helpmeattribute()     {     } }  ... [helpme(type = typeof(myclass2))] public class myclass1 { } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -