當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。