本文整理汇总了C#中TypeSymbol.IsValidVolatileFieldType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.IsValidVolatileFieldType方法的具体用法?C# TypeSymbol.IsValidVolatileFieldType怎么用?C# TypeSymbol.IsValidVolatileFieldType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.IsValidVolatileFieldType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeChecks
private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax, VariableDeclaratorSyntax declarator, DiagnosticBag diagnostics)
{
if (type.IsStatic)
{
// Cannot declare a variable of static type '{0}'
diagnostics.Add(ErrorCode.ERR_VarDeclIsStaticClass, this.ErrorLocation, type);
}
else if (type.SpecialType == SpecialType.System_Void)
{
diagnostics.Add(ErrorCode.ERR_FieldCantHaveVoidType, fieldSyntax.Declaration.Type.Location);
}
else if (type.IsRestrictedType())
{
diagnostics.Add(ErrorCode.ERR_FieldCantBeRefAny, fieldSyntax.Declaration.Type.Location, type);
}
else if (IsConst && !type.CanBeConst())
{
SyntaxToken constToken = default(SyntaxToken);
foreach (var modifier in fieldSyntax.Modifiers)
{
if (modifier.CSharpKind() == SyntaxKind.ConstKeyword)
{
constToken = modifier;
break;
}
}
Debug.Assert(constToken.CSharpKind() == SyntaxKind.ConstKeyword);
diagnostics.Add(ErrorCode.ERR_BadConstType, constToken.GetLocation(), type);
}
else if (IsVolatile && !type.IsValidVolatileFieldType())
{
if (ContainingType.TypeKind == TypeKind.Struct && !IsStatic && !IsConst)
{
var initializerOpt = declarator.Initializer;
if (initializerOpt != null)
{
// '{0}': cannot have instance field initializers in structs
diagnostics.Add(ErrorCode.ERR_FieldInitializerInStruct, this.ErrorLocation, this);
}
}
// '{0}': a volatile field cannot be of the type '{1}'
diagnostics.Add(ErrorCode.ERR_VolatileStruct, this.ErrorLocation, this, type);
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (!this.IsNoMoreVisibleThan(type, ref useSiteDiagnostics))
{
// Inconsistent accessibility: field type '{1}' is less accessible than field '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisFieldType, this.ErrorLocation, this, type);
}
diagnostics.Add(this.ErrorLocation, useSiteDiagnostics);
}
示例2: TypeChecks
protected void TypeChecks(TypeSymbol type, DiagnosticBag diagnostics)
{
if (type.IsStatic)
{
// Cannot declare a variable of static type '{0}'
diagnostics.Add(ErrorCode.ERR_VarDeclIsStaticClass, this.ErrorLocation, type);
}
else if (type.SpecialType == SpecialType.System_Void)
{
diagnostics.Add(ErrorCode.ERR_FieldCantHaveVoidType, TypeSyntax.Location);
}
else if (type.IsRestrictedType())
{
diagnostics.Add(ErrorCode.ERR_FieldCantBeRefAny, TypeSyntax.Location, type);
}
else if (IsConst && !type.CanBeConst())
{
SyntaxToken constToken = default(SyntaxToken);
foreach (var modifier in ModifiersTokenList)
{
if (modifier.Kind() == SyntaxKind.ConstKeyword)
{
constToken = modifier;
break;
}
}
Debug.Assert(constToken.Kind() == SyntaxKind.ConstKeyword);
diagnostics.Add(ErrorCode.ERR_BadConstType, constToken.GetLocation(), type);
}
else if (IsVolatile && !type.IsValidVolatileFieldType())
{
// '{0}': a volatile field cannot be of the type '{1}'
diagnostics.Add(ErrorCode.ERR_VolatileStruct, this.ErrorLocation, this, type);
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
if (!this.IsNoMoreVisibleThan(type, ref useSiteDiagnostics))
{
// Inconsistent accessibility: field type '{1}' is less accessible than field '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisFieldType, this.ErrorLocation, this, type);
}
diagnostics.Add(this.ErrorLocation, useSiteDiagnostics);
}