当前位置: 首页>>代码示例>>C#>>正文


C# TypeNode.GetTemplateType方法代码示例

本文整理汇总了C#中System.Compiler.TypeNode.GetTemplateType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.GetTemplateType方法的具体用法?C# TypeNode.GetTemplateType怎么用?C# TypeNode.GetTemplateType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Compiler.TypeNode的用法示例。


在下文中一共展示了TypeNode.GetTemplateType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteStartTypeReference

        /// <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;
            }
        }
开发者ID:armin-bauer,项目名称:SHFB,代码行数:95,代码来源:MRefWriter.cs


注:本文中的System.Compiler.TypeNode.GetTemplateType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。