Ejemplo n.º 1
0
		public TypeDetail(RootDetail parent, Type type)
			: base(parent, type)
		{
			CodeStringBuilder csb = new CodeStringBuilder(AppendMode.Text);
			csb.AppendType(type, false);
			_name = csb.ToString();
		}
Ejemplo n.º 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.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

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

            csb.Mode = AppendMode.Html;
            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.Both;

            _declaration = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
Ejemplo n.º 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.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            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();
        }
Ejemplo n.º 4
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);

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

            _declaration = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
Ejemplo n.º 5
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.Html;
			csb.AppendVisibility(_visibility);
			csb.AppendText(" ");
			csb.Mode = AppendMode.Both;

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

			_declaration = csb.ToString();
			_declarationHtml = csb.ToHtmlString();
		}
Ejemplo n.º 6
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.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            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("(");

            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();
            _parameterTypesList = csbParameters.ToString();
        }
Ejemplo n.º 7
0
        public PropertyDetail(RootDetail parent, PropertyInfo pi)
            : base(parent, pi)
        {
            _name = pi.Name;
            _category = "property";

            MethodInfo[] methods = pi.GetAccessors(true);
            foreach (MethodInfo mi in methods)
            {
                MethodDetail m = new MethodDetail(this, mi);

                if ((m.Name.Length > 3) && (mi.IsSpecialName))
                {
                    m.Name = m.Name.Substring(0, 3);
                }

                m.Declaration = null;
                _children.Add(m);
            }

            if (pi.GetIndexParameters().Length > 0)
            {
                CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);

                foreach (ParameterInfo ip in pi.GetIndexParameters())
                {
                    csbParameters.AppendParameterType(ip);
                    csbParameters.AppendText(", ");

                    _parameterCount++;
                }

                csbParameters.RemoveCharsFromEnd(2);

                _parameterTypesList = csbParameters.ToString();
            }

            _visibility = VisibilityUtil.GetMostVisible(FilterChildren<MethodDetail>());

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            csb.AppendType(pi.PropertyType);
            csb.AppendText(" ");
            csb.AppendText(pi.Name);

            if (this.ParameterCount > 0)
            {
                csb.AppendText("[");
                csb.AppendText(this.ParameterTypesList);
                csb.AppendText("]");
            }

            csb.Mode = AppendMode.Html;

            csb.AppendNewline();
            csb.AppendText("{");
            csb.AppendNewline();
            csb.AppendIndent();

            foreach (MethodDetail mi in FilterChildren<MethodDetail>())
            {
                if (mi.Visibility != _visibility)
                {
                    csb.AppendVisibility(mi.Visibility);
                    csb.AppendText(" ");
                }

                csb.AppendText(mi.Name);
                csb.AppendText("; ");
            }

            csb.AppendNewline();
            csb.AppendText("}");

            _declaration = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
Ejemplo n.º 8
0
        protected virtual void AppendAttributesDeclaration(CodeStringBuilder csb)
        {
            AppendMode oldMode = csb.Mode;
            csb.Mode = AppendMode.Html;

            foreach (AttributeDetail ad in FilterChildren<AttributeDetail>())
            {
                csb.AppendText("[");
                csb.AppendRawHtml(ad.GetHtmlDeclaration());
                csb.AppendText("]");
                csb.AppendNewline();
            }

            csb.Mode = oldMode;
        }
Ejemplo n.º 9
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.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            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();
        }