本文整理汇总了C#中BaseTypeDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# BaseTypeDeclarationSyntax类的具体用法?C# BaseTypeDeclarationSyntax怎么用?C# BaseTypeDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BaseTypeDeclarationSyntax类属于命名空间,在下文中一共展示了BaseTypeDeclarationSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: CalcTypeBounds
ISegment CalcTypeBounds (BaseTypeDeclarationSyntax type)
{
int start = type.Span.Start;
int end = type.Span.End;
foreach (var trivia in type.GetLeadingTrivia ()) {
if (trivia.Kind () == SyntaxKind.SingleLineDocumentationCommentTrivia) {
start = trivia.FullSpan.Start;
}
}
return TextSegment.FromBounds (start, end);
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:12,代码来源:MoveTypeToFile.cs
示例17: CreateNewFile
Document CreateNewFile (BaseTypeDeclarationSyntax type, string correctFileName)
{
var doc = IdeApp.Workbench.ActiveDocument;
var content = doc.Editor.Text;
var types = new List<BaseTypeDeclarationSyntax> (
root
.DescendantNodesAndSelf (n => !(n is BaseTypeDeclarationSyntax))
.OfType<BaseTypeDeclarationSyntax> ()
.Where (t => t.SpanStart != type.SpanStart)
);
types.Sort ((x, y) => y.SpanStart.CompareTo (x.SpanStart));
foreach (var removeType in types) {
var bounds = CalcTypeBounds (removeType);
content = content.Remove (bounds.Offset, bounds.Length);
}
if (doc.HasProject) {
string header = StandardHeaderService.GetHeader (doc.Project, correctFileName, true);
if (!string.IsNullOrEmpty (header))
content = header + doc.Editor.GetEolMarker () + StripHeader (content);
}
content = StripDoubleBlankLines (content);
File.WriteAllText (correctFileName, content);
if (doc.HasProject) {
doc.Project.AddFile (correctFileName);
IdeApp.ProjectOperations.SaveAsync (doc.Project);
}
doc.Editor.RemoveText (CalcTypeBounds (type));
return document;
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:35,代码来源:MoveTypeToFile.cs
示例18: GetTypeNamespace
public string GetTypeNamespace(BaseTypeDeclarationSyntax codeclass)
{
var semanticModel = _fullCompilation.GetSemanticModel(codeclass.SyntaxTree);
var symbol = semanticModel.GetDeclaredSymbol(codeclass);
return symbol.ContainingNamespace.ToString();
}
开发者ID:yumapos,项目名称:Yumapos-WCF-Generator,代码行数:8,代码来源:SolutionSyntaxWalker.cs
示例19: GetFullRepositoryModelName
public string GetFullRepositoryModelName(BaseTypeDeclarationSyntax codeclass)
{
var semanticModel = _repositoryModelsCompilation.GetSemanticModel(codeclass.SyntaxTree);
var symbol = semanticModel.GetDeclaredSymbol(codeclass);
return symbol.ContainingNamespace + "." + codeclass.Identifier.Text;
}
开发者ID:yumapos,项目名称:Yumapos-WCF-Generator,代码行数:8,代码来源:SolutionSyntaxWalker.cs
示例20: TypeParameterNamesMatch
private static bool TypeParameterNamesMatch(BaseTypeDeclarationSyntax baseTypeDeclarationSyntax, TypeSyntax name)
{
TypeParameterListSyntax typeParameterList;
if (baseTypeDeclarationSyntax.IsKind(SyntaxKind.ClassDeclaration))
{
typeParameterList = (baseTypeDeclarationSyntax as ClassDeclarationSyntax)?.TypeParameterList;
}
else
{
typeParameterList = (baseTypeDeclarationSyntax as StructDeclarationSyntax)?.TypeParameterList;
}
var genericName = name as GenericNameSyntax;
if (genericName != null)
{
var genericNameArgumentNames = genericName.TypeArgumentList.Arguments.Cast<SimpleNameSyntax>().Select(p => p.Identifier.ToString());
var classParameterNames = typeParameterList?.Parameters.Select(p => p.Identifier.ToString()) ?? Enumerable.Empty<string>();
// Make sure the names match up
return genericNameArgumentNames.SequenceEqual(classParameterNames);
}
else
{
return typeParameterList == null
|| !typeParameterList.Parameters.Any();
}
}
开发者ID:iaingalloway,项目名称:StyleCopAnalyzers,代码行数:27,代码来源:StandardTextDiagnosticBase.cs
注:本文中的BaseTypeDeclarationSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论