Example #1
0
        public AssemblyDetail(Assembly assembly)
        {
            _name = "";
            _location = assembly.Location;

            _children.Add(new TraitDetail(this, "FullName", assembly.FullName));
            _children.Add(new TraitDetail(this, "Version", assembly.GetName().Version.ToString()));
            _children.Add(new TraitDetail(this, "RuntimeVersion", assembly.ImageRuntimeVersion));
            _children.Add(new TraitDetail(this, "PublicKeyToken", GenericUtility.GetHashText(assembly.GetName().GetPublicKeyToken())));
            _children.Add(new TraitDetail(this, "Flags", assembly.GetName().Flags.ToString()));

            AttributesDetail attributes = new AttributesDetail(this);
            _children.Add(attributes);
            foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(assembly))
            {
                AttributeDetail ad = new AttributeDetail(attributes, cad);
                ad.Visibility = Visibility.Exported;
                attributes.Children.Add(ad);
            }

            ResourcesDetail resources = new ResourcesDetail(this);
            _children.Add(resources);
            foreach (string resource in assembly.GetManifestResourceNames())
            {
                resources.Children.Add(new ResourceDetail(resources, resource, GenericUtility.ReadStream(assembly, resource)));
            }

            ReferencesDetail references = new ReferencesDetail(this);
            _children.Add(references);
            foreach (AssemblyName an in assembly.GetReferencedAssemblies())
            {
                references.Children.Add(new ReferenceDetail(references, an));
            }

            Type[] types = assembly.GetTypes();

            foreach (Type type in types)
            {
                if (!type.IsNested)
                {
                    NamespaceDetail ns = FindOrCreateNamespace(type.Namespace);

                    if (type.IsEnum)
                    {
                        ns.Children.Add(new EnumDetail(ns, type));
                    }
                    else if (type.IsInterface)
                    {
                        ns.Children.Add(new InterfaceDetail(ns, type));
                    }
                    else if (type.IsClass)
                    {
                        ns.Children.Add(new ClassDetail(ns, type));
                    }
                }
            }
        }
Example #2
0
        public MemberDetail(RootDetail parent, MemberInfo mi)
            : base(parent, "")
        {
            // In some cases attributes do not resolve with .winmd files so this logs a warning but continues
            try
            {
                var cads = CustomAttributeData.GetCustomAttributes(mi)
                           .OrderBy(x => x.AttributeType.Name)
                           .ThenBy(x => x.AttributeType.Namespace)
                           .ThenBy(x => x.ConstructorArguments.Count)
                           .ThenBy(x => x.ConstructorArguments.FirstOrDefault().Value);

                foreach (CustomAttributeData cad in cads)
                {
                    var attribute = new AttributeDetail(this, cad);
                    switch (attribute.AttributeType)
                    {
                    case AttributeType.Obsolete:
                        // We found an ObsoleteAttribute; store a reference to it on the member itself.
                        // There *should* be only one ObsoleteAttribute on a member, but IL does not prohibit it (C# does)
                        // and so code generators like Fody.Obsolete can accidentally add a second one.
                        // In this case, take the first as the "winner", as Microsoft's compiler behaves this way.
                        if (_obsoleteAttribute == null)
                        {
                            _obsoleteAttribute = attribute;
                        }

                        break;
                    }

                    _children.Add(attribute);
                }
            }
            catch (TypeLoadException ex)
            {
                Log.Warn("Failed loading custom attribute data for type '{0}': {1}", parent.FullName, ex.Message);
            }
        }
        public AssemblyDetail(Assembly assembly)
        {
            _name     = "";
            _location = assembly.Location;

            _children.Add(new TraitDetail(this, "FullName", assembly.FullName));
            _children.Add(new TraitDetail(this, "Version", assembly.GetName().Version.ToString()));
            _children.Add(new TraitDetail(this, "RuntimeVersion", assembly.ImageRuntimeVersion));
            _children.Add(new TraitDetail(this, "PublicKeyToken", GenericUtility.GetHashText(assembly.GetName().GetPublicKeyToken())));
            _children.Add(new TraitDetail(this, "Flags", assembly.GetName().Flags.ToString()));

            AttributesDetail attributes = new AttributesDetail(this);

            _children.Add(attributes);
            foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(assembly))
            {
                AttributeDetail ad = new AttributeDetail(attributes, cad);
                ad.Visibility = Visibility.Exported;
                attributes.Children.Add(ad);
            }

            ResourcesDetail resources = new ResourcesDetail(this);

            _children.Add(resources);
            foreach (string resource in assembly.GetManifestResourceNames())
            {
                resources.Children.Add(new ResourceDetail(resources, resource, GenericUtility.ReadStream(assembly, resource)));
            }

            ReferencesDetail references = new ReferencesDetail(this);

            _children.Add(references);
            foreach (AssemblyName an in assembly.GetReferencedAssemblies())
            {
                references.Children.Add(new ReferenceDetail(references, an));
            }

            Type[] types = assembly.GetTypes();

            foreach (Type type in types)
            {
                try
                {
                    if (!type.IsNested)
                    {
                        NamespaceDetail ns = FindOrCreateNamespace(type.Namespace);

                        if (type.IsEnum)
                        {
                            ns.Children.Add(new EnumDetail(ns, type));
                        }
                        else if (type.IsInterface)
                        {
                            ns.Children.Add(new InterfaceDetail(ns, type));
                        }
                        else if (type.IsClass)
                        {
                            ns.Children.Add(new ClassDetail(ns, type));
                        }
                    }
                }
                catch (TypeLoadException tle)
                {
                    Log.Warn("Failed loading Type '{0}': {1}", type.FullName, tle.Message);
                }
            }
        }