本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol.CheckUnsafeModifier方法的典型用法代码示例。如果您正苦于以下问题:C# NamedTypeSymbol.CheckUnsafeModifier方法的具体用法?C# NamedTypeSymbol.CheckUnsafeModifier怎么用?C# NamedTypeSymbol.CheckUnsafeModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol
的用法示例。
在下文中一共展示了NamedTypeSymbol.CheckUnsafeModifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeModifiers
internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxToken firstIdentifier, SyntaxTokenList modifiers, DiagnosticBag diagnostics, out bool modifierErrors)
{
DeclarationModifiers defaultAccess =
(containingType.IsInterface) ? DeclarationModifiers.Public : DeclarationModifiers.Private;
DeclarationModifiers allowedModifiers =
DeclarationModifiers.AccessibilityMask |
DeclarationModifiers.Const |
DeclarationModifiers.New |
DeclarationModifiers.ReadOnly |
DeclarationModifiers.Static |
DeclarationModifiers.Volatile |
DeclarationModifiers.Fixed |
DeclarationModifiers.Unsafe |
DeclarationModifiers.Abstract; // filtered out later
var errorLocation = new SourceLocation(firstIdentifier);
DeclarationModifiers result = ModifierUtils.MakeAndCheckNontypeMemberModifiers(
modifiers, defaultAccess, allowedModifiers, errorLocation, diagnostics, out modifierErrors);
if ((result & DeclarationModifiers.Abstract) != 0)
{
diagnostics.Add(ErrorCode.ERR_AbstractField, errorLocation);
result &= ~DeclarationModifiers.Abstract;
}
if ((result & DeclarationModifiers.Fixed) != 0)
{
if ((result & DeclarationModifiers.Static) != 0)
{
// The modifier 'static' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.StaticKeyword));
}
if ((result & DeclarationModifiers.ReadOnly) != 0)
{
// The modifier 'readonly' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword));
}
if ((result & DeclarationModifiers.Const) != 0)
{
// The modifier 'const' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ConstKeyword));
}
if ((result & DeclarationModifiers.Volatile) != 0)
{
// The modifier 'volatile' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword));
}
result &= ~(DeclarationModifiers.Static | DeclarationModifiers.ReadOnly | DeclarationModifiers.Const | DeclarationModifiers.Volatile);
Debug.Assert((result & ~(DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Fixed | DeclarationModifiers.Unsafe | DeclarationModifiers.New)) == 0);
}
if ((result & DeclarationModifiers.Const) != 0)
{
if ((result & DeclarationModifiers.Static) != 0)
{
// The constant '{0}' cannot be marked static
diagnostics.Add(ErrorCode.ERR_StaticConstant, errorLocation, firstIdentifier.ValueText);
}
if ((result & DeclarationModifiers.ReadOnly) != 0)
{
// The modifier 'readonly' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword));
}
if ((result & DeclarationModifiers.Volatile) != 0)
{
// The modifier 'volatile' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword));
}
if ((result & DeclarationModifiers.Unsafe) != 0)
{
// The modifier 'unsafe' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.UnsafeKeyword));
}
result |= DeclarationModifiers.Static; // "constants are considered static members"
}
else
{
// NOTE: always cascading on a const, so suppress.
// NOTE: we're being a bit sneaky here - we're using the containingType rather than this symbol
// to determine whether or not unsafe is allowed. Since this symbol and the containing type are
// in the same compilation, it won't make a difference. We do, however, have to pass the error
// location explicitly.
containingType.CheckUnsafeModifier(result, errorLocation, diagnostics);
}
return result;
}