C# TypeInfo GetProperty(String, BindingFlags)
Description
TypeInfo GetProperty(String, BindingFlags)
Searches
for the specified property, using the specified binding constraints.
Syntax
TypeInfo.GetProperty(String, BindingFlags)
has the following syntax.
public PropertyInfo GetProperty(
string name,
BindingFlags bindingAttr
)
Parameters
TypeInfo.GetProperty(String, BindingFlags)
has the following parameters.
name
- The string containing the name of the property to get.bindingAttr
- A bitmask comprised of one or more BindingFlags that specify how the search is conducted.bindingAttr
- -or-bindingAttr
- Zero, to return null.
Returns
TypeInfo.GetProperty(String, BindingFlags)
method returns An object representing the property that matches the specified requirements,
if found; otherwise, null.
Example
using System;/* w ww. jav a 2 s . c o m*/
using System.Reflection;
class MyClass
{
private int myProperty;
public int MyProperty
{
get
{
return myProperty;
}
set
{
myProperty=value;
}
}
}
public class MyTypeClass
{
public static void Main(string[] args)
{
Type myType=typeof(MyClass);
PropertyInfo myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.Instance);
Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name);
}
}
The code above generates the following result.