Exemplo n.º 1
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <MethodInfo>(this));
                }

                Type       declaringType        = (Type)DeclaringType.GetClrVersion();
                Type[]     genericArgumentTypes = GenericArguments.Select(p => (Type)p.GetClrVersion()).ToArray();
                MethodInfo foundMethod          = null;
                foreach (MethodInfo method in declaringType.GetMethods().Where(m => m.Name == Name))
                {
                    MethodInfo currentMethod = method;
                    if (currentMethod.IsGenericMethod)
                    {
                        if (currentMethod.GetGenericArguments().Length == genericArgumentTypes.Length)
                        {
                            currentMethod = currentMethod.MakeGenericMethod(genericArgumentTypes);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    ParameterInfo[] currentParameters = currentMethod.GetParameters();
                    if (ParameterTypes.Count == currentParameters.Length)
                    {
                        bool allArumentsFit = true;
                        for (int i = 0; i < ParameterTypes.Count && i < currentParameters.Length; i++)
                        {
                            Type currentArg       = (Type)ParameterTypes[i].GetClrVersion();
                            Type currentParamType = currentParameters[i].ParameterType;
                            if (!currentParamType.IsAssignableFrom(currentArg))
                            {
                                allArumentsFit = false;
                                break;
                            }
                        }
                        if (allArumentsFit)
                        {
                            foundMethod = currentMethod;
                        }
                    }
                }

                if (foundMethod == null)
                {
                    throw new Exception(string.Format("Method \"{0}.{1}\" not found.", declaringType, Name));
                }
                tsInstance.SetClrVersion(this, foundMethod);
                return(foundMethod);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <Type>(this));
                }
                Type createdType = CreateClrType();
                tsInstance.SetClrVersion(this, createdType);
                return(createdType);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <ConstructorInfo>(this));
                }

                Type            declaringType    = (Type)DeclaringType.GetClrVersion();
                ConstructorInfo foundConstructor = declaringType.GetConstructor(ParameterTypes.Select(p => (Type)p.GetClrVersion()).ToArray());
                tsInstance.SetClrVersion(this, foundConstructor);
                return(foundConstructor);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <FieldInfo>(this));
                }

                Type      declaringType = (Type)DeclaringType.GetClrVersion();
                FieldInfo foundField    = declaringType.GetField(Name);
                tsInstance.SetClrVersion(this, foundField);
                return(foundField);
            }
        }
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <ConstructorInfo>(this));
                }

#if !NETFX_CORE
                Type            declaringType    = (Type)DeclaringType.GetClrVersion();
                ConstructorInfo foundConstructor = declaringType.GetConstructor(ParameterTypes.Select(p => (Type)p.GetClrVersion()).ToArray());
#else
                Type            declaringType    = ((TypeInfo)DeclaringType.GetClrVersion()).AsType();
                ConstructorInfo foundConstructor = declaringType.GetTypeInfo().DeclaredConstructors.FirstOrDefault(x => Enumerable.SequenceEqual(x.GetParameters().Select(y => y.ParameterType), ParameterTypes.Select(p => ((TypeInfo)p.GetClrVersion()).AsType())));
#endif
                tsInstance.SetClrVersion(this, foundConstructor);
                return(foundConstructor);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <FieldInfo>(this));
                }

#if !NETFX_CORE
                Type      declaringType = (Type)DeclaringType.GetClrVersion();
                FieldInfo foundField    = declaringType.GetField(Name);
#else
                Type      declaringType = ((TypeInfo)DeclaringType.GetClrVersion()).AsType();
                FieldInfo foundField    = declaringType.GetTypeInfo().DeclaredFields.FirstOrDefault(x => x.Name == Name);
#endif
                tsInstance.SetClrVersion(this, foundField);
                return(foundField);
            }
        }
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
                    return(tsInstance.GetClrVersion <PropertyInfo>(this));
                }

#if !NETFX_CORE
                Type         declaringType = (Type)DeclaringType.GetClrVersion();
                PropertyInfo foundProperty = declaringType.GetProperty(Name);
#else
                Type         declaringType = ((TypeInfo)DeclaringType.GetClrVersion()).AsType();
                PropertyInfo foundProperty = declaringType.GetTypeInfo().GetDeclaredProperty(Name);
#endif
                tsInstance.SetClrVersion(this, foundProperty);
                return(foundProperty);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the CLR <see cref="MemberInfo"/>.
        /// </summary>
        /// <returns>Returns the CLR <see cref="MemberInfo"/>.</returns>
        public override MemberInfo GetClrVersion()
        {
            InterLinqTypeSystem tsInstance = InterLinqTypeSystem.Instance;

            lock (tsInstance)
            {
                if (tsInstance.IsInterLinqMemberInfoRegistered(this))
                {
#if !NETFX_CORE
                    return(tsInstance.GetClrVersion <Type>(this));
#else
                    return(tsInstance.GetClrVersion <TypeInfo>(this));
#endif
                }
                Type createdType = CreateClrType();
#if !NETFX_CORE
                tsInstance.SetClrVersion(this, createdType);
                return(createdType);
#else
                tsInstance.SetClrVersion(this, createdType.GetTypeInfo());
                return(createdType.GetTypeInfo());
#endif
            }
        }