How can I read custom attributes without reflection?

3

I have the following code snippet:

[Campo(Chave=true)]
public System.Guid EscalaId { get; set; }

I know that I can read these tributes using the MemberInfo class, as the example in the documentation says:

System.Reflection.MemberInfo info = typeof(MyClass);
object[] attributes = info.GetCustomAttributes(true);

But are there alternatives without the use of reflection?

    
asked by anonymous 05.05.2017 / 22:49

1 answer

3
  

How can I read custom attributes without reflection?

There's no way.

How the problem is the issue of speed , the speed constraint in Reflection is in reading and setting property values , not in reading decorating attributes.

In addition, there are libraries to address this. The most famous of these is FastMember , which is part of #, which does just that: it reads several things for Reflection , but the definition of values uses static code dynamically generated at runtime by href="https://msdn.microsoft.com/en-us/library/system.reflection.emit(v=vs.110).aspx"> Reflection.Emit .

    
05.05.2017 / 23:17