Esempio n. 1
0
        public EventDetail(RootDetail parent, EventInfo ei)
            : base(parent, ei)
        {
            _name       = ei.Name;
            _visibility = VisibilityUtil.GetVisibilityFor(ei.GetAddMethod(true));
            _category   = "event";

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            csb.AppendKeyword("event ");
            csb.AppendType(ei.EventHandlerType);
            csb.AppendText(" ");
            csb.AppendText(ei.Name);

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
Esempio n. 2
0
        public AttributeDetail(RootDetail parent, CustomAttributeData cad)
            : base(parent, cad.Constructor.DeclaringType.FullName)
        {
            _declaration = cad.ToString();

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.AppendType(cad.Constructor.DeclaringType);

            using (var e = cad.ConstructorArguments.GetEnumerator())
            {
                if (e.MoveNext())
                {
                    csb.AppendText("(");
                    csb.AppendQuotedValue(e.Current.Value);
                    while (e.MoveNext())
                    {
                        csb.AppendText(", ");
                        csb.AppendQuotedValue(e.Current.Value);
                    }
                    csb.AppendText(")");
                }
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();

            if (cad.AttributeType.IsAssignableFrom(typeof(ExtensionAttribute)))
            {
                AttributeType = AttributeType.Extension;
                AppendInCode  = false;
            }
            else if (cad.AttributeType.IsAssignableFrom(typeof(ObsoleteAttribute)))
            {
                AttributeType = AttributeType.Obsolete;
            }
            else if (cad.AttributeType.IsAssignableFrom(typeof(CompilerGeneratedAttribute)))
            {
                AttributeType = AttributeType.CompilerGenerated;
                AppendInCode  = false;
            }
        }
Esempio n. 3
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
            {
                IList <CustomAttributeData> cads = CustomAttributeData.GetCustomAttributes(mi);

                foreach (CustomAttributeData cad in cads)
                {
                    _children.Add(new AttributeDetail(this, cad));
                }
            }
            catch (TypeLoadException ex)
            {
                Log.Warn("Failed loading custom attribute data for type '{0}': {1}", parent.FullName, ex.Message);
            }
        }
Esempio n. 4
0
        public FieldDetail(RootDetail parent, FieldInfo fi)
            : base(parent, fi)
        {
            _name       = fi.Name;
            _visibility = VisibilityUtil.GetVisibilityFor(fi);
            _category   = "field";

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            if (fi.IsLiteral)
            {
                csb.AppendKeyword("const ");
            }
            else if (fi.IsStatic)
            {
                csb.AppendKeyword("static ");
            }

            if (fi.IsInitOnly)
            {
                csb.AppendKeyword("readonly ");
            }

            csb.AppendType(fi.FieldType);
            csb.AppendText(" ");
            csb.AppendText(fi.Name);

            if (fi.IsLiteral)
            {
                csb.AppendParameterValue(fi.GetRawConstantValue());
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
        public AttributeDetail(RootDetail parent, CustomAttributeData cad)
            : base(parent, cad.Constructor.DeclaringType.FullName)
        {
            _declaration = cad.ToString();

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.AppendType(cad.Constructor.DeclaringType);

            if (cad.ConstructorArguments.Count > 0)
            {
                csb.AppendText("(");
                csb.AppendQuotedValue(cad.ConstructorArguments[0].Value);
                csb.AppendText(")");
            }

            _declaration     = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
 public InterfaceDetail(RootDetail parent, Type type)
     : base(parent, type, true)
 {
     _category = "interface";
 }
Esempio n. 7
0
        public MethodDetail(RootDetail parent, MethodBase mi)
            : base(parent, mi)
        {
            CodeStringBuilder csb = new CodeStringBuilder(AppendMode.Text);

            csb.AppendMethodName(mi);
            _name = csb.ToString();

            _visibility = VisibilityUtil.GetVisibilityFor(mi);
            _category   = "method";

            MethodBody body = null;

            try
            {
                body = mi.GetMethodBody();
            }
            catch (VerificationException)
            {
                // "Operation could destabilize the runtime" on .NET 3.0 WPF PresentationCore.dll
            }

            if (body != null)
            {
                _body = GenericUtility.GetILAsHashedText(mi);
            }

            csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            MethodInfo bi = null;

            if (mi is MethodInfo)
            {
                bi = ((MethodInfo)mi).GetBaseDefinition();
            }

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            if (mi.IsAbstract)
            {
                if (!mi.DeclaringType.IsInterface)
                {
                    csb.AppendKeyword("abstract ");
                }
            }
            else if (mi.IsVirtual && !mi.IsFinal)
            {
                if (!object.ReferenceEquals(mi, bi))
                {
                    csb.AppendKeyword("override ");
                }
                else
                {
                    csb.AppendKeyword("virtual ");
                }
            }
            else if (mi.IsStatic)
            {
                csb.AppendKeyword("static ");
            }

            if (mi is MethodInfo)
            {
                csb.AppendParameter(((MethodInfo)mi).ReturnParameter);
            }

            csb.AppendText(" ");
            csb.AppendText(_name);
            csb.AppendText("(");

            // Add "this" keyword for extension methods.
            if (mi.CustomAttributes.Any(x => typeof(ExtensionAttribute).IsAssignableFrom(x.AttributeType)))
            {
                csb.AppendKeyword("this");
                csb.AppendText(" ");
            }


            CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);

            foreach (ParameterInfo pi in mi.GetParameters())
            {
                csb.AppendParameter(pi);
                csb.AppendText(", ");

                csbParameters.AppendParameterType(pi);
                csbParameters.AppendText(", ");

                _parameterCount++;
            }

            if (mi.GetParameters().Length > 0)
            {
                csb.RemoveCharsFromEnd(2);
                csbParameters.RemoveCharsFromEnd(2);
            }

            csb.AppendText(")");

            if (mi is MethodInfo)
            {
                csb.AppendGenericRestrictions(mi);
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
            _parameterTypesList  = csbParameters.ToString();
        }
Esempio n. 8
0
 public ResourcesDetail(RootDetail parent)
     : base(parent, "Resources")
 {
 }