コード例 #1
0
ファイル: ApiFilter.cs プロジェクト: paulushub/SandAssists
 public virtual bool IsExposedMember(Member member)
 {
     if (member == null)
     {
         throw new ArgumentNullException("member");
     }
     return(apiFilter.IsExposedMember(member));
 }
コード例 #2
0
        /// <summary>
        /// This is used to see if a member is exposed
        /// </summary>
        /// <param name="Member">The member node to check</param>
        /// <returns>True if the member is exposed, false if not</returns>
        public virtual bool IsExposedMember(Member member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            // !EFW - Bug fix.  Some obfuscated assemblies have mangled names containing characters that
            // are not valid in XML.  Exclude those by default.
            if (member.FullName.HasInvalidXmlCharacters())
            {
                return(false);
            }

            // !EFW - Bug fix.  If not a recognized visibility, ignore it as it's probably an obfuscated
            // member and it won't be of any use anyway.
            if (!member.IsPublic && !member.IsAssembly && !member.IsFamilyOrAssembly && !member.IsFamily &&
                !member.IsFamilyAndAssembly && !member.IsPrivate)
            {
                return(false);
            }

            TypeNode type = member.DeclaringType;

            // Members of delegates are not exposed
            if (type.NodeType == NodeType.DelegateNode)
            {
                return(false);
            }

            // Accessor methods for properties and events are not exposed
            if (member.IsSpecialName && member.NodeType == NodeType.Method)
            {
                string name = member.Name.Name;

                if (name.Contains("get_"))
                {
                    return(false);
                }

                if (name.Contains("set_"))
                {
                    return(false);
                }

                // !EFW - Added for Windows Store/Phone
                if (name.Contains("put_"))
                {
                    return(false);
                }

                if (name.Contains("add_"))
                {
                    return(false);
                }

                if (name.Contains("remove_"))
                {
                    return(false);
                }

                if (name.Contains("raise_"))
                {
                    return(false);
                }
            }

            // The value field of enumerations is not exposed
            if (member.IsSpecialName && type.NodeType == NodeType.EnumNode && member.NodeType == NodeType.Field &&
                member.Name.Name == "value__")
            {
                return(false);
            }

            // Members marked as compiler-generated are not exposed unless public and wanted
            if (member.Attributes.Any(attr => attr.Type.FullName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute") &&
                (!this.IncludePublicCompilerGenerated || !member.IsPublic))
            {
                return(false);
            }

            // Members marked with an EditorBrowsableAttribute set to Never based on the visibility settings
            if (!this.IncludeEditorBrowsableNever)
            {
                // Only the current member is checked.  Overridden members in base types are not checked for the
                // attribute.  This mimics the behavior of the Object Browser which works the same way.  Unless
                // the attribute is actually present and set to Never, the member will appear.
                if (!IsEditorBrowsable(member.Attributes))
                {
                    return(false);
                }
            }

            // Members marked with a BrowsableAttribute set to False based on the visibility settings
            if (!this.IncludeNonBrowsable)
            {
                // As above, only the current member is checked
                if (!IsBrowsable(member.Attributes))
                {
                    return(false);
                }
            }

            // If not visible based on the visibility settings, ignore it
            if (!this.IsVisible(member))
            {
                return(false);
            }

            // One more test to deal with a weird case: a private method is an explicit implementation for
            // a property accessor, but is not marked with the special name flag. To find these, test for
            // the accessibility of the methods they implement.
            if (member.IsPrivate && member.NodeType == NodeType.Method)
            {
                Method     method     = (Method)member;
                MethodList implements = method.ImplementedInterfaceMethods;

                if (implements != null && implements.Count > 0 && !this.IsExposedMember(implements[0]))
                {
                    return(false);
                }
            }

            // Same for explicit property implementations
            if (member.IsPrivate && member.NodeType == NodeType.Property)
            {
                Property property   = (Property)member;
                var      implements = property.GetImplementedProperties().ToList();

                if (implements.Count > 0 && !this.IsExposedMember(implements[0]))
                {
                    return(false);
                }
            }

            // Same for explicit event implementations
            if (member.IsPrivate && member.NodeType == NodeType.Event)
            {
                Event evt        = (Event)member;
                var   implements = evt.GetImplementedEvents().ToList();

                if (implements.Count > 0 && !this.IsExposedMember(implements[0]))
                {
                    return(false);
                }
            }

            // Okay, passed all tests, the member is exposed as long as the base filters allow it
            return(apiFilter.IsExposedMember(member));
        }