Exemple #1
0
        /// <summary>
        /// Gets the members that are visible from the provided type of the specified name.
        ///
        /// The default implemetnation first searches the type, then the flattened heirachy of the type, and then
        /// registered extension methods.
        /// </summary>
        public virtual MemberGroup GetMember(MemberRequestKind action, Type type, string name)
        {
            IEnumerable <MemberInfo> foundMembers = type.GetInheritedMembers(name);

            if (!PrivateBinding)
            {
                foundMembers = CompilerHelpers.FilterNonVisibleMembers(type, foundMembers);
            }

            MemberGroup members = new MemberGroup(foundMembers.ToArray());

            // check for generic types w/ arity...
            string          genName  = name + ReflectionUtils.GenericArityDelimiter;
            List <TypeInfo> genTypes = null;

            foreach (TypeInfo t in type.GetDeclaredNestedTypes())
            {
                if (t.IsPublic && t.Name.StartsWith(genName))
                {
                    if (genTypes == null)
                    {
                        genTypes = new List <TypeInfo>();
                    }

                    genTypes.Add(t);
                }
            }

            if (genTypes != null)
            {
                List <MemberTracker> mt = new List <MemberTracker>(members);
                foreach (TypeInfo t in genTypes)
                {
                    mt.Add(MemberTracker.FromMemberInfo(t));
                }
                return(MemberGroup.CreateInternal(mt.ToArray()));
            }

            if (members.Count == 0)
            {
                members = new MemberGroup(
                    type.GetInheritedMembers(name, flattenHierarchy: true).WithBindingFlags(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance).ToArray()
                    );

                if (members.Count == 0)
                {
                    members = GetAllExtensionMembers(type, name);
                }
            }

            return(members);
        }
Exemple #2
0
        /// <summary>
        /// Gets the members that are visible from the provided type of the specified name.
        ///
        /// The default implemetnation first searches the type, then the flattened heirachy of the type, and then
        /// registered extension methods.
        /// </summary>
        public virtual MemberGroup GetMember(OldDynamicAction action, Type type, string name)
        {
            MemberInfo[] foundMembers = type.GetMember(name);
            if (!PrivateBinding)
            {
                foundMembers = CompilerHelpers.FilterNonVisibleMembers(type, foundMembers);
            }

            MemberGroup members = new MemberGroup(foundMembers);

            // check for generic types w/ arity...
            Type[]      types    = type.GetNestedTypes(BindingFlags.Public);
            string      genName  = name + ReflectionUtils.GenericArityDelimiter;
            List <Type> genTypes = null;

            foreach (Type t in types)
            {
                if (t.Name.StartsWith(genName))
                {
                    if (genTypes == null)
                    {
                        genTypes = new List <Type>();
                    }
                    genTypes.Add(t);
                }
            }

            if (genTypes != null)
            {
                List <MemberTracker> mt = new List <MemberTracker>(members);
                foreach (Type t in genTypes)
                {
                    mt.Add(MemberTracker.FromMemberInfo(t));
                }
                return(MemberGroup.CreateInternal(mt.ToArray()));
            }

            if (members.Count == 0)
            {
                members = new MemberGroup(type.GetMember(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance));
                if (members.Count == 0)
                {
                    members = GetAllExtensionMembers(type, name);
                }
            }

            return(members);
        }
