本文整理汇总了C#中System.Reflection.MethodInfo.GetGenericMethodDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetGenericMethodDefinition方法的具体用法?C# MethodInfo.GetGenericMethodDefinition怎么用?C# MethodInfo.GetGenericMethodDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetGenericMethodDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetExpectProvider
public bool TryGetExpectProvider(MethodInfo method, out IMethodExpectProvider provider)
{
var foundExact = lookup.TryGetValue(method, out provider);
if(!foundExact && method.IsGenericMethod)
return lookup.TryGetValue(method.GetGenericMethodDefinition(), out provider);
return foundExact;
}
示例2: VisitMethod
protected virtual MethodInfo VisitMethod(MethodInfo methodToSearch)
{
var newReflectedType = VisitType(methodToSearch.ReflectedType);
if (newReflectedType != methodToSearch.ReflectedType)
{
methodToSearch = newReflectedType.GetMethod(methodToSearch.Name,
(methodToSearch.IsStatic ? BindingFlags.Static : BindingFlags.Instance)
| (methodToSearch.IsPublic
? BindingFlags.Public
: BindingFlags.NonPublic),
null,
methodToSearch.GetParameters().Select(x => x.ParameterType).ToArray(),
null);
}
if (!methodToSearch.IsGenericMethod)
return methodToSearch;
var genArgs = methodToSearch.GetGenericArguments();
var newGenArgs = genArgs.Select(VisitType).ToArray();
if (genArgs.SequenceEqual(newGenArgs))
return methodToSearch;
return methodToSearch.GetGenericMethodDefinition().MakeGenericMethod(newGenArgs);
}
示例3: GetMethodGenerator
public IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method)
{
IHqlGeneratorForMethod methodGenerator;
if (method.IsGenericMethod)
{
method = method.GetGenericMethodDefinition();
}
if (_registeredMethods.TryGetValue(method, out methodGenerator))
{
return methodGenerator;
}
// No method generator registered. Look to see if it's a standard LinqExtensionMethod
var attr = method.GetCustomAttributes(typeof (LinqExtensionMethodAttribute), false);
if (attr.Length == 1)
{
// It is
// TODO - cache this? Is it worth it?
return new HqlGeneratorForExtensionMethod((LinqExtensionMethodAttribute) attr[0], method);
}
// Not that either. Let's query each type generator to see if it can handle it
foreach (var typeGenerator in _typeGenerators)
{
if (typeGenerator.SupportsMethod(method))
{
return typeGenerator.GetMethodGenerator(method);
}
}
throw new NotSupportedException(method.ToString());
}
示例4: GetItem
protected virtual IMethodCallTranslator GetItem(MethodInfo key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
IMethodCallTranslator translator;
if (Registry.TryGetValue(key, out translator))
{
return translator;
}
if (key.IsGenericMethod && !key.IsGenericMethodDefinition)
{
if (Registry.TryGetValue(key.GetGenericMethodDefinition(), out translator))
{
return translator;
}
}
// Check if the generic form of the declaring type matches
translator = GetItemFromGenericType(key);
if (translator != null)
{
return translator;
}
// Finally, check any interfaces that may have a matching
return GetItemFromInterfaces(key);
}
示例5: EnsureClosedMethod
private MethodInfo EnsureClosedMethod(MethodInfo method)
{
if (method.ContainsGenericParameters)
{
return method.GetGenericMethodDefinition().MakeGenericMethod(this.genericMethodArguments);
}
return method;
}
示例6: GetItem
protected virtual IMethodCallTranslator GetItem(MethodInfo key)
{
lock (Registry)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
IMethodCallTranslator translator;
if (Registry.TryGetValue(key, out translator))
{
return translator;
}
if (key.IsGenericMethod && !key.IsGenericMethodDefinition)
{
if (Registry.TryGetValue(key.GetGenericMethodDefinition(), out translator))
{
return translator;
}
}
// Check if the generic form of the declaring type matches
translator = GetItemFromGenericType(key);
if (translator != null)
{
return translator;
}
// Check any interfaces that may have a matching method
translator = GetItemFromInterfaces(key);
if (translator != null)
{
return translator;
}
// If no preregistered method is found, check to see if the method is decorated with N1QlFunctionAttribute
translator = CreateFromN1QlFunctionAttribute(key);
if (translator != null)
{
// Save this translator for reuse
Registry.Add(key, translator);
return translator;
}
// Finally, check base method if this is a virtual method
var baseMethod = key.GetBaseDefinition();
if ((baseMethod != null) && (baseMethod != key))
{
return GetItem(baseMethod);
}
// No match found
return null;
}
}
示例7: EnsureSatisfiesClassConstraints
public static void EnsureSatisfiesClassConstraints(MethodInfo reflectionMethodInfo)
{
MethodInfo genericMethodDefinition = reflectionMethodInfo.GetGenericMethodDefinition();
TypeInfo[] methodArguments = TypesToTypeInfos(reflectionMethodInfo.GetGenericArguments());
TypeInfo[] methodParameters = TypesToTypeInfos(genericMethodDefinition.GetGenericArguments());
TypeInfo[] typeArguments = TypesToTypeInfos(reflectionMethodInfo.DeclaringType.GetGenericArguments());
SigTypeContext typeContext = new SigTypeContext(typeArguments, methodArguments);
EnsureSatisfiesClassConstraints(methodParameters, methodArguments, genericMethodDefinition, typeContext);
}
示例8: GetBaseDefinition
private static MethodInfo GetBaseDefinition(MethodInfo method)
{
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
{
method = method.GetGenericMethodDefinition();
}
return method.GetBaseDefinition();
}
示例9: ArgsMatch
private static bool ArgsMatch(MethodInfo m, ReadOnlyCollection<Expression> args, Type[] typeArgs)
{
ParameterInfo[] parameters = m.GetParameters();
if (parameters.Length != args.Count)
{
return false;
}
if ((!m.IsGenericMethod && (typeArgs != null)) && (typeArgs.Length > 0))
{
return false;
}
if ((!m.IsGenericMethodDefinition && m.IsGenericMethod) && m.ContainsGenericParameters)
{
m = m.GetGenericMethodDefinition();
}
if (m.IsGenericMethodDefinition)
{
if ((typeArgs == null) || (typeArgs.Length == 0))
{
return false;
}
if (m.GetGenericArguments().Length != typeArgs.Length)
{
return false;
}
m = m.MakeGenericMethod(typeArgs);
parameters = m.GetParameters();
}
int index = 0;
int count = args.Count;
while (index < count)
{
Type parameterType = parameters[index].ParameterType;
if (parameterType == null)
{
return false;
}
if (parameterType.IsByRef)
{
parameterType = parameterType.GetElementType();
}
Expression operand = args[index];
if (!parameterType.IsAssignableFrom(operand.Type))
{
if (operand.NodeType == ExpressionType.Quote)
{
operand = ((UnaryExpression) operand).Operand;
}
if (!parameterType.IsAssignableFrom(operand.Type) && !parameterType.IsAssignableFrom(StripExpression(operand.Type)))
{
return false;
}
}
index++;
}
return true;
}
示例10: AsTransactional
public Maybe<ITransactionOptions> AsTransactional(MethodInfo target)
{
Contract.Requires(target != null);
Contract.Ensures(Contract.Result<Maybe<TransactionAttribute>>() != null);
var rawMethodInfo = target.IsGenericMethod ? target.GetGenericMethodDefinition() : target;
return _TxMethods.ContainsKey(rawMethodInfo)
? Maybe.Some<ITransactionOptions>(_TxMethods[rawMethodInfo])
: Maybe.None<ITransactionOptions>();
}
示例11: InvokeGenericMethod
public static object InvokeGenericMethod(object instance, MethodInfo methodInfo, Type[] typeArguments, object[] parameters)
{
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");
// Could check that methodInfo.GetParameters().Count() == parameters.Count(), and methodInfo.GetGenericArguments().Count() == typeArguments.Count() ?
var method = methodInfo.GetGenericMethodDefinition();
var genericMethod = method.MakeGenericMethod(typeArguments);
var result = genericMethod.Invoke(instance, parameters);
return result;
}
示例12: TryGetGenerator
public virtual bool TryGetGenerator(MethodInfo method, out IHqlGeneratorForMethod generator)
{
if (method.IsGenericMethod)
{
method = method.GetGenericMethodDefinition();
}
if (registeredMethods.TryGetValue(method, out generator)) return true;
// Not that either. Let's query each type generator to see if it can handle it
if (GetRuntimeMethodGenerator(method, out generator)) return true;
return false;
}
示例13: ImplementGenericPattern
public override IMethodInfo ImplementGenericPattern(MethodInfo method, Type[] typeArgs, Type[] methodArgs)
{
var jointArgs = new List<Type>();
var patternArgs = method.IsGenericMethod ? method.GetGenericMethodDefinition().GetGenericArguments() : new Type[0];
var patternMethodArgs = GetGenericPattern(method).GetMethodGenericArguments();
var patternTypeArgs = GetGenericPattern(method).GetTypeGenericArguments();
for (var i = 0; i < patternArgs.Length; ++i)
{
var patternArg = patternArgs[i];
for (var j = 0; j < patternMethodArgs.Length; ++j)
{
var patternMethodArg = patternMethodArgs[j];
if (patternMethodArg.SameMetadataToken(patternArg))
{
jointArgs.Add(methodArgs[j]);
break;
}
}
for (var j = 0; j < patternTypeArgs.Length; ++j)
{
var patternTypeArg = patternTypeArgs[j];
if (patternTypeArg.SameMetadataToken(patternArg))
{
jointArgs.Add(typeArgs[j]);
break;
}
}
}
var pattern = method.IsGenericMethod ? method.GetGenericMethodDefinition() : method;
return ForgedMethod.Forge(pattern.MakeGenericMethod(jointArgs.ToArray()), this);
}
示例14: Generate
public void Generate(MethodInfo newMethod)
{
if (newMethod.IsGenericMethod)
newMethod = newMethod.GetGenericMethodDefinition();
FieldInfo field = typeof (DynamicWrapperBase).GetField("UnderlyingObject", BindingFlags.Instance | BindingFlags.NonPublic);
ParameterInfo[] parameters = newMethod.GetParameters();
Type[] parameterTypes = Enumerable.ToArray<Type>(Enumerable.Select<ParameterInfo, Type>((IEnumerable<ParameterInfo>) parameters, (Func<ParameterInfo, Type>) (parameter => parameter.ParameterType)));
MethodBuilder methodBuilder = this._wrapperBuilder.DefineMethod(newMethod.Name, MethodAttributes.Public | MethodAttributes.Virtual, newMethod.ReturnType, parameterTypes);
if (newMethod.IsGenericMethod)
methodBuilder.DefineGenericParameters(Enumerable.ToArray<string>(Enumerable.Select<Type, string>((IEnumerable<Type>) newMethod.GetGenericArguments(), (Func<Type, string>) (arg => arg.Name))));
ILGenerator ilGenerator = methodBuilder.GetILGenerator();
WrapperMethodBuilder.LoadUnderlyingObject(ilGenerator, field);
WrapperMethodBuilder.PushParameters((ICollection<ParameterInfo>) parameters, ilGenerator);
this.ExecuteMethod((MethodBase) newMethod, parameterTypes, ilGenerator);
WrapperMethodBuilder.Return(ilGenerator);
}
示例15: ExtractBaseMethod
static MethodInfo ExtractBaseMethod (MethodInfo info)
{
if (info is MethodBuilder)
return info;
if (info is MethodOnTypeBuilderInst)
return ((MethodOnTypeBuilderInst)info).base_method;
if (info.IsGenericMethod)
info = info.GetGenericMethodDefinition ();
Type t = info.DeclaringType;
if (!t.IsGenericType || t.IsGenericTypeDefinition)
return info;
return (MethodInfo)t.Module.ResolveMethod (info.MetadataToken);
}