OutputAttributes() public static méthode

public static OutputAttributes ( XmlDocument doc, XmlNode parent, IList attributes ) : void
doc System.Xml.XmlDocument
parent System.Xml.XmlNode
attributes IList
Résultat void
Exemple #1
0
        public static void OutputGenericParameters(XmlDocument document, XmlNode nclass, IGenericParameterProvider provider)
        {
            if (provider.GenericParameters.Count == 0)
            {
                return;
            }

            var gparameters = provider.GenericParameters;

            XmlElement ngeneric = document.CreateElement(string.Format("generic-parameters"));

            nclass.AppendChild(ngeneric);

            foreach (GenericParameter gp in gparameters)
            {
                XmlElement nparam = document.CreateElement(string.Format("generic-parameter"));
                nparam.SetAttribute("name", gp.Name);
                nparam.SetAttribute("attributes", ((int)gp.Attributes).ToString());

                AttributeData.OutputAttributes(document, nparam, gp.CustomAttributes);

                ngeneric.AppendChild(nparam);

                var constraints = gp.Constraints;
                if (constraints.Count == 0)
                {
                    continue;
                }

                XmlElement nconstraint = document.CreateElement("generic-parameter-constraints");

                foreach (TypeReference constraint in constraints)
                {
                    XmlElement ncons = document.CreateElement("generic-parameter-constraint");
                    ncons.SetAttribute("name", Utils.CleanupTypeName(constraint));
                    nconstraint.AppendChild(ncons);
                }

                nparam.AppendChild(nconstraint);
            }
        }
Exemple #2
0
        public override void DoOutput()
        {
            XmlNode parametersNode = document.CreateElement("parameters");

            parent.AppendChild(parametersNode);

            foreach (ParameterDefinition parameter in parameters)
            {
                XmlNode paramNode = document.CreateElement("parameter");
                parametersNode.AppendChild(paramNode);
                AddAttribute(paramNode, "name", parameter.Name);
                AddAttribute(paramNode, "position", parameter.Method.Parameters.IndexOf(parameter).ToString(CultureInfo.InvariantCulture));
                AddAttribute(paramNode, "attrib", ((int)parameter.Attributes).ToString());

                string direction = "in";

                if (parameter.ParameterType is ByReferenceType)
                {
                    direction = parameter.IsOut ? "out" : "ref";
                }

                TypeReference t = parameter.ParameterType;
                AddAttribute(paramNode, "type", Utils.CleanupTypeName(t));

                if (parameter.IsOptional)
                {
                    AddAttribute(paramNode, "optional", "true");
                    if (parameter.HasConstant)
                    {
                        AddAttribute(paramNode, "defaultValue", parameter.Constant == null ? "NULL" : parameter.Constant.ToString());
                    }
                }

                if (direction != "in")
                {
                    AddAttribute(paramNode, "direction", direction);
                }

                AttributeData.OutputAttributes(document, paramNode, parameter.CustomAttributes);
            }
        }
Exemple #3
0
        public override void DoOutput()
        {
            XmlNode mclass = document.CreateElement(ParentTag, null);

            parent.AppendChild(mclass);

            foreach (MemberReference member in members)
            {
                XmlNode mnode = document.CreateElement(Tag, null);
                mclass.AppendChild(mnode);
                AddAttribute(mnode, "name", GetName(member));
                if (!NoMemberAttributes)
                {
                    AddAttribute(mnode, "attrib", GetMemberAttributes(member));
                }

                AttributeData.OutputAttributes(document, mnode, GetCustomAttributes(member));

                AddExtraData(mnode, member);
            }
        }
Exemple #4
0
        protected override void AddExtraData(XmlNode p, MemberReference memberDefenition)
        {
            base.AddExtraData(p, memberDefenition);

            if (!(memberDefenition is MethodDefinition))
            {
                return;
            }

            MethodDefinition mbase = (MethodDefinition)memberDefenition;

            ParameterData parms = new ParameterData(document, p, mbase.Parameters);

            parms.DoOutput();

            if (mbase.IsAbstract)
            {
                AddAttribute(p, "abstract", "true");
            }
            if (mbase.IsVirtual)
            {
                AddAttribute(p, "virtual", "true");
            }
            if (mbase.IsStatic)
            {
                AddAttribute(p, "static", "true");
            }

            string rettype = Utils.CleanupTypeName(mbase.MethodReturnType.ReturnType);

            if (rettype != "System.Void" || !mbase.IsConstructor)
            {
                AddAttribute(p, "returntype", (rettype));
            }

            AttributeData.OutputAttributes(document, p, mbase.MethodReturnType.CustomAttributes);

            MemberData.OutputGenericParameters(document, p, mbase);
        }
