Right, say I have something like:
myClass.myClassIntegerVariable=23
Is there an easy way of getting not the value of myClassIntegerVariable, but it's name as a String? Otherwise I'd have to create redundant data like:
myClass.myClassIntegerVariable=23;
myClass.myClassIntegerVariableName="myClassIntegerVariableName";
Loading
yuriy thebestPosted Oct 30, 2011, 6:31 AM
Jaish MathewsPosted Oct 30, 2011, 2:42 AM
You didn't mention scenarios like
- Do you need to access it in side same class or in side a separate class?
- Want to know whether your class is static?
Below is the code if it's same class where specified field need to access. Please refactor it.Assembly assembly = Assembly.GetExecutingAssembly();
MemberInfo[] memberInfo = assembly.GetType("Web.foo._Default").GetMembers();
IEnumerator infoCollection = memberInfo.GetEnumerator();
while (infoCollection.MoveNext())
{
MemberInfo info = (MemberInfo)infoCollection.Current;
if (info.MemberType.Equals(MemberTypes.Field))
{
//Here you will get all fileds in side the loaded type and use .Name property for the name
}
}
Dipal ChoksiPosted Oct 30, 2011, 2:13 AM
http://www.c-sharpcorner.com/UploadFile/kirtan007/787/
http://www.csharp-examples.net/reflection-property-names/