本文整理汇总了C#中MemberDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# MemberDeclarationSyntax类的具体用法?C# MemberDeclarationSyntax怎么用?C# MemberDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberDeclarationSyntax类属于命名空间,在下文中一共展示了MemberDeclarationSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GenerateAsync
/// <inheritdoc />
public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(MemberDeclarationSyntax applyTo, Document document, IProgress<Diagnostic> progress, CancellationToken cancellationToken)
{
var type = (ClassDeclarationSyntax)applyTo;
var generatedType = type
.WithMembers(SyntaxFactory.List<MemberDeclarationSyntax>());
var methodsWithNativePointers =
from method in type.Members.OfType<MethodDeclarationSyntax>()
where WhereIsPointerParameter(method.ParameterList.Parameters).Any() || method.ReturnType is PointerTypeSyntax
select method;
foreach (var method in methodsWithNativePointers)
{
var intPtrOverload = method
.WithParameterList(TransformParameterList(method.ParameterList))
.WithReturnType(TransformReturnType(method.ReturnType))
.WithIdentifier(TransformMethodName(method))
.WithModifiers(RemoveModifier(method.Modifiers, SyntaxKind.ExternKeyword))
.WithAttributeLists(SyntaxFactory.List<AttributeListSyntax>())
.WithLeadingTrivia(method.GetLeadingTrivia().Where(t => !t.IsDirective))
.WithTrailingTrivia(method.GetTrailingTrivia().Where(t => !t.IsDirective))
.WithBody(CallNativePointerOverload(method))
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None));
generatedType = generatedType.AddMembers(intPtrOverload);
}
return Task.FromResult(SyntaxFactory.SingletonList<MemberDeclarationSyntax>(generatedType));
}
开发者ID:Eucaly,项目名称:pinvoke,代码行数:28,代码来源:OfferIntPtrOverloadGenerator.cs
示例2: Create
public static ClassDeclarationSyntax Create(string name, BaseTypeSyntax[] baseTypes, ConstructorDeclarationSyntax constructor, MemberDeclarationSyntax[] body)
{
return SyntaxFactory.ClassDeclaration(name)
.AddBaseListTypes(baseTypes)
.AddMembers(constructor)
.AddMembers(body);
}
开发者ID:FociSolutions,项目名称:Foci.CodeGeneration,代码行数:7,代码来源:Class.cs
示例3: CheckDeclarationName
private static void CheckDeclarationName(MemberDeclarationSyntax member, SyntaxToken identifier, SyntaxNodeAnalysisContext context)
{
var symbol = context.SemanticModel.GetDeclaredSymbol(member);
if (ClassName.IsTypeComRelated(symbol?.ContainingType) ||
symbol.IsInterfaceImplementationOrMemberOverride() ||
symbol.IsExtern)
{
return;
}
if (identifier.ValueText.StartsWith("_", StringComparison.Ordinal) ||
identifier.ValueText.EndsWith("_", StringComparison.Ordinal))
{
context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
identifier.ValueText, MessageFormatUnderscore));
return;
}
string suggestion;
if (TryGetChangedName(identifier.ValueText, out suggestion))
{
var messageEnding = string.Format(MessageFormatNonUnderscore, suggestion);
context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
identifier.ValueText, messageEnding));
}
}
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:26,代码来源:MethodName.cs
示例4: ShouldUseOverrideKeyword
private static bool ShouldUseOverrideKeyword(MemberDeclarationSyntax member, bool isInterface)
{
ISymbol symbol = TypeProcessor.GetDeclaredSymbol(member);
if (symbol is IMethodSymbol)
{
if ((symbol as IMethodSymbol).IsGenericMethod)
return false;
}
if (symbol.ContainingType.TypeKind == TypeKind.Struct ||
symbol.ContainingType.TypeKind == TypeKind.Interface)
{
return false;
// Structs dont have a base class to override (maybe opEquals) ... but that will be handled separately
//Interfaces are contracts, so no overriding here// maybe we should compare the methods
}
if (member.GetModifiers().Any(SyntaxKind.OverrideKeyword) && !isInterface)
return true;
if (member.GetModifiers().Any(SyntaxKind.StaticKeyword))
return false;
// if (method.Modifiers.Any(SyntaxKind.NewKeyword))
// return symbol.ContainingType.BaseType.GetMembers(symbol.Name).Any(k=>k.IsAbstract || k.IsVirtual);
if (member.GetModifiers().Any(SyntaxKind.PartialKeyword))
//partial methods seem exempt from C#'s normal override keyword requirement, so we have to check manually to see if it exists in a base class
return symbol.ContainingType.BaseType.GetMembers(symbol.Name).Any();
return member.GetModifiers().Any(SyntaxKind.OverrideKeyword);
}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:33,代码来源:MemberUtilities.cs
示例5: GetDeclaredAccessibility
private Accessibility GetDeclaredAccessibility(MemberDeclarationSyntax declaration)
{
var result = Accessibility.Private;
SyntaxTokenList? syntaxTokenList;
syntaxTokenList = (declaration as PropertyDeclarationSyntax)?.Modifiers ??
(declaration as FieldDeclarationSyntax)?.Modifiers ??
(declaration as ConstructorDeclarationSyntax)?.Modifiers ??
(declaration as MethodDeclarationSyntax)?.Modifiers;
var accessibilityToken = syntaxTokenList?.Where(x => accessibilityTypes.Contains(x.Kind())).FirstOrDefault();
if (accessibilityToken.HasValue)
{
switch (accessibilityToken.Value.Kind())
{
case SyntaxKind.PublicKeyword:
result = Accessibility.Public;
break;
case SyntaxKind.PrivateKeyword:
result = Accessibility.Private;
break;
case SyntaxKind.InternalKeyword:
result = Accessibility.Internal;
break;
case SyntaxKind.ProtectedKeyword:
result = Accessibility.Protected;
break;
default:
result = Accessibility.Private;
break;
}
}
return result;
}
开发者ID:Ophlan,项目名称:Ophlan.Analyzers,代码行数:34,代码来源:OrganizeMembersCodeFixProvider.cs
示例6: YieldClassGenerator
public YieldClassGenerator(Compilation compilation, ClassDeclarationSyntax classDeclarationSyntax, MemberDeclarationSyntax node)
{
this.compilation = compilation;
this.classDeclarationSyntax = classDeclarationSyntax;
this.node = node;
method = ModelExtensions.GetDeclaredSymbol(compilation.GetSemanticModel(node.SyntaxTree), node);
}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:8,代码来源:YieldClassGenerator.cs
示例7: MemberOrderHelper
/// <summary>
/// Initializes a new instance of the <see cref="MemberOrderHelper"/> struct.
/// </summary>
/// <param name="member">The member to wrap.</param>
public MemberOrderHelper(MemberDeclarationSyntax member)
{
this.Member = member;
var modifiers = member.GetModifiers();
this.modifierFlags = GetModifierFlags(modifiers);
this.accessibilty = AccessLevelHelper.GetAccessLevel(modifiers);
}
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:12,代码来源:MemberOrderHelper.cs
示例8: HasYield
public static bool HasYield(MemberDeclarationSyntax method)
{
if (method.IsAsync())
return false;
var yieldChecker = new YieldChecker(true);
method.Accept(yieldChecker);
return yieldChecker.isSpecial;
}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:9,代码来源:YieldChecker.cs
示例9: VisitMemberDeclaration
private SyntaxNode VisitMemberDeclaration(MemberDeclarationSyntax node, SyntaxNode newNode)
{
var newMember = ((MemberDeclarationSyntax) newNode).WithoutAttributes();
var isSolutionPart = node.HasAttribute<ExcludeFromSolutionAttribute>() || node.HasAttribute<ExerciseAttribute>();
if (node.HasAttribute<ExcludeFromSolutionAttribute>()
|| (node is TypeDeclarationSyntax && node.HasAttribute<ExerciseAttribute>()))
Exercise.EthalonSolution += newMember.ToFullString();
return isSolutionPart ? null : newMember;
}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:9,代码来源:ExerciseBuilder.cs
示例10: Sort
internal static int Sort(MemberDeclarationSyntax first, MemberDeclarationSyntax second)
{
Requires.NotNull(first, "first");
Requires.NotNull(second, "second");
int firstOrder = GetMemberDeclarationTypeOrder(first);
int secondOrder = GetMemberDeclarationTypeOrder(second);
int compareResult = firstOrder.CompareTo(secondOrder);
if (compareResult == 0)
{
firstOrder = GetMemberDeclarationVisibilityOrder(first);
secondOrder = GetMemberDeclarationVisibilityOrder(second);
compareResult = firstOrder.CompareTo(secondOrder);
if (compareResult == 0)
{
bool firstIsStatic = first.HasModifier(SyntaxKind.StaticKeyword);
bool secondIsStatic = second.HasModifier(SyntaxKind.StaticKeyword);
if (firstIsStatic && !secondIsStatic)
{
compareResult = -1;
}
else if (!firstIsStatic && secondIsStatic)
{
compareResult = 1;
}
if (compareResult == 0)
{
bool firstIsReadOnly = first.HasModifier(SyntaxKind.ReadOnlyKeyword);
bool secondIsReadOnly = second.HasModifier(SyntaxKind.ReadOnlyKeyword);
if (firstIsReadOnly && !secondIsReadOnly)
{
compareResult = -1;
}
else if (!firstIsReadOnly && secondIsReadOnly)
{
compareResult = 1;
}
if (compareResult == 0)
{
var firstName = GetName(first);
var secondName = GetName(second);
if (firstName.HasValue && secondName.HasValue)
{
compareResult = string.Compare(firstName.Value.ValueText, secondName.Value.ValueText, StringComparison.CurrentCulture);
}
}
}
}
}
return compareResult;
}
开发者ID:azeno,项目名称:ImmutableObjectGraph,代码行数:56,代码来源:StyleCop.cs
示例11: MemberOrderHelper
/// <summary>
/// Initializes a new instance of the <see cref="MemberOrderHelper"/> struct.
/// </summary>
/// <param name="member">The member to wrap.</param>
/// <param name="elementOrder">The element ordering traits.</param>
internal MemberOrderHelper(MemberDeclarationSyntax member, ImmutableArray<OrderingTrait> elementOrder)
{
this.Member = member;
var modifiers = member.GetModifiers();
var type = member.Kind();
type = type == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : type;
this.Priority = 0;
foreach (OrderingTrait trait in elementOrder)
{
switch (trait)
{
case OrderingTrait.Kind:
// 4 bits are required to store this.
this.Priority <<= 4;
this.Priority |= TypeMemberOrder.IndexOf(type) & 0x0F;
break;
case OrderingTrait.Accessibility:
// 3 bits are required to store this.
this.Priority <<= 3;
this.Priority |= (int)GetAccessLevelForOrdering(member, modifiers) & 0x07;
break;
case OrderingTrait.Constant:
this.Priority <<= 1;
if (modifiers.Any(SyntaxKind.ConstKeyword))
{
this.Priority |= 1;
}
break;
case OrderingTrait.Static:
this.Priority <<= 1;
if (modifiers.Any(SyntaxKind.StaticKeyword))
{
this.Priority |= 1;
}
break;
case OrderingTrait.Readonly:
this.Priority <<= 1;
if (modifiers.Any(SyntaxKind.ReadOnlyKeyword))
{
this.Priority |= 1;
}
break;
default:
continue;
}
}
}
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:61,代码来源:MemberOrderHelper.cs
示例12: VisitMemberDeclaration
private SyntaxNode VisitMemberDeclaration(MemberDeclarationSyntax node, SyntaxNode newNode)
{
var parent = node.GetParents().OfType<BaseTypeDeclarationSyntax>().FirstOrDefault();
if (!ShowOnSlide(node)) return null;
if (parent == null
|| parent.HasAttribute<SlideAttribute>()
|| parent.HasAttribute<ShowBodyOnSlideAttribute>())
AddCodeBlock(((MemberDeclarationSyntax)newNode));
return ((MemberDeclarationSyntax)newNode).WithoutAttributes();
}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:10,代码来源:BlocksBuilder.cs
示例13: GetDeclaredSymbols
internal static IEnumerable<ISymbol> GetDeclaredSymbols(SemanticModel semanticModel, MemberDeclarationSyntax memberDeclaration, CancellationToken cancellationToken)
{
if (memberDeclaration is FieldDeclarationSyntax)
{
return ((FieldDeclarationSyntax)memberDeclaration).Declaration.Variables.Select(
v => semanticModel.GetDeclaredSymbol(v, cancellationToken));
}
return SpecializedCollections.SingletonEnumerable(
semanticModel.GetDeclaredSymbol(memberDeclaration, cancellationToken));
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:11,代码来源:GenerateFromMembersHelpers.cs
示例14: UpdateNamedTypeDeclaration
public static MemberDeclarationSyntax UpdateNamedTypeDeclaration(
ICodeGenerationService service,
MemberDeclarationSyntax declaration,
IList<ISymbol> newMembers,
CodeGenerationOptions options,
CancellationToken cancellationToken)
{
declaration = RemoveAllMembers(declaration);
declaration = service.AddMembers(declaration, newMembers, options, cancellationToken);
return AddCleanupAnnotationsTo(declaration);
}
开发者ID:nemec,项目名称:roslyn,代码行数:11,代码来源:NamedTypeGenerator.cs
示例15: ExtractToExpressionTree
private async Task<Document> ExtractToExpressionTree(Document document, MemberDeclarationSyntax declaration, CancellationToken c)
{
var typeSyntax = declaration.Ancestors().OfType<TypeDeclarationSyntax>().First();
var sm = await document.GetSemanticModelAsync(c);
var type = sm.GetDeclaredSymbol(typeSyntax, c);
var symbol = sm.GetDeclaredSymbol(declaration);
string name = declaration is MethodDeclarationSyntax ?
((MethodDeclarationSyntax)declaration).Identifier.ToString() :
((PropertyDeclarationSyntax)declaration).Identifier.ToString();
string candidateName = name + "Expression";
if (type.MemberNames.Contains(candidateName))
candidateName = Enumerable.Range(2, 1000).Select(i => name + "Expression" + i).First(n => !type.MemberNames.Contains(n));
List<ParameterSyntax> parameterList = GetParameters(declaration, type, symbol);
TypeSyntax returnType = GetReturnType(declaration);
var bodyExpression = GetSingleBody(declaration);
var newField = GetStaticField(candidateName, parameterList, returnType, bodyExpression, sm, type);
var newBody = GetNewBody(candidateName, parameterList);
var newDeclaration = declaration.ReplaceNode(bodyExpression, newBody);
MoveInitialTrivia(ref newField, ref newDeclaration);
var newMembers = typeSyntax.Members.ReplaceRange(declaration, new[] { newField, newDeclaration });
var newType = typeSyntax is StructDeclarationSyntax ?
(TypeDeclarationSyntax)((StructDeclarationSyntax)typeSyntax).WithMembers(newMembers) :
(TypeDeclarationSyntax)((ClassDeclarationSyntax)typeSyntax).WithMembers(newMembers);
var docRoot = await document.GetSyntaxRootAsync();
var newDoc = docRoot.ReplaceNode(typeSyntax, newType);
var usings = newDoc.ChildNodes().OfType<UsingDirectiveSyntax>();
if (usings.Any() && !usings.Any(a => a.Name.ToString() == "System.Linq.Expressions"))
newDoc = newDoc.InsertNodesAfter(usings.LastOrDefault(), new[] {
SyntaxFactory.UsingDirective(
SyntaxFactory.IdentifierName("System").Qualified("Linq").Qualified("Expressions")
).NormalizeWhitespace().WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)
});
return document.WithSyntaxRoot(newDoc);
}
开发者ID:rondoo,项目名称:framework,代码行数:52,代码来源:ExpressionFieldFixProvider.cs
示例16: BeforeMember
private static MemberDeclarationSyntax BeforeMember(
SyntaxList<MemberDeclarationSyntax> members,
MemberDeclarationSyntax eventDeclaration)
{
// If it's a field style event, then it goes before everything else if we don't have any
// existing fields/events.
if (eventDeclaration.Kind() == SyntaxKind.FieldDeclaration)
{
return members.FirstOrDefault();
}
// Otherwise just place it before the methods.
return FirstMethod(members);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:14,代码来源:EventGenerator.cs
示例17: IsObsolete
static bool IsObsolete (MemberDeclarationSyntax entity)
{
if (entity == null)
return false;
// TODO!
// foreach (var section in entity.Attributes) {
// foreach (var attr in section.Attributes) {
// var attrText = attr.Type.ToString ();
// if (attrText == "Obsolete" || attrText == "ObsoleteAttribute" || attrText == "System.Obsolete" || attrText == "System.ObsoleteAttribute" )
// return true;
// }
// }
return false;
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:14,代码来源:AstAmbience.cs
示例18: GenerateAsync
/// <inheritdoc />
public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(MemberDeclarationSyntax applyTo, Document document, IProgress<Diagnostic> progress, CancellationToken cancellationToken)
{
var applyToStruct = applyTo as StructDeclarationSyntax;
var applyToClass = applyTo as ClassDeclarationSyntax;
var applyToType = applyTo as TypeDeclarationSyntax;
var generatedMembers = SyntaxFactory.List<MemberDeclarationSyntax>();
var nativePointerFields = from field in applyToType.Members.OfType<FieldDeclarationSyntax>()
where field.Declaration.Type is PointerTypeSyntax && field.Modifiers.Any(m => m.IsKind(SyntaxKind.PublicKeyword))
select field;
foreach (var field in nativePointerFields)
{
foreach (var variable in field.Declaration.Variables)
{
generatedMembers = generatedMembers.Add(
SyntaxFactory.PropertyDeclaration(IntPtrTypeSyntax, variable.Identifier.ValueText + "_IntPtr")
.WithModifiers(field.Modifiers)
//// get { return new IntPtr(this.field); }
//// set { this.field = (byte*)value.ToPointer(); }
.AddAccessorListAccessors(
SyntaxFactory.AccessorDeclaration(
SyntaxKind.GetAccessorDeclaration,
SyntaxFactory.Block(
SyntaxFactory.ReturnStatement(
SyntaxFactory.ObjectCreationExpression(IntPtrTypeSyntax)
.AddArgumentListArguments(SyntaxFactory.Argument(ThisDot(variable.Identifier)))))),
SyntaxFactory.AccessorDeclaration(
SyntaxKind.SetAccessorDeclaration,
SyntaxFactory.Block(
SyntaxFactory.ExpressionStatement(
SyntaxFactory.AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
ThisDot(variable.Identifier),
TypedAs(
SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
SyntaxFactory.IdentifierName("value"),
SyntaxFactory.IdentifierName(nameof(IntPtr.ToPointer))),
SyntaxFactory.ArgumentList()),
field.Declaration.Type)))))));
}
}
var generatedType = (TypeDeclarationSyntax)applyToStruct?.WithMembers(generatedMembers)
.WithAttributeLists(SyntaxFactory.List<AttributeListSyntax>())
?? applyToClass?.WithMembers(generatedMembers)
.WithAttributeLists(SyntaxFactory.List<AttributeListSyntax>());
return Task.FromResult(SyntaxFactory.SingletonList<MemberDeclarationSyntax>(generatedType));
}
开发者ID:Eucaly,项目名称:pinvoke,代码行数:51,代码来源:OfferIntPtrPropertyAccessorsGenerator.cs
示例19: MoveField
private static SyntaxNode MoveField(SyntaxNode root, MemberDeclarationSyntax field, MemberDeclarationSyntax firstNonConst)
{
var trackedRoot = root.TrackNodes(field, firstNonConst);
var fieldToMove = trackedRoot.GetCurrentNode(field);
var firstNonConstTracked = trackedRoot.GetCurrentNode(firstNonConst);
if (!fieldToMove.HasLeadingTrivia)
{
fieldToMove = fieldToMove.WithLeadingTrivia(firstNonConstTracked.GetLeadingTrivia().Where(x => x.IsKind(SyntaxKind.WhitespaceTrivia)).LastOrDefault());
}
root = trackedRoot.InsertNodesBefore(firstNonConstTracked, new[] { fieldToMove });
var fieldToMoveTracked = root.GetCurrentNodes(field).Last();
return root.RemoveNode(fieldToMoveTracked, SyntaxRemoveOptions.KeepNoTrivia);
}
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:14,代码来源:SA1203SA1214SA1215CodeFixProvider.cs
示例20: GenerateAsync
public Task<IReadOnlyList<MemberDeclarationSyntax>> GenerateAsync(MemberDeclarationSyntax applyTo, Document document, IProgress<Diagnostic> progress, CancellationToken cancellationToken)
{
Requires.NotNull(applyTo, nameof(applyTo));
var options = new CodeGen.Options(this.attributeData)
{
GenerateBuilder = this.GetBoolData(nameof(GenerateImmutableAttribute.GenerateBuilder)),
Delta = this.GetBoolData(nameof(GenerateImmutableAttribute.Delta)),
DefineInterface = this.GetBoolData(nameof(GenerateImmutableAttribute.DefineInterface)),
DefineRootedStruct = this.GetBoolData(nameof(GenerateImmutableAttribute.DefineRootedStruct)),
DefineWithMethodsPerProperty = this.GetBoolData(nameof(GenerateImmutableAttribute.DefineWithMethodsPerProperty)),
};
return CodeGen.GenerateAsync((ClassDeclarationSyntax)applyTo, document, progress, options, cancellationToken);
}
开发者ID:zbynek001,项目名称:ImmutableObjectGraph,代码行数:15,代码来源:CodeGenerator.cs
注:本文中的MemberDeclarationSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论