本文整理汇总了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;
}
示例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;
}
}
示例3: MyCodeAction
public MyCodeAction (Document document, string title, SyntaxNode root, BaseTypeDeclarationSyntax type)
{
this.root = root;
this.title = title;
this.type = type;
this.document = document;
}
示例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
};
}
示例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;
}
示例6: BaseTypeDeclarationTranslation
public BaseTypeDeclarationTranslation(BaseTypeDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Modifiers = syntax.Modifiers.Get(this);
AttributeList = syntax.AttributeLists.Get<AttributeListSyntax, AttributeListTranslation>(this);
}
示例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));
}
示例8: GetDeclaredSymbol
public override INamedTypeSymbol GetDeclaredSymbol(BaseTypeDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
// Can't define type inside a member.
return null;
}
示例9: IsInTypeDeclaration
internal static bool IsInTypeDeclaration(int position, BaseTypeDeclarationSyntax typeDecl)
{
Debug.Assert(typeDecl != null);
return IsBeforeToken(position, typeDecl, typeDecl.CloseBraceToken);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例15: IsNestedType
private static bool IsNestedType(BaseTypeDeclarationSyntax typeDeclaration)
{
return typeDeclaration?.Parent is BaseTypeDeclarationSyntax;
}