Click here to Skip to main content
15,891,253 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using outlook to send messages. Pin
Heath Stewart8-May-04 20:01
protectorHeath Stewart8-May-04 20:01 
GeneralRe: Using outlook to send messages. Pin
mpalle8-May-04 22:24
mpalle8-May-04 22:24 
GeneralRe: Using outlook to send messages. Pin
Heath Stewart9-May-04 2:23
protectorHeath Stewart9-May-04 2:23 
GeneralRe: Using outlook to send messages. Pin
mpalle9-May-04 2:39
mpalle9-May-04 2:39 
GeneralGet name of variable Pin
Stefan Troschuetz8-May-04 4:06
Stefan Troschuetz8-May-04 4:06 
GeneralRe: Get name of variable Pin
Hesham Amin8-May-04 4:13
Hesham Amin8-May-04 4:13 
GeneralRe: Get name of variable Pin
Stefan Troschuetz8-May-04 4:22
Stefan Troschuetz8-May-04 4:22 
GeneralRe: Get name of variable Pin
kayhustle8-May-04 16:03
kayhustle8-May-04 16:03 
You can get the name. Let's say you have a class Test as follows,
class Test<br />
{<br />
private int variable;<br />
private int Variable<br />
{<br />
get{return variable;}<br />
}<br />
private int VariableFunc()<br />
{<br />
return variable;<br />
}<br />
}

Let says we use the FindNames class to get the names of the members of this class. Since we already know the class name we can do,
using System.Reflection;<br />
class FindNames<br />
{<br />
<br />
	public string[] GetNamesType()<br />
	{<br />
		Type mytype = typeof(Test);<br />
		ArrayList names = new ArrayList();<br />
		PropertyInfo [] properties = mytype.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance);<br />
		foreach(PropertyInfo pinfo in properties)<br />
		{<br />
			names.Add(pinfo.Name);//this will get the string "Variable"<br />
		}<br />
		FieldInfo [] fields= mytype.GetFields(BindingFlags.NonPublic|BindingFlags.Instance);<br />
		foreach(FieldInfo finfo in fields)<br />
		{<br />
			names.Add(finfo.Name);//this will get the string "variable"<br />
		}<br />
		MethodInfo [] methods = mytype.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);<br />
		foreach(MethodInfo methinfo in properties)<br />
		{<br />
			names.Add(methinfo.Name);//this will get the string "VariableFunc"<br />
		}<br />
		MemberInfo [] members = mytype.GetMembers<br />
			(BindingFlags.NonPublic|BindingFlags.Instance);<br />
		foreach(MemberInfo minfo in members)<br />
		{<br />
			names.Add(pinfo.Name);//this will get the strings "Variable", "variable",<br />
			//"VariableFunc",<br />
		}<br />
<br />
		return names.ToArray(typeof(string)) as string[];<br />
	}<br />

Make sure you put in the BindingFlags.Instance or BindingFlags.Static or it will throw an exception. Play around with the BindingFlags depending on what type of members you want to get. You can find out many useful things about the member of the class including its type, name, etc. You can also dynamically get/set/invoke it if it is static, or get/set/invoke it on an instance that you pass in. P.S. if you don't want to hardcode the class name too then you can just take an instance of that class and do something like
Type mytype=instance.GetType();
.
.
.
Hope that helped.
GeneralRe: Get name of variable Pin
Stefan Troschuetz9-May-04 0:51
Stefan Troschuetz9-May-04 0:51 
GeneralRe: Get name of variable Pin
Heath Stewart8-May-04 19:29
protectorHeath Stewart8-May-04 19:29 
GeneralRe: Get name of variable Pin
Stefan Troschuetz9-May-04 0:42
Stefan Troschuetz9-May-04 0:42 
GeneralRe: Get name of variable Pin
Heath Stewart9-May-04 2:51
protectorHeath Stewart9-May-04 2:51 
Generaladd a property Pin
cristina_tudor8-May-04 2:48
cristina_tudor8-May-04 2:48 
GeneralRe: add a property Pin
Dave Kreskowiak8-May-04 3:17
mveDave Kreskowiak8-May-04 3:17 
GeneralC# Questions relating to TextBox Pin
Member 6910898-May-04 0:33
Member 6910898-May-04 0:33 
GeneralRe: C# Questions relating to TextBox Pin
Hesham Amin8-May-04 1:19
Hesham Amin8-May-04 1:19 
GeneralRe: C# Questions relating to TextBox Pin
surgeproof8-May-04 4:21
surgeproof8-May-04 4:21 
GeneralRe: C# Questions relating to TextBox Pin
kayhustle8-May-04 5:19
kayhustle8-May-04 5:19 
GeneralRe: C# Questions relating to TextBox Pin
Heath Stewart8-May-04 19:56
protectorHeath Stewart8-May-04 19:56 
Questionhow can i got the version infomation about the sqlsever? Pin
lowiq7-May-04 20:04
lowiq7-May-04 20:04 
AnswerRe: how can i got the version infomation about the sqlsever? Pin
Mazdak7-May-04 20:20
Mazdak7-May-04 20:20 
GeneralRe: how can i got the version infomation about the sqlsever? Pin
lowiq7-May-04 20:30
lowiq7-May-04 20:30 
GeneralRe: how can i got the version infomation about the sqlsever? Pin
Hesham Amin7-May-04 21:02
Hesham Amin7-May-04 21:02 
GeneralRe: how can i got the version infomation about the sqlsever? Pin
lowiq7-May-04 21:09
lowiq7-May-04 21:09 
GeneralRe: how can i got the version infomation about the sqlsever? Pin
Mazdak7-May-04 21:05
Mazdak7-May-04 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.