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


C# CsElement.GetType方法代码示例

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


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

示例1: RecordElement

        /// <summary>
        /// Records information about the given element, under the given node.
        /// </summary>
        /// <param name="element">
        /// The element to record.
        /// </param>
        /// <param name="parentNode">
        /// The Xml node to record this element beneath.
        /// </param>
        /// <returns>
        /// Returns the new Xml node describing this element.
        /// </returns>
        private static XmlNode RecordElement(CsElement element, XmlNode parentNode)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(parentNode, "parentNode");

            // Create a new node for this element and add it to the parent.
            XmlNode elementNode = parentNode.OwnerDocument.CreateElement("Element");
            parentNode.AppendChild(elementNode);

            // Add the name and type of the element.
            XmlAttribute name = parentNode.OwnerDocument.CreateAttribute("Name");
            name.Value = element.Declaration.Name;
            elementNode.Attributes.Append(name);

            XmlAttribute type = parentNode.OwnerDocument.CreateAttribute("Type");
            type.Value = element.GetType().Name;
            elementNode.Attributes.Append(type);

            return elementNode;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:32,代码来源:CsParserDump.cs

示例2: GetDeclaration

        private string GetDeclaration(CsElement codeElement)
        {
            if (codeElement.GetType().Name == "Method")
            {
                var methodDeclaration = (Method)codeElement;

                var parameters = string.Join(",", methodDeclaration.Parameters.Select(x => x.Type.Text));
                var returnType = methodDeclaration.ReturnType != null ? " : " + methodDeclaration.ReturnType.Text : string.Empty;

                var declaration = methodDeclaration.Declaration.Name + "(" + parameters + ")" + returnType;

                return declaration.Replace(",", ", ");
            }

            if (codeElement.GetType().Name == "Constructor")
            {
                var constructorDeclaration = (Constructor)codeElement;
                var parameters = string.Join(",", constructorDeclaration.Parameters.Select(x => x.Type.Text));
                var declaration = constructorDeclaration.Declaration.Name + "(" + parameters + ")";

                return declaration.Replace(",", ", ");
            }

            if (codeElement.GetType().Name == "Accessor")
            {
                var accessor = (Accessor)codeElement;
                var property = (Property)codeElement.Parent;
                var parameters = string.Join(", ", accessor.Parameters.Select(x => x.Type.Text));
                var returnType = accessor.ReturnType != null ? " : " + accessor.ReturnType.Text : string.Empty;

                var declaration = property.Declaration.Name + "." + accessor.Declaration.Name + "(" + parameters + ")" + returnType;
                return declaration.Replace(",", ", ");
            }

            return codeElement.Declaration.Name.Replace(",", ", ");
        }
开发者ID:pauloortins,项目名称:CodeBlamer,代码行数:36,代码来源:Violation.cs

示例3: GetNameSpace

        private string GetNameSpace(CsElement codeElement)
        {
            while (codeElement.GetType().Name != "Namespace" && codeElement.GetType().Name != "DocumentRoot")
            {
                codeElement = (CsElement)codeElement.Parent;
            }

            return codeElement.FullNamespaceName.Replace("Root.", string.Empty);
        }
开发者ID:pauloortins,项目名称:CodeBlamer,代码行数:9,代码来源:Violation.cs

示例4: GetClassName

        private string GetClassName(CsElement codeElement)
        {
            if (codeElement.GetType().Name == "DocumentRoot" ||
                codeElement.GetType().Name == "Namespace" ||
                codeElement.GetType().Name == "AssemblyOrModuleAttribute")
            {
                return string.Empty;
            }

            if (codeElement.GetType().Name == "UsingDirective")
            {
                return "UsingDirective";
            }

            if (codeElement.GetType().Name == "Class" || codeElement.GetType().Name == "Interface" || codeElement.GetType().Name == "Enum")
            {
                return codeElement.Declaration.Name;
            }

            return GetClassName((CsElement)codeElement.Parent);
        }
开发者ID:pauloortins,项目名称:CodeBlamer,代码行数:21,代码来源:Violation.cs


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