Ruben,
What you're looking for are te "Reflection" classes in System.Reflection. I
adapted the sample from the MSDN library with your "A" class:
using System;
using System.Reflection;
public class FieldInfoClass
{
// the class you're interested in:
public class TestClass
{
public string a;
}
// the sample from MSDN, modified to use the test class
public static void Main()
{
FieldInfo[] myFieldInfo;
TestClass A = new TestClass();
Type myType = A.GetType();
// Get the type and fields of TestClass
myFieldInfo = myType.GetFields(BindingFlags.NonPublic |
BindingFlags.Instance
| BindingFlags.Public);
Console.WriteLine("\nThe fields of " +
"FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
for(int i = 0; i < myFieldInfo.Length; i++)
{
Console.WriteLine("\nName : {0}",
myFieldInfo[i].Name);
Console.WriteLine("Declaring Type : {0}",
myFieldInfo[i].DeclaringType);
Console.WriteLine("IsPublic : {0}",
myFieldInfo[i].IsPublic);
Console.WriteLine("MemberType : {0}",
myFieldInfo[i].MemberType);
Console.WriteLine("FieldType : {0}",
myFieldInfo[i].FieldType);
Console.WriteLine("IsFamily : {0}",
myFieldInfo[i].IsFamily);
}
}
}
"Ruben" <Mr****@gmx.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi!
I am looking for a way to get the name of a class-member as string, as
example:
class A
{
public string a;
}
[...]
string MemberName = GiveMeTheNameOf(A.a);
What I want is: MemberName == "A.a"
Is there any way to do that?
Thank you!
Ruben