Exemple #3
0
        /// <summary>
        /// Gets the extension members of the given name from the provided type.  Subclasses of the
        /// type and their extension members are not searched.
        /// </summary>
        public MemberGroup GetExtensionMembers(Type declaringType, string name)
        {
            IList <Type>         extTypes = GetExtensionTypes(declaringType);
            List <MemberTracker> members  = new List <MemberTracker>();

            foreach (Type ext in extTypes)
            {
                foreach (MemberInfo mi in ext.GetDeclaredMembers(name).WithBindingFlags(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                {
                    MemberInfo newMember = mi;
                    if (PrivateBinding || (newMember = CompilerHelpers.TryGetVisibleMember(ext, mi)) != null)
                    {
                        if (IncludeExtensionMember(newMember))
                        {
                            if (ext != declaringType)
                            {
                                members.Add(MemberTracker.FromMemberInfo(newMember, declaringType));
                            }
                            else
                            {
                                members.Add(MemberTracker.FromMemberInfo(newMember));
                            }
                        }
                    }
                }

                // TODO: Support indexed getters/setters w/ multiple methods
                MethodInfo getter  = GetExtensionOperator(ext, "Get" + name);
                MethodInfo setter  = GetExtensionOperator(ext, "Set" + name);
                MethodInfo deleter = GetExtensionOperator(ext, "Delete" + name);

                if (getter != null || setter != null || deleter != null)
                {
                    members.Add(new ExtensionPropertyTracker(name, getter, setter, deleter, declaringType));
                }
            }

            if (members.Count != 0)
            {
                return(MemberGroup.CreateInternal(members.ToArray()));
            }
            return(MemberGroup.EmptyGroup);
        }
Exemple #4
0
        /// <summary>
        /// Gets the extension members of the given name from the provided type.  Subclasses of the
        /// type and their extension members are not searched.
        /// </summary>
        public MemberGroup GetExtensionMembers(Type declaringType, string name)
        {
            IList <Type>         extTypes = GetExtensionTypes(declaringType);
            List <MemberTracker> members  = new List <MemberTracker>();

            foreach (Type ext in extTypes)
            {
                foreach (MemberInfo mi in ext.GetMember(name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
                {
                    MemberInfo newMember = mi;
                    if (PrivateBinding || (newMember = CompilerHelpers.TryGetVisibleMember(mi)) != null)
                    {
                        if (ext != declaringType)
                        {
                            members.Add(MemberTracker.FromMemberInfo(newMember, declaringType));
                        }
                        else
                        {
                            members.Add(MemberTracker.FromMemberInfo(newMember));
                        }
                    }
                }

                // TODO: Support indexed getters/setters w/ multiple methods
                MethodInfo getter = null, setter = null, deleter = null;
                foreach (MemberInfo mi in ext.GetMember("Get" + name, MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                    {
                        continue;
                    }

                    Debug.Assert(getter == null);
                    getter = (MethodInfo)mi;
                }

                foreach (MemberInfo mi in ext.GetMember("Set" + name, MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                    {
                        continue;
                    }
                    Debug.Assert(setter == null);
                    setter = (MethodInfo)mi;
                }

                foreach (MemberInfo mi in ext.GetMember("Delete" + name, MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                    {
                        continue;
                    }
                    Debug.Assert(deleter == null);
                    deleter = (MethodInfo)mi;
                }

                if (getter != null || setter != null || deleter != null)
                {
                    members.Add(new ExtensionPropertyTracker(name, getter, setter, deleter, declaringType));
                }
            }

            if (members.Count != 0)
            {
                return(MemberGroup.CreateInternal(members.ToArray()));
            }
            return(MemberGroup.EmptyGroup);
        }
Exemple #5
0
        public MemberGroup GetExtensionMembers(Type type, string name)
        {
            Type curType = type;

            do
            {
                IList <Type>         extTypes = GetExtensionTypes(curType);
                List <MemberTracker> members  = new List <MemberTracker>();

                foreach (Type ext in extTypes)
                {
                    foreach (MemberInfo mi in ext.GetMember(name))
                    {
                        members.Add(MemberTracker.FromMemberInfo(mi, true));
                    }

                    // TODO: Support indexed getters/setters w/ multiple methods
                    MethodInfo getter = null, setter = null, deleter = null;
                    foreach (MemberInfo mi in ext.GetMember("Get" + name))
                    {
                        if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                        {
                            continue;
                        }

                        Debug.Assert(getter == null);
                        getter = (MethodInfo)mi;
                    }

                    foreach (MemberInfo mi in ext.GetMember("Set" + name))
                    {
                        if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                        {
                            continue;
                        }
                        Debug.Assert(setter == null);
                        setter = (MethodInfo)mi;
                    }

                    foreach (MemberInfo mi in ext.GetMember("Delete" + name))
                    {
                        if (!mi.IsDefined(typeof(PropertyMethodAttribute), false))
                        {
                            continue;
                        }
                        Debug.Assert(deleter == null);
                        deleter = (MethodInfo)mi;
                    }


#if FULL
                    if (getter != null || setter != null || deleter != null)
                    {
                        members.Add(new ExtensionPropertyTracker(name, getter, setter, deleter, curType));
                    }
#endif
                }

                if (members.Count != 0)
                {
                    return(MemberGroup.CreateInternal(members.ToArray()));
                }

                curType = curType.BaseType;
            } while (curType != null);

            return(MemberGroup.EmptyGroup);
        }