Exemple #1
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            return(DeclaringType.ToType(genericArguments).GetField(_name
#if USE_SLIM
                                                                   , _fieldType.ToType(genericArguments)
#endif
                                                                   ));
        }
Exemple #2
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            return(DeclaringType.ToType(genericArguments).GetProperty(_name
#if USE_SLIM
                                                                      , _propertyType.ToType(genericArguments)
                                                                      , EmptyReadOnlyCollection <Type> .Instance
                                                                      , false // REVIEW
#endif
                                                                      ));
        }
Exemple #3
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            var n = _parameterTypes.Length;

            var parameterTypes = new Type[n];

            for (var i = 0; i < n; i++)
            {
                parameterTypes[i] = _parameterTypes[i].ToType(genericArguments);
            }

            var returnType = _returnType.ToType(genericArguments);

            var declaringType = DeclaringType.ToType(genericArguments);

#if USE_SLIM
            return(declaringType.GetSimpleMethod(_name, new ReadOnlyCollection <Type>(parameterTypes), returnType));
#else
            var methods = declaringType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            foreach (var method in methods)
            {
                if (method.Name == _name)
                {
                    if (method.ReturnType == returnType)
                    {
                        var pars = method.GetParameters();

                        if (pars.Length == n)
                        {
                            var found = true;

                            for (var i = 0; i < n; i++)
                            {
                                if (pars[i].ParameterType != parameterTypes[i])
                                {
                                    found = false;
                                    break;
                                }
                            }

                            if (found)
                            {
                                return(method);
                            }
                        }
                    }
                }
            }

            throw new InvalidOperationException("Method not found.");
#endif
        }
Exemple #4
0
        /// <summary>
        /// Gets the the declaring type.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">DeclaringType is not set.</exception>
        /// <exception cref="System.TypeLoadException">Failed to load DeclaringType:  + this.DeclaringType</exception>
        protected Type GetDeclaringType(IExpressionContext context)
        {
            if (DeclaringType == null)
            {
                throw new InvalidOperationException("DeclaringType is not set.");
            }

            var declaringType = DeclaringType.ToType(context);

            if (declaringType == null)
            {
                throw new TypeLoadException("Failed to load DeclaringType: " + DeclaringType);
            }

            return(declaringType);
        }
Exemple #5
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            var n = _parameterTypes.Length;

            var parameterTypes = new Type[n];

            for (var i = 0; i < n; i++)
            {
                parameterTypes[i] = _parameterTypes[i].ToType(genericArguments);
            }

            return(DeclaringType.ToType(genericArguments).GetConstructor(
#if USE_SLIM
                       new ReadOnlyCollection <Type>(parameterTypes)
#else
                       parameterTypes
#endif
                       ));
        }
Exemple #6
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            var n = _parameterTypes.Length;

            var parameterTypes = new Type[n];

            for (var i = 0; i < n; i++)
            {
                parameterTypes[i] = _parameterTypes[i].ToType(genericArguments);
            }

            return(DeclaringType.ToType(genericArguments).GetProperty(_name,
#if USE_SLIM
                                                                      _propertyType.ToType(genericArguments),
                                                                      new ReadOnlyCollection <Type>(parameterTypes),
                                                                      false // REVIEW
#else
                                                                      parameterTypes
#endif
                                                                      ));
        }
Exemple #7
0
        protected override MemberInfo ToMemberCore(Epyt[] genericArguments)
        {
            var n = _parameterTypes.Length;

#if USE_SLIM
            var declaringType = DeclaringType.ToType(EmptyArray <Epyt> .Instance);

            var genericParameters     = new Epyt[Arity];
            var genericParameterTypes = new Type[Arity];

            for (var i = 0; i < Arity; i++)
            {
                var parameter = Type.GenericParameter("T" + i);
                genericParameterTypes[i] = parameter;
                genericParameters[i]     = new UnboundGenericParameterEpyt(parameter);
            }

            var parameterTypes = new Type[n];

            for (var i = 0; i < n; i++)
            {
                parameterTypes[i] = _parameterTypes[i].ToType(genericParameters);
            }

            var returnType = _returnType.ToType(genericParameters);

            return(declaringType.GetGenericDefinitionMethod(
                       _name,
                       new ReadOnlyCollection <Type>(genericParameterTypes),
                       new ReadOnlyCollection <Type>(parameterTypes),
                       returnType
                       ));
#else
            var declaringType = DeclaringType.ToType(genericArguments); // REVIEW: Does this work for generic methods on generic types?

            var candidates = new List <MethodInfo>();

            foreach (var method in declaringType.GetMethods())
            {
                if (method.IsGenericMethodDefinition && method.Name == _name)
                {
                    var genArgs    = method.GetGenericArguments();
                    var parameters = method.GetParameters();

                    if (genArgs.Length == Arity && parameters.Length == n)
                    {
                        candidates.Add(method);
                    }
                }
            }

            foreach (var candidate in candidates)
            {
                var genArgs = candidate.GetGenericArguments();

                var arity = genArgs.Length;

                var genArgsTypes = new Epyt[arity];

                for (var i = 0; i < arity; i++)
                {
                    genArgsTypes[i] = new SimpleEpyt(genArgs[i]);
                }

                var parameters = candidate.GetParameters();

                var match = true;

                for (var i = 0; i < n; i++)
                {
                    var parameterType = _parameterTypes[i].ToType(genArgsTypes);
                    if (parameters[i].ParameterType != parameterType)
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    var returnType = _returnType.ToType(genArgsTypes);
                    if (candidate.ReturnType != returnType)
                    {
                        match = false;
                    }
                }

                if (match)
                {
                    return(candidate); // TODO: continue to detect ambiguity?
                }
            }

            throw new NotImplementedException();
#endif
        }
Exemple #8
0
 public MethodInfo ToMethod(AppDomain domain)
 {
     Type[] parameterTypes = ParameterTypes.Select(t => t.ToType(domain)).ToArray();
     return(DeclaringType.ToType(domain).GetMethod(MethodName, parameterTypes));
 }