本文整理汇总了C#中System.Reflection.MemberInfo.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.OfType方法的具体用法?C# MemberInfo.OfType怎么用?C# MemberInfo.OfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.OfType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindIndexer
int FindIndexer(Type type, Expression[] args, out MethodBase method)
{
foreach (Type t in SelfAndBaseTypes(type))
{
#if !(NETFX_CORE || DNXCORE50)
MemberInfo[] members = t.GetDefaultMembers();
#else
MemberInfo[] members = new MemberInfo[0];
#endif
if (members.Length != 0)
{
IEnumerable<MethodBase> methods = members.
OfType<PropertyInfo>().
#if !(NETFX_CORE || DNXCORE50)
Select(p => (MethodBase)p.GetGetMethod()).
Where(m => m != null);
#else
Select(p => (MethodBase)p.GetMethod);
#endif
int count = FindBestMethod(methods, args, out method);
if (count != 0) return count;
}
}
method = null;
return 0;
}
示例2: EvaluateMethod
bool EvaluateMethod (string str, MemberInfo[] member, object instance, object [] parameterValues, out object val)
{
val = null;
// Find a method with a matching number of parameters
var method = FindBestOverload (member.OfType<MethodBase> (), parameterValues);
if (method == null)
return false;
try {
// Convert the given parameters to the types specified in the method signature
var methodParams = method.GetParameters ();
var convertedArgs = (methodParams.Length == parameterValues.Length) ? parameterValues : new object [methodParams.Length];
int numArgs = methodParams.Length;
Type paramsArgType = null;
if (methodParams.Length > 0 && methodParams [methodParams.Length - 1].ParameterType.IsArray && methodParams [methodParams.Length - 1].IsDefined (typeof (ParamArrayAttribute))) {
paramsArgType = methodParams [methodParams.Length - 1].ParameterType.GetElementType ();
numArgs--;
}
int n;
for (n = 0; n < numArgs; n++)
convertedArgs [n] = ConvertArg (method, n, parameterValues [n], methodParams [n].ParameterType);
if (methodParams.Length == parameterValues.Length && paramsArgType != null) {
// Invoking an method with a params argument, but the number of arguments provided is the same as the
// number of arguments of the method, so the last argument can be either one of the values of the
// params array, or it can be the whole params array.
try {
var last = convertedArgs.Length - 1;
convertedArgs [last] = ConvertArg (method, last, parameterValues [last], methodParams [last].ParameterType);
// Conversion worked. Ignore the params argument.
paramsArgType = null;
} catch (InvalidCastException) {
// Conversion of the last argument failed, so it probably needs to be handled as a single value
// for the params argument.
}
}
if (paramsArgType != null) {
var argsArray = new object [parameterValues.Length - numArgs];
for (int m = 0; m < argsArray.Length; m++)
argsArray [m] = ConvertArg (method, n, parameterValues [n++], paramsArgType);
convertedArgs [convertedArgs.Length - 1] = argsArray;
}
// Invoke the method
val = method.Invoke (instance, convertedArgs);
} catch (Exception ex) {
LoggingService.LogError ("MSBuild property evaluation failed: " + str, ex);
return false;
}
return true;
}