Example #1
0
        protected void AddConstructors(Type type, LookupListItem item)
        {
            BindingFlags bindingAttr =
                BindingFlags.Public |
                BindingFlags.FlattenHierarchy |
                BindingFlags.Instance;

            ConstructorInfo[] cia = type.GetConstructors(bindingAttr);

            foreach (ConstructorInfo ci in cia)
            {
                LookupMenuItem lmi = new LookupMenuItem();
                lmi.DisplayText = CSharpFormattingTools.
                                  GetConstructorSignature(ci, type);
                lmi.InsertText = CSharpFormattingTools.
                                 GetMinimalConstructorSignature(ci, type);

                item.MenuItems.Add(lmi);
            }
        }
Example #2
0
        private List <MemberTagData> GetTypeMembers(Type type)
        {
            List <MemberTagData> memberList = new List <MemberTagData>();

            BindingFlags flags =
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.Static;

            if (!_hideNonPublicMembers)
            {
                flags |= BindingFlags.NonPublic;
            }

            if (_hideInheritedMembers)
            {
                flags |= BindingFlags.DeclaredOnly;
            }
            else
            {
                flags |= BindingFlags.FlattenHierarchy;
            }

            MemberInfo[] members = type.GetMembers(flags);

            bool hasExtensionMethods = false;

            hasExtensionMethods = type.GetCustomAttributes(
                typeof(ExtensionAttribute), false).Length > 0;

            foreach (MemberInfo memberInfo in members)
            {
                MemberTagData mtd = new MemberTagData();
                mtd.Name = memberInfo.Name;
                mtd.Info = memberInfo;

                switch (memberInfo.MemberType)
                {
                case MemberTypes.NestedType:
                    continue;

                case MemberTypes.Constructor:
                    ConstructorInfo ci = (ConstructorInfo)memberInfo;

                    /*
                     * Even though constructors are special names
                     * for convenience sake we don't hide them.
                     */
                    //if (_hideSpecialNames && ci.IsSpecialName) continue;
                    mtd.Name     = CSharpFormattingTools.GetConstructorSignature(ci, type);
                    mtd.ImageKey = GetMemberImageKey(Constants.METHOD,
                                                     ci.IsPrivate, ci.IsFamily, ci.IsFamilyAndAssembly);
                    break;

                case MemberTypes.Method:
                    MethodInfo mi = (MethodInfo)memberInfo;
                    if (_hideSpecialNames && mi.IsSpecialName)
                    {
                        continue;
                    }

                    bool isExtensionMethod = false;

                    if (hasExtensionMethods)
                    {
                        isExtensionMethod = mi.GetCustomAttributes(
                            typeof(ExtensionAttribute), false).Length > 0;
                    }

                    mtd.Name = CSharpFormattingTools.
                               GetMethodSignature(mi, isExtensionMethod);

                    if (isExtensionMethod)
                    {
                        mtd.ImageKey = Constants.METHOD_EXTENSION;
                    }
                    else
                    {
                        mtd.ImageKey = GetMemberImageKey(Constants.METHOD,
                                                         mi.IsPrivate, mi.IsFamily, mi.IsFamilyAndAssembly);
                    }

                    break;

                case MemberTypes.Field:
                    FieldInfo fi = (FieldInfo)memberInfo;
                    if (_hideSpecialNames && fi.IsSpecialName)
                    {
                        continue;
                    }
                    mtd.ImageKey = GetMemberImageKey(
                        (fi.IsLiteral) ? Constants.CONSTANT : Constants.FIELD,
                        fi.IsPrivate, fi.IsFamily, fi.IsFamilyAndAssembly);
                    break;

                case MemberTypes.Property:
                    mtd.ImageKey = Constants.PROPERTIES;
                    break;

                case MemberTypes.Event:
                    mtd.ImageKey = Constants.EVENT;
                    break;
                }

                memberList.Add(mtd);
            }

            return(memberList);
        }