Angel J. Hernández M. wrote:[color=blue]
> Hi there... You can use the Type.GetMember method.
>
http://msdn.microsoft.com/library/de...embertopic.asp
> When specifying the binding flags remember to add BindingFlags.Static.
>
> Regards,
>
>
> --
> Angel J. Hernández M.
> MCP - MCAD - MCSD - MCDBA
>
http://groups.msn.com/desarrolladoresmiranda
>
http://www.consein.com
>
>
>
>
>
>
> <rettigcd@gmail.com> escribió en el mensaje
> news:1126665486.192412.314970@g49g2000cwa.googlegr oups.com...[color=green]
> >I have several classes that all have the same static member:
> >
> > class A{
> > public static string Table = "TableA";
> > }
> >
> > class B{
> > public static string Table = "TableB";
> > }
> >
> > none of the classes inherit from a common base class or interface.
> >
> > How can I use reflection to get the value stored in A.Table and
> > B.Table?
> > I found examples that called static member functions but none that
> > accessed non-function/non-property.
> >
> > I'm simply trying associate a string with a class and not with a
> > particular instance of that class. I could create an interface but I
> > don't want to have to create an instance just to access a static
> > member.
> >
> > thanks.
> > Dean
> >[/color][/color]
Angel,
I already tried using GetMember like this:
private static string GetTableName( Type t ){
MemberInfo[] TableNameInfo = t.GetMember("TableName" );
return TableNameInfo[0].ToString();
}
but the function returned: "string ClassName.TableName" instead of the
value stored in it.
So then I tried this:
private static string GetTableName( Type t ){
MemberInfo[] TableNameInfo =
t.GetMember("TableName",MemberTypes.All, BindingFlags.Static );
return TableNameInfo[0].ToString();
}
and got no members returned from the GetMembers() function.
After I get the MemberInfo object, how do I get the static value
associated with it. I was looking for a GetValue() function but
couldn't find one.
thanks,
Dean Rettig