public interface IReflect
|
UnderlyingSystemType | Read-only Gets the underlying type that represents the IReflect object. |
GetField | Returns the FieldInfo object corresponding to the specified field and BindingFlag. |
GetFields | Returns an array of FieldInfo objects corresponding to all fields of the current class. |
GetMember | Retrieves an array of MemberInfo objects corresponding to all public members or to all members that match a specified name. |
GetMembers | Retrieves an array of MemberInfo objects corresponding either to all public members or to all members of the current class. |
GetMethod | Overloaded:GetMethod(string name, BindingFlags bindingAttr) Retrieves a MethodInfo object corresponding to a specified method under specified search constraints. |
GetMethod | Overloaded:GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) Retrieves a MethodInfo object corresponding to a specified method, using a Type array to choose from among overloaded methods. |
GetMethods | Retrieves an array of MethodInfo objects with all public methods or all methods of the current class. |
GetProperties | Retrieves an array of PropertyInfo objects corresponding to all public properties or to all properties of the current class. |
GetProperty | Overloaded:GetProperty(string name, BindingFlags bindingAttr) Retrieves a PropertyInfo object corresponding to a specified property under specified search constraints. |
GetProperty | Overloaded:GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) Retrieves a PropertyInfo object corresponding to a specified property with specified search constraints. |
InvokeMember | Invokes a specified member. |
Type UnderlyingSystemType {get;}
|
FieldInfo GetField( |
name
bindingAttr
Exception Type | Condition |
---|---|
AmbiguousMatchException | The object implements multiple fields with the same name. |
FieldInfo[] GetFields( |
bindingAttr
MemberInfo[] GetMember( |
name
bindingAttr
MemberInfo[] GetMembers( |
bindingAttr
MethodInfo GetMethod( |
name
bindingAttr
Exception Type | Condition |
---|---|
AmbiguousMatchException | The object implements multiple methods with the same name. |
MethodInfo GetMethod( |
name
bindingAttr
binder
types
modifiers
Exception Type | Condition |
---|---|
AmbiguousMatchException | The object implements multiple methods with the same name. |
MethodInfo[] GetMethods( |
bindingAttr
PropertyInfo[] GetProperties( |
bindingAttr
PropertyInfo GetProperty( |
name
bindingAttr
Exception Type | Condition |
---|---|
AmbiguousMatchException | The object implements multiple fields with the same name. |
PropertyInfo GetProperty( |
name
bindingAttr
binder
returnType
types
modifiers
object InvokeMember( |
name
invokeAttr
binder
target
args
modifiers
culture
namedParameters
Exception Type | Condition |
---|---|
ArgumentException | invokeAttr is BindingFlags.CreateInstance and another bit flag is also set. |
ArgumentException | invokeAttr is not BindingFlags.CreateInstance and name is null. |
ArgumentException | invokeAttr is not an invocation attribute from BindingFlags. |
ArgumentException | invokeAttr specifies both get and set for a property or field. |
ArgumentException | invokeAttr specifies both a field set and an Invoke method.args are provided for a field get. |
ArgumentException | More than one argument is specified for a field set. |
MissingFieldException | The field or property cannot be found. |
MissingMethodException | The method cannot be found. |
SecurityException | A private member is invoked without the necessary ReflectionPermission. |
A method is invoked if the number of parameters in the method declaration equals the number of arguments in the specified argument list, and the type of each argument can be converted by the binder to the type of the parameter.
The binder finds all matching methods, in accordance with the type of binding requested ( BindingFlags.InvokeMethod, IReflect.GetProperties, and so on). The set of methods is filtered by the name, number of arguments, and a set of search modifiers defined in the binder. After the method is selected, it is invoked, and accessibility is checked at that point. The search may control which set of methods is searched based upon the accessibility attribute associated with the method. Binder.BindToMethod selects the method to be invoked. The default binder selects the most specific match.
Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked through reflection whenever the code is fully trusted.
public class MainClass { public static void Main(string[] args) { Type tDate = Type.GetType("System.DateTime"); Object result = tDate.InvokeMember("Now", BindingFlags.GetProperty, null, null, new Object[0]); Console.WriteLine(result.ToString()); } } /* OUTPUT: D:\CCOM>csc invokemember.cs Microsoft (R) Visual C# Compiler Version 7.00.9150 [CLR version v1.0.2702] Copyright (C) Microsoft Corp 2000. All rights reserved. D:\CCOM>invokemember.exe 3/26/2001 2:39:22 PM */