Maybe this question make you confuse ,but please help me
In .NET 4.0 , language C#
I have two project ,one is the library define classes and attribute mark infors for class, one is the project that process reflection of class declared from that library.
The problem is , without make reference to library , I just use reflection-related classes to read assembly and I have to get value of properties that declared in object class.
For example
—In LIB project , named lib.dll
public class MarkAttribute: Attribute
{
public string A{get;set;}
public string B{get;set;}
}
[Mark(A="Hello" B="World")]
public class Data
{
}
—In Reflection project
public void DoIt()
{
string TypeName="Lib.Data";
var asm=Assembly.LoadFrom("lib.dll");
foreach (var x in asm.GetTypes())
{
if (x.GetType().Name=="Data")
{
var obj=x.GetType().GetCustomAttributes(false);
//now if i make reference to lib.dll in the usual way , it is ok
var mark=(Lib.MarkAttribute)obj;
var a=obj.A ;
var b=obj.B ;
//but if i do not make that ref
//how can i get A,B value
}
}
}
any idea appreciated
You can retrieve the attribute’s properties using reflection as well: