本文整理汇总了C#中MemberDeclarationSyntax.HasModifier方法的典型用法代码示例。如果您正苦于以下问题:C# MemberDeclarationSyntax.HasModifier方法的具体用法?C# MemberDeclarationSyntax.HasModifier怎么用?C# MemberDeclarationSyntax.HasModifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberDeclarationSyntax
的用法示例。
在下文中一共展示了MemberDeclarationSyntax.HasModifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: GetMemberDeclarationVisibilityOrder
private static int GetMemberDeclarationVisibilityOrder(MemberDeclarationSyntax member)
{
SyntaxTokenList? modifiers = GetModifiers(member);
if (modifiers.HasValue)
{
bool isPublic = member.HasModifier(SyntaxKind.PublicKeyword);
bool isProtected = member.HasModifier(SyntaxKind.ProtectedKeyword);
bool isInternal = member.HasModifier(SyntaxKind.InternalKeyword);
bool isPrivate = member.HasModifier(SyntaxKind.PrivateKeyword);
if (isPublic)
{
return 0;
}
else if (isProtected && isInternal)
{
return 1;
}
else if (isInternal)
{
return 2;
}
else if (isProtected)
{
return 3;
}
else if (isPrivate)
{
return 4;
}
else // assume private-level
{
return 4;
}
}
return -1;
}