本文整理汇总了C#中System.Reflection.MethodInfo.IsExtension方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.IsExtension方法的具体用法?C# MethodInfo.IsExtension怎么用?C# MethodInfo.IsExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.IsExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsHiddenBy
public static bool IsHiddenBy(this MethodInfo m1, MethodInfo m2)
{
if (m1.IsExtension() || m2.IsExtension()) return false;
if (m1.IsOperator() || m2.IsOperator()) return false;
m1 = m1.XGetGenericDefinition();
m2 = m2.XGetGenericDefinition();
if (!m2.DeclaringType.LookupThisAndBaseTypes().Contains(m1.DeclaringType)) return false;
var aux = Guid.NewGuid().ToString();
var namesMatch = (m1.IsIndexer() ? aux : m1.Name) == (m2.IsIndexer() ? aux : m2.Name);
var typeParamsMatch = m1.XGetGenericArguments().Length == m2.XGetGenericArguments().Length;
var paramListStyleMatch = m1.IsVarargs() == m2.IsVarargs();
var formalParamsMatch = m1.GetParameters().AllMatch(m2.GetParameters(), (p1, p2) =>
{
if (p1.IsOut ^ p2.IsOut) return false;
if (p1.ParameterType.IsByRef ^ p2.ParameterType.IsByRef) return false;
var p1m = p1.ParameterType.GetStructuralTree();
var p2m = p2.ParameterType.GetStructuralTree();
return p1m.AllMatch(p2m, (p1mi, p2mi) =>
{
if (p1mi.Key != p2mi.Key) return false;
if (p1mi.Value.IsGenericParameter ^ p2mi.Value.IsGenericParameter) return false;
if (!p1mi.Value.IsGenericParameter && !p2mi.Value.IsGenericParameter)
{
return p1mi.Value.SameBasisType(p2mi.Value);
}
else
{
Func<MethodInfo, KeyValuePair<String, Type>, bool> isMethodParam =
(mi, pimi) => mi.XGetGenericArguments().Contains(pimi.Value);
var positionsMatch = p1mi.Value.GenericParameterPosition ==
p2mi.Value.GenericParameterPosition;
return isMethodParam(m1, p1mi) && isMethodParam(m2, p2mi) && positionsMatch;
}
});
});
var sigsMatch = namesMatch && typeParamsMatch && paramListStyleMatch && formalParamsMatch;
return m1.IsHideBySig ? sigsMatch : namesMatch;
}
示例2: CompileCallArguments
private IEnumerable<LinqExpression> CompileCallArguments(
MethodInfo sig, IEnumerable<Cast> casts,
IEnumerable<RelinqScriptExpression> args, CompilationContext ctx)
{
var sigp = sig.GetParameters();
var instaCasts = sig.IsExtension() ? casts : casts.Skip(1);
for (var i = 0; i < sigp.Length; ++i)
{
var cast = instaCasts.ElementAt(i);
if (i != sigp.Length - 1 || !sig.IsVarargs())
{
yield return CompileCast(cast, args.ElementAt(i), ctx);
}
else
{
// cba to check whether the cast actually features a nice CLR type
var argType = ((ClrType)cast.Destination).Type;
yield return LinqExpression.NewArrayInit(
argType, args.Skip(sigp.Length - 1).Select(arg => CompileCast(cast, arg, ctx)));
}
}
}