Exemple #1
0
        /// <summary>
        /// 根据Target重新定义当前方法的泛型参数
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        internal bool ResetGenericArgumentsWithTarget(GenericMethodInfo target)
        {
            var genericArguments = new Type[GenericDefinitionArguments.Length];

            Array.Copy(GenericDefinitionArguments, genericArguments, GenericDefinitionArguments.Length);
            for (var i = 0; i < Parameters.Length; i++)
            {
                genericArguments.CompareExchange(Parameters[i].ParameterType, target.Parameters[i].ParameterType);
            }
            genericArguments.CompareExchange(Method.ReturnType, target.Method.ReturnType);

            if (genericArguments.Any(x => x.IsGenericParameter))
            {
                if (target.GenericDefinitionArguments == null)
                {
                    return(false);
                }
                for (var i = 0; i < genericArguments.Length; i++)
                {
                    var arg = genericArguments[i];
                    if (arg.IsGenericParameter)
                    {
                        var newArg = target.GetGenericArgumentByDefineName(arg.Name);
                        if (newArg == null)
                        {
                            return(false);
                        }
                        genericArguments[i] = newArg;
                    }
                }
            }
            GenericArguments = genericArguments;
            return(true);
        }
Exemple #2
0
 /// <summary>
 /// 检查兼容性
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 internal bool Compatible(GenericMethodInfo target)
 {
     if (target.Parameters == null || Parameters == null)
     {
         return(false);
     }
     if (target.Parameters.Length != Parameters.Length ||
         target.GenericArguments == null ||
         (Method.ReturnType == typeof(void) && target.Method.ReturnType != typeof(void)) ||
         (Method.ReturnType != typeof(void) && target.Method.ReturnType == typeof(void)))
     {
         return(false);
     }
     return(true);
 }