Пример #1
0
        /// <summary>
        /// Write a starting type reference element based on the type node
        /// </summary>
        /// <param name="type">The type for which to write a starting type reference</param>
        private void WriteStartTypeReference(TypeNode type)
        {
            switch(type.NodeType)
            {
                case NodeType.ArrayType:
                    ArrayType array = type as ArrayType;
                    writer.WriteStartElement("arrayOf");
                    writer.WriteAttributeString("rank", array.Rank.ToString(CultureInfo.InvariantCulture));
                    this.WriteTypeReference(array.ElementType);
                    break;

                case NodeType.Reference:
                    Reference reference = type as Reference;
                    writer.WriteStartElement("referenceTo");
                    this.WriteTypeReference(reference.ElementType);
                    break;

                case NodeType.Pointer:
                    Pointer pointer = type as Pointer;
                    writer.WriteStartElement("pointerTo");
                    this.WriteTypeReference(pointer.ElementType);
                    break;

                case NodeType.OptionalModifier:
                    TypeModifier optionalModifierClause = type as TypeModifier;
                    this.WriteStartTypeReference(optionalModifierClause.ModifiedType);
                    writer.WriteStartElement("optionalModifier");
                    this.WriteTypeReference(optionalModifierClause.Modifier);
                    writer.WriteEndElement();
                    break;

                case NodeType.RequiredModifier:
                    TypeModifier requiredModifierClause = type as TypeModifier;
                    this.WriteStartTypeReference(requiredModifierClause.ModifiedType);
                    writer.WriteStartElement("requiredModifier");
                    this.WriteTypeReference(requiredModifierClause.Modifier);
                    writer.WriteEndElement();
                    break;

                default:
                    if(type.IsTemplateParameter)
                    {
                        ITypeParameter gtp = (ITypeParameter)type;
                        writer.WriteStartElement("template");

                        // !EFW - Change from ComponentOne
                        writer.WriteAttributeString("name", type.Name.Name.TranslateToValidXmlValue());
                        writer.WriteAttributeString("index", gtp.ParameterListIndex.ToString(CultureInfo.InvariantCulture));
                        writer.WriteAttributeString("api", namer.GetApiName(gtp.DeclaringMember).TranslateToValidXmlValue());
                    }
                    else
                    {
                        writer.WriteStartElement("type");

                        if(type.IsGeneric)
                        {
                            TypeNode template = type.GetTemplateType();

                            // !EFW - Change from ComponentOne
                            writer.WriteAttributeString("api", namer.GetTypeName(template).TranslateToValidXmlValue());
                            this.WriteBooleanAttribute("ref", !template.IsValueType);

                            // Record specialization							
                            TypeNodeList arguments = type.TemplateArguments;

                            if(arguments != null && arguments.Count > 0)
                            {
                                writer.WriteStartElement("specialization");

                                foreach(var arg in arguments)
                                    this.WriteTypeReference(arg);

                                writer.WriteEndElement();
                            }

                        }
                        else
                        {
                            // !EFW - Change from ComponentOne
                            writer.WriteAttributeString("api", namer.GetTypeName(type).TranslateToValidXmlValue());
                            this.WriteBooleanAttribute("ref", !type.IsValueType);
                        }

                        // Record outer types because they may be specialized and otherwise that information
                        // is lost.
                        if(type.DeclaringType != null)
                            this.WriteTypeReference(type.DeclaringType);
                    }
                    break;
            }
        }