Exemple #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();
        }
Exemple #2
0
        public EnumDetail(RootDetail parent, Type type)
            : base(parent, type)
        {
            _visibility = VisibilityUtil.GetVisibilityFor(type);
            _category   = "enum";

            foreach (string name in Enum.GetNames(type))
            {
                _children.Add(
                    new EnumItemDetail(
                        this,
                        name,
                        Convert.ToInt64(
                            type.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                            .GetRawConstantValue()),
                        _visibility));
            }

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

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

            csb.AppendKeyword("enum ");
            csb.AppendText(type.Name);

            csb.Mode = AppendMode.NonText;
            csb.AppendNewline();
            csb.AppendText("{");
            csb.AppendNewline();

            foreach (EnumItemDetail eid in FilterChildren <EnumItemDetail>())
            {
                csb.AppendIndent();
                csb.AppendText(eid.GetHtmlDeclaration());
                csb.AppendText(",");
                csb.AppendNewline();
            }

            csb.RemoveCharsFromEnd("<br>".Length);
            csb.RemoveCharsFromEnd(",".Length);
            csb.AppendNewline();
            csb.AppendText("}");
            csb.Mode = AppendMode.All;

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
Exemple #3
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();
        }
Exemple #4
0
        public EntityDetail(RootDetail parent, Type type, bool takeVisibilityFromParent)
            : base(parent, type)
        {
            _visibility = VisibilityUtil.GetVisibilityFor(type);

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

            List <MethodBase> methods = FilterMethods(type.GetMethods(flags), type, false);

            foreach (MethodBase mi in methods)
            {
                MethodDetail md = new MethodDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    md.Visibility = _visibility;
                }

                _children.Add(md);
            }

            List <MethodBase> constructors = FilterMethods(type.GetConstructors(flags), type, false);

            foreach (MethodBase mi in constructors)
            {
                MethodDetail md = new MethodDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    md.Visibility = _visibility;
                }

                _children.Add(md);
            }

            List <MethodBase> operators = FilterMethods(type.GetMethods(flags), type, true);

            foreach (MethodBase mi in operators)
            {
                OperatorDetail od = new OperatorDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    od.Visibility = _visibility;
                }

                _children.Add(od);
            }

            List <PropertyInfo> props = FilterProperties(type.GetProperties(flags), type);

            foreach (PropertyInfo pi in props)
            {
                PropertyDetail pd = new PropertyDetail(this, pi);

                if (takeVisibilityFromParent)
                {
                    pd.Visibility = _visibility;
                }

                _children.Add(pd);
            }

            List <EventInfo> events = FilterEvents(type.GetEvents(flags), type);

            foreach (EventInfo ei in events)
            {
                EventDetail ed = new EventDetail(this, ei);

                if (takeVisibilityFromParent)
                {
                    ed.Visibility = _visibility;
                }

                _children.Add(ed);
            }

            List <FieldInfo> fields = FilterFields(type.GetFields(flags), type);

            foreach (FieldInfo fi in fields)
            {
                FieldDetail fd = new FieldDetail(this, fi);

                if (takeVisibilityFromParent)
                {
                    fd.Visibility = _visibility;
                }

                _children.Add(fd);
            }

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

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

            if (type.IsAbstract && type.IsSealed)
            {
                csb.AppendKeyword("static ");
            }
            else if (type.IsInterface)
            {
                csb.AppendKeyword("interface ");
            }
            else if (type.IsAbstract)
            {
                csb.AppendKeyword("abstract ");
            }
            else if (type.IsSealed)
            {
                csb.AppendKeyword("sealed ");
            }

            if (type.IsClass)
            {
                csb.AppendKeyword("class ");
            }

            csb.AppendText(_name);

            csb.AppendBaseClasses(type);

            csb.AppendGenericRestrictions(type);

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
Exemple #5
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();
        }