For example, in C# I can do the following using reflection:
public class A
{
object obj1;
[MyCustumAttribute(data)]
public object Obj1Property
{ get; set; }
public A() {}
}
public static void Main(string[] args)
{
Type t = typeof(a);
PropertyInfo[] props = t.GetProperties();
attrs = props[0].GetCustomAttributes();
//Do something with the properties based on their custom attributes
}
Note that I can do the same thing with A’s methods, data members, etc. not just on properties.
Is there a way to do this same type of thing in Python 2.7?
EDIT: After re-reading your question I realized that the reflection aspect wasn’t addressed. The answer is still no from what I can find though. .NET reflection doesn’t seem to address DLR types (e.g. IronPython, IronRuby). There is a reflection mechanism in python that you may be able to utilize though, see https://stackoverflow.com/a/1447529/635634 for details.
–
Not really, but you can sort of achieve the same effect using DevHawk’s solution.