> Anybody can help me in C#.net how to do macro like vfp..
>
>
> Foxpro style:
>
> mystring = "thisform.textbox."
> myprop = "enabled"
> mytrue = "=.T."
>
> mymacro = mystring+myprop+mytrue
>
> &mymacro
>
>
> here's what I need in C#.net
>
> textBox1.Enable = true; - this would be my execution.
>
> string mystring mytexbox = "textBox1";
> string myprop = "Enable ==";
> boolean mytrue = true;
>
> How to execute it in C#?
>
>
> Thanks in advance...
>
> Gary
Gary,
In C# there isn't a direct macro substitution like in VFP. However using Reflection namespace and other features you can do what you would with & and more. Here is a sample using reflection (and this is not the only way, the code is verbose):
string mytextbox = "textBox1";
string myprop = "Enabled";
bool mytrue = true;
// Find a member of thisform using reflection
// (again - this is not the only way)
Object myControl = this.GetType().InvokeMember(mytextbox,
BindingFlags.IgnoreCase |
BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.GetField,
null, this, new object[] { });
// invoke set property on myControl
typeof(TextBox).InvokeMember(myprop,
BindingFlags.SetProperty,
null, myControl, new Object[] { mytrue });
Cetin Basoz
.Net has got better.Think about moving - check my blog:
Blog (main)Blog (mirror)