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


C# BaseTypeDeclarationSyntax类代码示例

本文整理汇总了C#中BaseTypeDeclarationSyntax的典型用法代码示例。如果您正苦于以下问题:C# BaseTypeDeclarationSyntax类的具体用法?C# BaseTypeDeclarationSyntax怎么用?C# BaseTypeDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: MoveTypeToFile

 private Document MoveTypeToFile(BaseTypeDeclarationSyntax typeDeclaration, Document curentDocument)
 {
     var typeName = typeDeclaration.Identifier.Text;
     var fileName = typeName + ".cs";
     var newDocument = MoveTypeToFile(curentDocument, typeDeclaration, fileName);
     return newDocument;
 }
开发者ID:igorushi,项目名称:Refacta,代码行数:7,代码来源:MoveTypeToFileRefactoring.cs

示例2: RenameType

        private async Task<Solution> RenameType(Document document, BaseTypeDeclarationSyntax typeDecl, CancellationToken cancellationToken)
        {
            try
            {
                var newName = GetDocumentName(document);

                // Get the symbol representing the type to be renamed.
                var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
                var typeSymbol = semanticModel.GetDeclaredSymbol(typeDecl, cancellationToken);

                // Produce a new solution that has all references to that type renamed, including the declaration.
                var originalSolution = document.Project.Solution;
                var optionSet = originalSolution.Workspace.Options;
                var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, typeSymbol, newName, optionSet, cancellationToken).ConfigureAwait(false);

                // Return the new solution with the now-uppercase type name.
                return newSolution;
            }
            catch (Exception e)
            {
                LogException(e);
                return document.Project.Solution;
            }

        }
开发者ID:igorushi,项目名称:Refacta,代码行数:25,代码来源:RenameTypeRefactoring.cs

示例3: MyCodeAction

			public MyCodeAction (Document document, string title, SyntaxNode root, BaseTypeDeclarationSyntax type)
			{
				this.root = root;
				this.title = title;
				this.type = type;
				this.document = document;

			}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:8,代码来源:MoveTypeToFile.cs

示例4: From

 public static TypeNameText From(BaseTypeDeclarationSyntax syntax)
 {
     var identifier = syntax.Identifier.Text;
     var typeArgs = string.Empty;
     var typeDeclaration = syntax as TypeDeclarationSyntax;
     if (typeDeclaration != null && typeDeclaration.TypeParameterList != null)
     {
         var count = typeDeclaration.TypeParameterList.Parameters.Count;
         identifier = $"\"{identifier}`{count}\"";
         typeArgs = "<" + string.Join(",", typeDeclaration.TypeParameterList.Parameters) + ">";
     }
     return new TypeNameText
     {
         Identifier = identifier,
         TypeArguments = typeArgs
     };
 }
开发者ID:pierre3,项目名称:PlantUmlClassDiagramGenerator,代码行数:17,代码来源:TypeNameText.cs

