ABC -
Reflection allows you to programatically examine and work with objects
at runtime. This is a very powerful feature of .NET which allows you
to interact with objects which you may not know how to work with at
design time. With reflection, you can obtain information about
methods, constructors, fields, events, anything that is contained
within an object. Also, the objects which you wish to explore and work
with don't necessarily need to be public, so you can, for example, set
the value of a private field of an object even if it's marked as
private!
For your specific question, the code is relatively simple. For
example:
public bool HasProperty(object control, string propertyName)
{
return control.GetType().GetProperty(propertyName) != null;
}
public bool HasEvent(object control, string eventName)
{
return control.GetType().GetEvent(eventName) != null;
}
So, for example, if you want to know if a control, has a property named
"Text", you'd simply do:
bool hasText = HasProperty(myControl, "Text");
If you want to know if it has an event called "Clicked":
bool hasClicked = HasProperty(myControl, "Clicked");
Hope this helps!
Brant Estes
Senior Consultant
Magenic Technologies
ABC wrote:
I am a newie about Reflection. I have not any ideas about Reflection
concept. May I have some tutorials or artists from internet? Any
recommandation?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eS**************@TK2MSFTNGP14.phx.gbl... ABC,
You want to use Reflection for this. First, get the type of the object
through a call to GetType. Once you do this, you will want to call
GetProperties or GetEvents to get the properties or events.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"ABC" <ab*@abc.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?