예제 #1
0
        protected IGenericParameterInfo GetGenericMethodParameter(Type parameter)
        {
            IGenericParameterInfo wrapper = (IGenericParameterInfo)GetMethod((MethodInfo)parameter.DeclaringMethod).GenericArguments[parameter.GenericParameterPosition];

            Assert.IsNotNull(wrapper, "Could not find generic method parameter '{0}'.", parameter);
            return(wrapper);
        }
예제 #2
0
        public void GenericParameterWrapper(int position)
        {
            Type target = typeof(ReflectionPolicySample.Struct1 <,>).GetGenericArguments()[position];
            IGenericParameterInfo info = GetGenericTypeParameter(target);

            WrapperAssert.AreEquivalent(target, info, false);
        }
예제 #3
0
        private static void ValidateSlots(IMethodInfo method, IEnumerable <KeyValuePair <ISlotInfo, object> > slotValues)
        {
            foreach (KeyValuePair <ISlotInfo, object> slotValue in slotValues)
            {
                ISlotInfo slot = slotValue.Key;
                switch (slot.Kind)
                {
                case CodeElementKind.GenericParameter:
                    IGenericParameterInfo genericParameter = (IGenericParameterInfo)slot;
                    if (method.Equals(genericParameter.DeclaringMethod))
                    {
                        continue;
                    }
                    break;

                case CodeElementKind.Parameter:
                    IParameterInfo parameter = (IParameterInfo)slot;
                    if (method.Equals(parameter.Member))
                    {
                        continue;
                    }
                    break;
                }

                throw new ArgumentException(String.Format("Slot '{0}' is not valid for invoking method '{1}'.", slot, method), "slotValues");
            }
        }
예제 #4
0
        protected IGenericParameterInfo GetGenericTypeParameter(Type parameter)
        {
            IGenericParameterInfo wrapper = (IGenericParameterInfo)GetType(parameter.DeclaringType).GenericArguments[parameter.GenericParameterPosition];

            Assert.IsNotNull(wrapper, "Could not find generic type parameter '{0}'.", parameter);
            return(wrapper);
        }
예제 #5
0
        private void ResolveMethod()
        {
            int genericParameterCount = method.IsGenericMethodDefinition ? method.GenericArguments.Count : 0;

            resolvedGenericArguments = new Type[genericParameterCount];

            int seen = 0;

            foreach (KeyValuePair <ISlotInfo, object> slotValue in SlotValues)
            {
                IGenericParameterInfo genericParameter = slotValue.Key as IGenericParameterInfo;
                if (genericParameter != null)
                {
                    resolvedGenericArguments[genericParameter.Position] = (Type)Converter.Convert(slotValue.Value, typeof(Type));
                    seen += 1;
                }
            }

            if (genericParameterCount != seen)
            {
                throw new ArgumentException(String.Format("The method has {0} generic parameters but the bindings only provide values for {1} of them.",
                                                          genericParameterCount, seen));
            }

            resolvedMethod = ResolveMember(resolvedType, method.Resolve(true));
            if (genericParameterCount != 0)
            {
                resolvedMethod = resolvedMethod.MakeGenericMethod(resolvedGenericArguments);
            }
        }
예제 #6
0
        private static Type ResolveGenericParameter(IGenericParameterInfo genericParameter, MethodInfo methodContext)
        {
            IMethodInfo declaringMethod = genericParameter.DeclaringMethod;

            if (declaringMethod != null)
            {
                if (methodContext == null)
                {
                    methodContext = declaringMethod.Resolve(true);
                }

                return(methodContext.GetGenericArguments()[genericParameter.Position]);
            }

            return(genericParameter.DeclaringType.Resolve(true).GetGenericArguments()[genericParameter.Position]);
        }
 /// <inheritdoc />
 public bool Equals(IGenericParameterInfo other)
 {
     return(Equals((object)other));
 }
 public bool Equals(IGenericParameterInfo other)
 {
     return Equals((object)other);
 }
        private static Type ResolveGenericParameter(IGenericParameterInfo genericParameter, MethodInfo methodContext)
        {
            IMethodInfo declaringMethod = genericParameter.DeclaringMethod;
            if (declaringMethod != null)
            {
                if (methodContext == null)
                    methodContext = declaringMethod.Resolve(true);

                return methodContext.GetGenericArguments()[genericParameter.Position];
            }

            return genericParameter.DeclaringType.Resolve(true).GetGenericArguments()[genericParameter.Position];
        }