示例5: MoveClassIntoNewFileAsync

        private async Task<Solution> MoveClassIntoNewFileAsync(Document document, BaseTypeDeclarationSyntax typeDecl, CancellationToken cancellationToken)
        {
            var identifierToken = typeDecl.Identifier;

            // symbol representing the type
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
            var typeSymbol = semanticModel.GetDeclaredSymbol(typeDecl, cancellationToken);

            // remove type from current files
            var currentSyntaxTree = await document.GetSyntaxTreeAsync(cancellationToken);
            var currentRoot = await currentSyntaxTree.GetRootAsync(cancellationToken);
            var replacedRoot = currentRoot.RemoveNode(typeDecl, SyntaxRemoveOptions.KeepNoTrivia);

            document = document.WithSyntaxRoot(replacedRoot);

            // TODO: use Simplifier instead.
            document = await RemoveUnusedImportDirectivesAsync(document, cancellationToken);

            // create new tree for a new file
            // we drag all the usings because we don't know which are needed
            // and there is no easy way to find out which
            var currentUsings = currentRoot.DescendantNodesAndSelf().Where(s => s is UsingDirectiveSyntax);

            var newFileTree = SyntaxFactory.CompilationUnit()
                .WithUsings(SyntaxFactory.List<UsingDirectiveSyntax>(currentUsings.Select(i => ((UsingDirectiveSyntax)i))))
                .WithMembers(
                            SyntaxFactory.SingletonList<MemberDeclarationSyntax>(
                                SyntaxFactory.NamespaceDeclaration(
                                    SyntaxFactory.IdentifierName(typeSymbol.ContainingNamespace.ToString()))
                .WithMembers(SyntaxFactory.SingletonList<MemberDeclarationSyntax>(typeDecl))))
                .WithoutLeadingTrivia()
                .NormalizeWhitespace();

            //move to new File
            //TODO: handle name conflicts
            var newDocument = document.Project.AddDocument(string.Format("{0}.cs", identifierToken.Text), SourceText.From(newFileTree.ToFullString()), document.Folders);

            newDocument = await RemoveUnusedImportDirectivesAsync(newDocument, cancellationToken);

            return newDocument.Project.Solution;
        }
开发者ID:joymon,项目名称:joyful-visualstudio,代码行数:41,代码来源:MoveClassToFile.cs