Exemple #5
0
        public override void DoOutput()
        {
            if (document == null)
            {
                throw new InvalidOperationException("Document not set");
            }

            XmlNode nclass = document.CreateElement("class", null);

            AddAttribute(nclass, "name", type.Name);
            string classType = GetClassType(type);

            AddAttribute(nclass, "type", classType);

            if (type.BaseType != null)
            {
                AddAttribute(nclass, "base", Utils.CleanupTypeName(type.BaseType));
            }

            if (type.IsSealed)
            {
                AddAttribute(nclass, "sealed", "true");
            }

            if (type.IsAbstract)
            {
                AddAttribute(nclass, "abstract", "true");
            }

            if ((type.Attributes & TypeAttributes.Serializable) != 0 || type.IsEnum)
            {
                AddAttribute(nclass, "serializable", "true");
            }

            string charSet = GetCharSet(type);

            AddAttribute(nclass, "charset", charSet);

            string layout = GetLayout(type);

            if (layout != null)
            {
                AddAttribute(nclass, "layout", layout);
            }

            if (type.PackingSize >= 0)
            {
                AddAttribute(nclass, "pack", type.PackingSize.ToString());
            }

            if (type.ClassSize >= 0)
            {
                AddAttribute(nclass, "size", type.ClassSize.ToString());
            }

            parent.AppendChild(nclass);

            AttributeData.OutputAttributes(document, nclass, GetCustomAttributes(type));

            XmlNode ifaces = null;

            foreach (TypeReference iface in  TypeHelper.GetInterfaces(type))
            {
                if (!TypeHelper.IsPublic(iface))
                {
                    // we're only interested in public interfaces
                    continue;
                }

                if (ifaces == null)
                {
                    ifaces = document.CreateElement("interfaces", null);
                    nclass.AppendChild(ifaces);
                }

                XmlNode iface_node = document.CreateElement("interface", null);
                AddAttribute(iface_node, "name", Utils.CleanupTypeName(iface));
                ifaces.AppendChild(iface_node);
            }

            MemberData.OutputGenericParameters(document, nclass, type);

            ArrayList members = new ArrayList();

            FieldDefinition [] fields = GetFields(type);
            if (fields.Length > 0)
            {
                Array.Sort(fields, MemberReferenceComparer.Default);
                FieldData fd = new FieldData(document, nclass, fields);
                members.Add(fd);
            }

            if (type.IsEnum)
            {
                var value_type = GetEnumValueField(type);
                if (value_type == null)
                {
                    throw new NotSupportedException();
                }

                AddAttribute(nclass, "enumtype", Utils.CleanupTypeName(value_type.FieldType));
            }

            if (!Driver.AbiMode)
            {
                MethodDefinition [] ctors = GetConstructors(type);
                if (ctors.Length > 0)
                {
                    Array.Sort(ctors, MemberReferenceComparer.Default);
                    members.Add(new ConstructorData(document, nclass, ctors));
                }

                PropertyDefinition[] properties = GetProperties(type);
                if (properties.Length > 0)
                {
                    Array.Sort(properties, MemberReferenceComparer.Default);
                    members.Add(new PropertyData(document, nclass, properties));
                }

                EventDefinition [] events = GetEvents(type);
                if (events.Length > 0)
                {
                    Array.Sort(events, MemberReferenceComparer.Default);
                    members.Add(new EventData(document, nclass, events));
                }

                MethodDefinition [] methods = GetMethods(type);
                if (methods.Length > 0)
                {
                    Array.Sort(methods, MemberReferenceComparer.Default);
                    members.Add(new MethodData(document, nclass, methods));
                }
            }

            foreach (MemberData md in members)
            {
                md.DoOutput();
            }

            var nested = type.NestedTypes;

            //remove non public(familiy) and nested in second degree
            for (int i = nested.Count - 1; i >= 0; i--)
            {
                TypeDefinition t = nested [i];
                if ((t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic ||
                    (t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily ||
                    (t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem)
                {
                    // public
                    if (t.DeclaringType == type)
                    {
                        continue;                         // not nested of nested
                    }
                }

                nested.RemoveAt(i);
            }


            if (nested.Count > 0)
            {
                XmlNode classes = document.CreateElement("classes", null);
                nclass.AppendChild(classes);
                foreach (TypeDefinition t in nested)
                {
                    TypeData td = new TypeData(document, classes, t);
                    td.DoOutput();
                }
            }
        }
Exemple #6
0
        public override void DoOutput()
        {
            if (document == null)
            {
                throw new InvalidOperationException("Document not set");
            }

            XmlNode nassembly            = document.CreateElement("assembly", null);
            AssemblyNameDefinition aname = ass.Name;

            AddAttribute(nassembly, "name", aname.Name);
            AddAttribute(nassembly, "version", aname.Version.ToString());
            parent.AppendChild(nassembly);
            TypeForwardedToData.OutputForwarders(document, nassembly, ass);
            AttributeData.OutputAttributes(document, nassembly, ass.CustomAttributes);
            var typesCollection = ass.MainModule.Types;

            if (typesCollection == null || typesCollection.Count == 0)
            {
                return;
            }
            object [] typesArray = new object [typesCollection.Count];
            for (int i = 0; i < typesCollection.Count; i++)
            {
                typesArray [i] = typesCollection [i];
            }
            Array.Sort(typesArray, TypeReferenceComparer.Default);

            XmlNode nss = document.CreateElement("namespaces", null);

            nassembly.AppendChild(nss);

            string  current_namespace = "$%&$&";
            XmlNode ns      = null;
            XmlNode classes = null;

            foreach (TypeDefinition t in typesArray)
            {
                if (string.IsNullOrEmpty(t.Namespace))
                {
                    continue;
                }

                if (!Driver.AbiMode && ((t.Attributes & TypeAttributes.VisibilityMask) != TypeAttributes.Public))
                {
                    continue;
                }

                if (t.DeclaringType != null)
                {
                    continue;                     // enforce !nested
                }
                if (t.Namespace != current_namespace)
                {
                    current_namespace = t.Namespace;
                    ns = document.CreateElement("namespace", null);
                    AddAttribute(ns, "name", current_namespace);
                    nss.AppendChild(ns);
                    classes = document.CreateElement("classes", null);
                    ns.AppendChild(classes);
                }

                TypeData bd = new TypeData(document, classes, t);
                bd.DoOutput();
            }
        }