本文整理汇总了C#中TypeSymbol.EnumUnderlyingType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.EnumUnderlyingType方法的具体用法?C# TypeSymbol.EnumUnderlyingType怎么用?C# TypeSymbol.EnumUnderlyingType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.EnumUnderlyingType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBinaryIntrinsicSymbol
//.........这里部分代码省略.........
else
{
Assert.True(rightType.IsStringType());
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.String, compilation.ObjectType, rightType, rightType);
}
}
else if (op == BinaryOperatorKind.Addition &&
(((leftType.IsIntegralType() || leftType.IsCharType()) && rightType.IsPointerType()) ||
(leftType.IsPointerType() && (rightType.IsIntegralType() || rightType.IsCharType()))))
{
if (leftType.IsPointerType())
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Pointer, leftType, symbol1.Parameters[1].Type, leftType);
Assert.True(symbol1.Parameters[1].Type.IsIntegralType());
}
else
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Pointer, symbol1.Parameters[0].Type, rightType, rightType);
Assert.True(symbol1.Parameters[0].Type.IsIntegralType());
}
}
else if (op == BinaryOperatorKind.Subtraction &&
(leftType.IsPointerType() && (rightType.IsIntegralType() || rightType.IsCharType())))
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.String, leftType, symbol1.Parameters[1].Type, leftType);
Assert.True(symbol1.Parameters[1].Type.IsIntegralType());
}
else if (op == BinaryOperatorKind.Subtraction && leftType.IsPointerType() && leftType == rightType)
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Pointer, leftType, rightType, compilation.GetSpecialType(SpecialType.System_Int64));
}
else if ((op == BinaryOperatorKind.Addition || op == BinaryOperatorKind.Subtraction) &&
leftType.IsEnumType() && (rightType.IsIntegralType() || rightType.IsCharType()) &&
(result = OverloadResolution.BinopEasyOut.OpKind(op, leftType.EnumUnderlyingType(), rightType)) != BinaryOperatorKind.Error &&
(signature = compilation.builtInOperators.GetSignature(result)).RightType == leftType.EnumUnderlyingType())
{
signature = new BinaryOperatorSignature(signature.Kind | BinaryOperatorKind.EnumAndUnderlying, leftType, signature.RightType, leftType);
}
else if ((op == BinaryOperatorKind.Addition || op == BinaryOperatorKind.Subtraction) &&
rightType.IsEnumType() && (leftType.IsIntegralType() || leftType.IsCharType()) &&
(result = OverloadResolution.BinopEasyOut.OpKind(op, leftType, rightType.EnumUnderlyingType())) != BinaryOperatorKind.Error &&
(signature = compilation.builtInOperators.GetSignature(result)).LeftType == rightType.EnumUnderlyingType())
{
signature = new BinaryOperatorSignature(signature.Kind | BinaryOperatorKind.EnumAndUnderlying, signature.LeftType, rightType, rightType);
}
else if (op == BinaryOperatorKind.Subtraction &&
leftType.IsEnumType() && leftType == rightType)
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Enum, leftType, rightType, leftType.EnumUnderlyingType());
}
else if ((op == BinaryOperatorKind.Equal ||
op == BinaryOperatorKind.NotEqual ||
op == BinaryOperatorKind.LessThan ||
op == BinaryOperatorKind.LessThanOrEqual ||
op == BinaryOperatorKind.GreaterThan ||
op == BinaryOperatorKind.GreaterThanOrEqual) &&
leftType.IsEnumType() && leftType == rightType)
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Enum, leftType, rightType, compilation.GetSpecialType(SpecialType.System_Boolean));
}
else if ((op == BinaryOperatorKind.Xor ||
op == BinaryOperatorKind.And ||
op == BinaryOperatorKind.Or) &&
leftType.IsEnumType() && leftType == rightType)
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Enum, leftType, rightType, leftType);
示例2: ShouldEmitBlockInitializer
private ArrayInitializerStyle ShouldEmitBlockInitializer(TypeSymbol elementType, ImmutableArray<BoundExpression> inits)
{
if (!_module.SupportsPrivateImplClass)
{
return ArrayInitializerStyle.Element;
}
if (elementType.IsEnumType())
{
if (!_module.Compilation.EnableEnumArrayBlockInitialization)
{
return ArrayInitializerStyle.Element;
}
elementType = elementType.EnumUnderlyingType();
}
if (elementType.SpecialType.IsBlittable())
{
if (_module.GetInitArrayHelper() == null)
{
return ArrayInitializerStyle.Element;
}
int initCount = 0;
int constCount = 0;
InitializerCountRecursive(inits, ref initCount, ref constCount);
if (initCount > 2)
{
if (initCount == constCount)
{
return ArrayInitializerStyle.Block;
}
int thresholdCnt = Math.Max(3, (initCount / 3));
if (constCount >= thresholdCnt)
{
return ArrayInitializerStyle.Mixed;
}
}
}
return ArrayInitializerStyle.Element;
}
示例3: TestUnaryIntrinsicSymbol
private void TestUnaryIntrinsicSymbol(
UnaryOperatorKind op,
TypeSymbol type,
CSharpCompilation compilation,
SemanticModel semanticModel,
ExpressionSyntax node1,
ExpressionSyntax node2,
ExpressionSyntax node3,
ExpressionSyntax node4
)
{
SymbolInfo info1 = semanticModel.GetSymbolInfo(node1);
Assert.Equal(type.IsDynamic() ? CandidateReason.LateBound : CandidateReason.None, info1.CandidateReason);
Assert.Equal(0, info1.CandidateSymbols.Length);
var symbol1 = (MethodSymbol)info1.Symbol;
var symbol2 = semanticModel.GetSymbolInfo(node2).Symbol;
var symbol3 = (MethodSymbol)semanticModel.GetSymbolInfo(node3).Symbol;
var symbol4 = semanticModel.GetSymbolInfo(node4).Symbol;
Assert.Equal(symbol1, symbol3);
if ((object)symbol1 != null)
{
Assert.NotSame(symbol1, symbol3);
Assert.Equal(symbol1.GetHashCode(), symbol3.GetHashCode());
Assert.Equal(symbol1.Parameters[0], symbol3.Parameters[0]);
Assert.Equal(symbol1.Parameters[0].GetHashCode(), symbol3.Parameters[0].GetHashCode());
}
Assert.Equal(symbol2, symbol4);
TypeSymbol underlying = type;
if (op == UnaryOperatorKind.BitwiseComplement ||
op == UnaryOperatorKind.PrefixDecrement || op == UnaryOperatorKind.PrefixIncrement ||
op == UnaryOperatorKind.PostfixDecrement || op == UnaryOperatorKind.PostfixIncrement)
{
underlying = type.EnumUnderlyingType();
}
UnaryOperatorKind result = OverloadResolution.UnopEasyOut.OpKind(op, underlying);
UnaryOperatorSignature signature;
if (result == UnaryOperatorKind.Error)
{
if (type.IsDynamic())
{
signature = new UnaryOperatorSignature(op | UnaryOperatorKind.Dynamic, type, type);
}
else if (type.IsPointerType() &&
(op == UnaryOperatorKind.PrefixDecrement || op == UnaryOperatorKind.PrefixIncrement ||
op == UnaryOperatorKind.PostfixDecrement || op == UnaryOperatorKind.PostfixIncrement))
{
signature = new UnaryOperatorSignature(op | UnaryOperatorKind.Pointer, type, type);
}
else
{
Assert.Null(symbol1);
Assert.Null(symbol2);
Assert.Null(symbol3);
Assert.Null(symbol4);
return;
}
}
else
{
signature = compilation.builtInOperators.GetSignature(result);
if ((object)underlying != (object)type)
{
Assert.Equal(underlying, signature.OperandType);
Assert.Equal(underlying, signature.ReturnType);
signature = new UnaryOperatorSignature(signature.Kind, type, type);
}
}
Assert.NotNull(symbol1);
string containerName = signature.OperandType.ToTestDisplayString();
string returnName = signature.ReturnType.ToTestDisplayString();
if (op == UnaryOperatorKind.LogicalNegation && type.IsEnumType())
{
containerName = type.ToTestDisplayString();
returnName = containerName;
}
Assert.Equal(String.Format("{2} {0}.{1}({0} value)",
containerName,
OperatorFacts.UnaryOperatorNameFromOperatorKind(op),
returnName),
symbol1.ToTestDisplayString());
Assert.Equal(MethodKind.BuiltinOperator, symbol1.MethodKind);
Assert.True(symbol1.IsImplicitlyDeclared);
bool expectChecked = false;
//.........这里部分代码省略.........