示例6: BaseTypeDeclarationTranslation

 public BaseTypeDeclarationTranslation(BaseTypeDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
     Modifiers = syntax.Modifiers.Get(this);
     AttributeList = syntax.AttributeLists.Get<AttributeListSyntax, AttributeListTranslation>(this);
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:5,代码来源:BaseTypeDeclarationTranslation.cs

示例7: GetCorrectFileName

		internal static string GetCorrectFileName (Document document, BaseTypeDeclarationSyntax type)
		{
			if (type == null)
				return document.FilePath;
			return Path.Combine (Path.GetDirectoryName (document.FilePath), type.Identifier + Path.GetExtension (document.FilePath));
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:6,代码来源:MoveTypeToFile.cs

示例8: GetDeclaredSymbol

 public override INamedTypeSymbol GetDeclaredSymbol(BaseTypeDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define type inside a member.
     return null;
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:5,代码来源:MemberSemanticModel.cs

示例9: IsInTypeDeclaration

        internal static bool IsInTypeDeclaration(int position, BaseTypeDeclarationSyntax typeDecl)
        {
            Debug.Assert(typeDecl != null);

            return IsBeforeToken(position, typeDecl, typeDecl.CloseBraceToken);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:6,代码来源:LookupPosition.cs

示例10: GetStartPoint

            private VirtualTreePoint GetStartPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
            {
                int startPosition;

                switch (part)
                {
                    case EnvDTE.vsCMPart.vsCMPartName:
                    case EnvDTE.vsCMPart.vsCMPartAttributes:
                    case EnvDTE.vsCMPart.vsCMPartWhole:
                    case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
                        throw Exceptions.ThrowENotImpl();

                    case EnvDTE.vsCMPart.vsCMPartHeader:
                        startPosition = node.GetFirstTokenAfterAttributes().SpanStart;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
                        if (node.AttributeLists.Count == 0)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        goto case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes;

                    case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
                        startPosition = node.GetFirstToken().SpanStart;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartNavigate:
                        startPosition = node.Identifier.SpanStart;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartBody:
                        if (node.OpenBraceToken.IsMissing || node.CloseBraceToken.IsMissing)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        return GetBodyStartPoint(text, node.OpenBraceToken);

                    default:
                        throw Exceptions.ThrowEInvalidArg();
                }

                return new VirtualTreePoint(node.SyntaxTree, text, startPosition);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:47,代码来源:CSharpCodeModelService.NodeLocator.cs

示例11: GetEndPoint

            private VirtualTreePoint GetEndPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
            {
                int endPosition;

                switch (part)
                {
                    case EnvDTE.vsCMPart.vsCMPartName:
                    case EnvDTE.vsCMPart.vsCMPartAttributes:
                    case EnvDTE.vsCMPart.vsCMPartHeader:
                    case EnvDTE.vsCMPart.vsCMPartWhole:
                    case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
                        throw Exceptions.ThrowENotImpl();

                    case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
                        if (node.AttributeLists.Count == 0)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        endPosition = node.AttributeLists.Last().GetLastToken().Span.End;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
                        endPosition = node.Span.End;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartNavigate:
                        endPosition = node.Identifier.Span.End;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartBody:
                        return GetBodyEndPoint(text, node.CloseBraceToken);

                    default:
                        throw Exceptions.ThrowEInvalidArg();
                }

                return new VirtualTreePoint(node.SyntaxTree, text, endPosition);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:40,代码来源:CSharpCodeModelService.NodeLocator.cs

示例12: CreateDefaultConstructor

        public JsBlockStatement CreateDefaultConstructor(BaseTypeDeclarationSyntax type)
        {
            var classType = transformer.model.GetDeclaredSymbol(type);

            var fullTypeName = type.GetFullName();
            var constructorBlock = new JsBlockStatement();

            if (fullTypeName != "System.Object")
            {
                constructorBlock.Express(InvokeParameterlessBaseClassConstructor(classType.BaseType));
            }

            if (type is ClassDeclarationSyntax)
            {
                constructorBlock.Aggregate(InitializeInstanceFields((ClassDeclarationSyntax)type));
            }

            var block = new JsBlockStatement();
            var constructorName = classType.GetDefaultConstructorName();
            block.Add(StoreInPrototype(constructorName, Js.Reference(SpecialNames.DefineConstructor).Invoke(
                Js.Reference(SpecialNames.TypeInitializerTypeFunction), 
                Js.Function().Body(constructorBlock))));

            return block;            
        }
开发者ID:x335,项目名称:WootzJs,代码行数:25,代码来源:Idioms.cs

示例13: AddTypeToMemberList

			void AddTypeToMemberList (BaseTypeDeclarationSyntax btype)
			{
				var e = btype as EnumDeclarationSyntax;
				if (e !=null){
					foreach (var member in e.Members) {
						memberList.Add (member);
					}
					return;
				}
				var type = btype as TypeDeclarationSyntax;
				foreach (var member in type.Members) {
					if (member is FieldDeclarationSyntax) {
						foreach (var variable in ((FieldDeclarationSyntax)member).Declaration.Variables)
							memberList.Add (variable);
					} else if (member is EventFieldDeclarationSyntax) {
						foreach (var variable in ((EventFieldDeclarationSyntax)member).Declaration.Variables)
							memberList.Add (variable);
					} else {
						memberList.Add (member);
					}
				}
			}
开发者ID:ZZHGit,项目名称:monodevelop,代码行数:22,代码来源:PathedDocumentTextEditorExtension.cs

示例14: GetQualifiedTypeName

        private string GetQualifiedTypeName(BaseTypeDeclarationSyntax cls)
        {
            var qname = cls.Identifier.ToString();

            foreach (var a in cls.Ancestors())
            {
                if(a is NamespaceDeclarationSyntax)
                {
                    qname = a.ChildNodes().First().ToString() + "." + qname;
                }
                else if(a is ClassDeclarationSyntax)
                {
                    qname = ((ClassDeclarationSyntax)a).Identifier + "+" + qname;
                }
            }

            return qname;
        }
开发者ID:thomas13335,项目名称:wpf2html5,代码行数:18,代码来源:CSharpToJScriptConverter.cs

示例15: IsNestedType

 private static bool IsNestedType(BaseTypeDeclarationSyntax typeDeclaration)
 {
     return typeDeclaration?.Parent is BaseTypeDeclarationSyntax;
 }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:4,代码来源:SA1400CodeFixProvider.cs


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