当前位置: 首页>>代码示例>>C#>>正文


C# MethodInfo.GetGenericMethodDefinition方法代码示例

本文整理汇总了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;
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:7,代码来源:MethodExpectProviderLookup.cs

示例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);
        }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:25,代码来源:ExpressionTypeVisitor.cs

示例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());
        }
开发者ID:paulbatum,项目名称:nhibernate,代码行数:34,代码来源:FunctionRegistry.cs

示例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);
        }
开发者ID:amccool,项目名称:Linq2Couchbase,代码行数:31,代码来源:DefaultMethodCallTranslatorProvider.cs

示例5: EnsureClosedMethod

		private MethodInfo EnsureClosedMethod(MethodInfo method)
		{
			if (method.ContainsGenericParameters)
			{
				return method.GetGenericMethodDefinition().MakeGenericMethod(this.genericMethodArguments);
			}
			return method;
		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:8,代码来源:WCFAbstractInvocation.cs

示例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;
            }
        }
开发者ID:akorczynski,项目名称:Linq2Couchbase,代码行数:58,代码来源:DefaultMethodCallTranslatorProvider.cs

示例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);
 }
开发者ID:tijoytom,项目名称:corert,代码行数:9,代码来源:ConstraintValidator.cs

示例8: GetBaseDefinition

        private static MethodInfo GetBaseDefinition(MethodInfo method)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = method.GetGenericMethodDefinition();
            }

            return method.GetBaseDefinition();
        }
开发者ID:bluePlayer,项目名称:FakeItEasy,代码行数:9,代码来源:MethodInfoManager.cs

示例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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:57,代码来源:EnumerableRewriter.cs

示例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>();
		}
开发者ID:hammett,项目名称:Castle.Transactions,代码行数:10,代码来源:TransactionalClassMetaInfo.cs

示例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;
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:13,代码来源:ReflectionHelper.cs

示例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;
		}
开发者ID:thilaknathen,项目名称:nhibernate-core,代码行数:14,代码来源:DefaultLinqToHqlGeneratorsRegistry.cs

示例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);
        }
开发者ID:xeno-by,项目名称:relinq,代码行数:36,代码来源:ExtensionToInstanceMethodForger.cs

示例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);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:16,代码来源:WrapperMethodBuilder.cs

示例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);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:16,代码来源:MethodOnTypeBuilderInst.cs


注:本文中的System.Reflection.MethodInfo.GetGenericMethodDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。