本文整理汇总了C#中CSharpCompilation.GetSpecialType方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.GetSpecialType方法的具体用法?C# CSharpCompilation.GetSpecialType怎么用?C# CSharpCompilation.GetSpecialType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.GetSpecialType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewriteLocal
internal override BoundExpression RewriteLocal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax)
{
var method = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetReturnValueMethodName,
(c, n, s) =>
{
var parameterType = compilation.GetSpecialType(SpecialType.System_Int32);
var returnType = compilation.GetSpecialType(SpecialType.System_Object);
return new PlaceholderMethodSymbol(
c,
s,
n,
returnType,
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)));
});
var argument = new BoundLiteral(
syntax,
Microsoft.CodeAnalysis.ConstantValue.Create(_index),
method.Parameters[0].Type);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(argument));
return ConvertToLocalType(compilation, call, this.Type);
}
示例2: RewriteLocalInternal
private static BoundExpression RewriteLocalInternal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax, LocalSymbol local)
{
var parameterType = compilation.GetSpecialType(SpecialType.System_String);
var getValueMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableValueMethodName,
(c, n, s) =>
{
var returnType = compilation.GetSpecialType(SpecialType.System_Object);
return new PlaceholderMethodSymbol(
c,
s,
n,
returnType,
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)));
});
var getAddressMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableAddressMethodName,
(c, n, s) =>
{
return new PlaceholderMethodSymbol(
c,
s,
n,
m => ImmutableArray.Create<TypeParameterSymbol>(new SimpleTypeParameterSymbol(m, 0, "<>T")),
m => m.TypeParameters[0], // return type is <>T&
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)),
returnValueIsByRef: true);
});
return new BoundPseudoVariable(
syntax,
local,
new ObjectIdExpressions(compilation, getValueMethod, getAddressMethod),
local.Type);
}
示例3: RewriteLocalDeclaration
private static void RewriteLocalDeclaration(
CSharpCompilation compilation,
EENamedTypeSymbol container,
HashSet<LocalSymbol> declaredLocals,
ArrayBuilder<BoundStatement> statements,
BoundLocalDeclaration node)
{
Debug.Assert(node.ArgumentsOpt.IsDefault);
var local = node.LocalSymbol;
var syntax = node.Syntax;
declaredLocals.Add(local);
var voidType = compilation.GetSpecialType(SpecialType.System_Void);
var objectType = compilation.GetSpecialType(SpecialType.System_Object);
var typeType = compilation.GetWellKnownType(WellKnownType.System_Type);
var stringType = compilation.GetSpecialType(SpecialType.System_String);
// <>CreateVariable(Type type, string name)
var method = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.CreateVariableMethodName,
(c, n, s) => new PlaceholderMethodSymbol(
c,
s,
n,
voidType,
m => ImmutableArray.Create<ParameterSymbol>(
new SynthesizedParameterSymbol(m, typeType, ordinal: 0, refKind: RefKind.None),
new SynthesizedParameterSymbol(m, stringType, ordinal: 1, refKind: RefKind.None))));
var type = new BoundTypeOfOperator(syntax, new BoundTypeExpression(syntax, aliasOpt: null, type: local.Type), null, typeType);
var name = new BoundLiteral(syntax, ConstantValue.Create(local.Name), stringType);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create<BoundExpression>(type, name));
statements.Add(new BoundExpressionStatement(syntax, call));
var initializer = node.InitializerOpt;
if (initializer != null)
{
// Generate assignment to local. The assignment will
// be rewritten in PlaceholderLocalRewriter.
var assignment = new BoundAssignmentOperator(
syntax,
new BoundLocal(syntax, local, constantValueOpt: null, type: local.Type),
initializer,
RefKind.None,
local.Type);
statements.Add(new BoundExpressionStatement(syntax, assignment));
}
}
示例4: TypedConstantTests
public TypedConstantTests()
{
compilation = CreateCompilationWithMscorlib("class C {}");
namedType = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
systemType = compilation.GetWellKnownType(WellKnownType.System_Type);
arrayType = compilation.CreateArrayTypeSymbol(compilation.GetSpecialType(SpecialType.System_Object));
intType = compilation.GetSpecialType(SpecialType.System_Int32);
stringType = compilation.GetSpecialType(SpecialType.System_String);
enumString1 = compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(compilation.GetSpecialType(SpecialType.System_String));
enumString2 = compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(compilation.GetSpecialType(SpecialType.System_String));
}
示例5: RewriteLocalDeclaration
private static void RewriteLocalDeclaration(
CSharpCompilation compilation,
EENamedTypeSymbol container,
HashSet<LocalSymbol> declaredLocals,
ArrayBuilder<BoundStatement> statements,
BoundLocalDeclaration node)
{
Debug.Assert(node.ArgumentsOpt.IsDefault);
var local = node.LocalSymbol;
var syntax = node.Syntax;
declaredLocals.Add(local);
var typeType = compilation.GetWellKnownType(WellKnownType.System_Type);
var stringType = compilation.GetSpecialType(SpecialType.System_String);
var guidConstructor = (MethodSymbol)compilation.GetWellKnownTypeMember(WellKnownMember.System_Guid__ctor);
// CreateVariable(Type type, string name)
var method = PlaceholderLocalSymbol.GetIntrinsicMethod(compilation, ExpressionCompilerConstants.CreateVariableMethodName);
var type = new BoundTypeOfOperator(syntax, new BoundTypeExpression(syntax, aliasOpt: null, type: local.Type), null, typeType);
var name = new BoundLiteral(syntax, ConstantValue.Create(local.Name), stringType);
bool hasCustomTypeInfoPayload;
var customTypeInfoPayload = GetCustomTypeInfoPayload(local, syntax, compilation, out hasCustomTypeInfoPayload);
var customTypeInfoPayloadId = GetCustomTypeInfoPayloadId(syntax, guidConstructor, hasCustomTypeInfoPayload);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create(type, name, customTypeInfoPayloadId, customTypeInfoPayload));
statements.Add(new BoundExpressionStatement(syntax, call));
var initializer = node.InitializerOpt;
if (initializer != null)
{
// Generate assignment to local. The assignment will
// be rewritten in PlaceholderLocalRewriter.
var assignment = new BoundAssignmentOperator(
syntax,
new BoundLocal(syntax, local, constantValueOpt: null, type: local.Type),
initializer,
RefKind.None,
local.Type);
statements.Add(new BoundExpressionStatement(syntax, assignment));
}
}
示例6: CreateLocal
private static void CreateLocal(CSharpCompilation compilation, HashSet<LocalSymbol> declaredLocals, ArrayBuilder<BoundStatement> statements, LocalSymbol local, SyntaxNode syntax)
{
declaredLocals.Add(local);
var typeType = compilation.GetWellKnownType(WellKnownType.System_Type);
var stringType = compilation.GetSpecialType(SpecialType.System_String);
var guidConstructor = (MethodSymbol)compilation.GetWellKnownTypeMember(WellKnownMember.System_Guid__ctor);
// CreateVariable(Type type, string name)
var method = PlaceholderLocalSymbol.GetIntrinsicMethod(compilation, ExpressionCompilerConstants.CreateVariableMethodName);
var type = new BoundTypeOfOperator(syntax, new BoundTypeExpression(syntax, aliasOpt: null, type: local.Type), null, typeType);
var name = new BoundLiteral(syntax, ConstantValue.Create(local.Name), stringType);
bool hasCustomTypeInfoPayload;
var customTypeInfoPayload = GetCustomTypeInfoPayload(local, syntax, compilation, out hasCustomTypeInfoPayload);
var customTypeInfoPayloadId = GetCustomTypeInfoPayloadId(syntax, guidConstructor, hasCustomTypeInfoPayload);
var call = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: method,
arguments: ImmutableArray.Create(type, name, customTypeInfoPayloadId, customTypeInfoPayload));
statements.Add(new BoundExpressionStatement(syntax, call));
}
示例7: ConvertToLocalType
internal static BoundExpression ConvertToLocalType(CSharpCompilation compilation, BoundExpression expr, TypeSymbol type, DiagnosticBag diagnostics)
{
if (type.IsPointerType())
{
var syntax = expr.Syntax;
var intPtrType = compilation.GetSpecialType(SpecialType.System_IntPtr);
Binder.ReportUseSiteDiagnostics(intPtrType, diagnostics, syntax);
MethodSymbol conversionMethod;
if (Binder.TryGetSpecialTypeMember(compilation, SpecialMember.System_IntPtr__op_Explicit_ToPointer, syntax, diagnostics, out conversionMethod))
{
var temp = ConvertToLocalTypeHelper(compilation, expr, intPtrType, diagnostics);
expr = BoundCall.Synthesized(
syntax,
receiverOpt: null,
method: conversionMethod,
arg0: temp);
}
else
{
return new BoundBadExpression(
syntax,
LookupResultKind.Empty,
ImmutableArray<Symbol>.Empty,
ImmutableArray.Create<BoundNode>(expr),
type);
}
}
return ConvertToLocalTypeHelper(compilation, expr, type, diagnostics);
}
示例8: VerifySkipVerificationSecurityAttribute
internal static void VerifySkipVerificationSecurityAttribute(Cci.SecurityAttribute securityAttribute, CSharpCompilation compilation)
{
var assemblyAttribute = (CSharpAttributeData)securityAttribute.Attribute;
Assert.Equal(compilation.GetWellKnownType(WellKnownType.System_Security_Permissions_SecurityPermissionAttribute), assemblyAttribute.AttributeClass);
Assert.Equal(compilation.GetWellKnownTypeMember(WellKnownMember.System_Security_Permissions_SecurityPermissionAttribute__ctor), assemblyAttribute.AttributeConstructor);
var assemblyAttributeArgument = assemblyAttribute.CommonConstructorArguments.Single();
Assert.Equal(compilation.GetWellKnownType(WellKnownType.System_Security_Permissions_SecurityAction), assemblyAttributeArgument.Type);
Assert.Equal(DeclarativeSecurityAction.RequestMinimum, securityAttribute.Action);
Assert.Equal(DeclarativeSecurityAction.RequestMinimum, (DeclarativeSecurityAction)(int)assemblyAttributeArgument.Value);
var assemblyAttributeNamedArgument = assemblyAttribute.CommonNamedArguments.Single();
Assert.Equal("SkipVerification", assemblyAttributeNamedArgument.Key);
var assemblyAttributeNamedArgumentValue = assemblyAttributeNamedArgument.Value;
Assert.Equal(compilation.GetSpecialType(SpecialType.System_Boolean), assemblyAttributeNamedArgumentValue.Type);
Assert.Equal(true, assemblyAttributeNamedArgumentValue.Value);
}
示例9: VerifyNormalEventShape
private static void VerifyNormalEventShape(EventSymbol @event, CSharpCompilation compilation)
{
Assert.False(@event.IsWindowsRuntimeEvent);
var eventType = @event.Type;
var voidType = compilation.GetSpecialType(SpecialType.System_Void);
Assert.NotNull(voidType);
var addMethod = @event.AddMethod;
Assert.Equal(voidType, addMethod.ReturnType);
Assert.True(addMethod.ReturnsVoid);
Assert.Equal(1, addMethod.ParameterCount);
Assert.Equal(eventType, addMethod.ParameterTypes.Single());
var removeMethod = @event.RemoveMethod;
Assert.Equal(voidType, removeMethod.ReturnType);
Assert.True(removeMethod.ReturnsVoid);
Assert.Equal(1, removeMethod.ParameterCount);
Assert.Equal(eventType, removeMethod.ParameterTypes.Single());
if (@event.HasAssociatedField)
{
Assert.Equal(eventType, @event.AssociatedField.Type);
}
else
{
Assert.Null(@event.AssociatedField);
}
}
示例10: VerifyWinRTEventShape
private static void VerifyWinRTEventShape(EventSymbol @event, CSharpCompilation compilation)
{
Assert.True(@event.IsWindowsRuntimeEvent);
var eventType = @event.Type;
var tokenType = compilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationToken);
Assert.NotNull(tokenType);
var voidType = compilation.GetSpecialType(SpecialType.System_Void);
Assert.NotNull(voidType);
var addMethod = @event.AddMethod;
Assert.Equal(tokenType, addMethod.ReturnType);
Assert.False(addMethod.ReturnsVoid);
Assert.Equal(1, addMethod.ParameterCount);
Assert.Equal(eventType, addMethod.ParameterTypes.Single());
var removeMethod = @event.RemoveMethod;
Assert.Equal(voidType, removeMethod.ReturnType);
Assert.True(removeMethod.ReturnsVoid);
Assert.Equal(1, removeMethod.ParameterCount);
Assert.Equal(tokenType, removeMethod.ParameterTypes.Single());
if (@event.HasAssociatedField)
{
var expectedFieldType = compilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T).Construct(eventType);
Assert.Equal(expectedFieldType, @event.AssociatedField.Type);
}
else
{
Assert.Null(@event.AssociatedField);
}
}
示例11: GetCustomTypeInfoPayload
private static BoundExpression GetCustomTypeInfoPayload(LocalSymbol local, SyntaxNode syntax, CSharpCompilation compilation, out bool hasCustomTypeInfoPayload)
{
var byteArrayType = ArrayTypeSymbol.CreateSZArray(
compilation.Assembly,
compilation.GetSpecialType(SpecialType.System_Byte));
var flags = CSharpCompilation.DynamicTransformsEncoder.Encode(local.Type, customModifiersCount: 0, refKind: RefKind.None);
var bytes = DynamicFlagsCustomTypeInfo.Create(flags).GetCustomTypeInfoPayload();
hasCustomTypeInfoPayload = bytes != null;
if (!hasCustomTypeInfoPayload)
{
return new BoundLiteral(syntax, ConstantValue.Null, byteArrayType);
}
var byteType = byteArrayType.ElementType;
var intType = compilation.GetSpecialType(SpecialType.System_Int32);
var numBytes = bytes.Count;
var initializerExprs = ArrayBuilder<BoundExpression>.GetInstance(numBytes);
foreach (var b in bytes)
{
initializerExprs.Add(new BoundLiteral(syntax, ConstantValue.Create(b), byteType));
}
var lengthExpr = new BoundLiteral(syntax, ConstantValue.Create(numBytes), intType);
return new BoundArrayCreation(
syntax,
ImmutableArray.Create<BoundExpression>(lengthExpr),
new BoundArrayInitialization(syntax, initializerExprs.ToImmutableAndFree()),
byteArrayType);
}
示例12: ValidateDynamicAttribute
private static void ValidateDynamicAttribute(Symbol symbol, CSharpCompilation comp, MethodSymbol dynamicAttributeCtorNoArgs,
MethodSymbol dynamicAttributeCtorTransformFlags, bool expectedDynamicAttribute, bool[] expectedTransformFlags = null, bool forReturnType = false)
{
Assert.True(!forReturnType || symbol.Kind == SymbolKind.Method, "Incorrect usage of ValidateDynamicAttribute");
var synthesizedDynamicAttributes = symbol.GetSynthesizedAttributes(forReturnType).Where((attr) => string.Equals(attr.AttributeClass.Name, "DynamicAttribute", StringComparison.Ordinal));
if (!expectedDynamicAttribute)
{
Assert.Empty(synthesizedDynamicAttributes);
}
else
{
Assert.Equal(1, synthesizedDynamicAttributes.Count());
var dynamicAttribute = synthesizedDynamicAttributes.First();
var expectedCtor = expectedTransformFlags == null ? dynamicAttributeCtorNoArgs : dynamicAttributeCtorTransformFlags;
Assert.NotNull(expectedCtor);
Assert.Equal(expectedCtor, dynamicAttribute.AttributeConstructor);
if (expectedTransformFlags == null)
{
// Dynamic()
Assert.Equal(0, dynamicAttribute.CommonConstructorArguments.Length);
}
else
{
// Dynamic(bool[] transformFlags)
Assert.Equal(1, dynamicAttribute.CommonConstructorArguments.Length);
TypedConstant argument = dynamicAttribute.CommonConstructorArguments[0];
Assert.Equal(TypedConstantKind.Array, argument.Kind);
ImmutableArray<TypedConstant> actualTransformFlags = argument.Values;
Assert.Equal(expectedTransformFlags.Length, actualTransformFlags.Length);
TypeSymbol booleanType = comp.GetSpecialType(SpecialType.System_Boolean);
for (int i = 0; i < actualTransformFlags.Length; i++)
{
TypedConstant actualTransformFlag = actualTransformFlags[i];
Assert.Equal(TypedConstantKind.Primitive, actualTransformFlag.Kind);
Assert.Equal(booleanType, actualTransformFlag.Type);
Assert.Equal(expectedTransformFlags[i], (bool)actualTransformFlag.Value);
}
}
}
}
示例13: TestBinaryIntrinsicSymbol
//.........这里部分代码省略.........
case BinaryOperatorKind.LogicalOr:
Assert.Null(symbol1);
Assert.Null(symbol2);
Assert.Null(symbol3);
Assert.Null(symbol4);
return;
}
BinaryOperatorKind result = OverloadResolution.BinopEasyOut.OpKind(op, leftType, rightType);
BinaryOperatorSignature signature;
bool isDynamic = (leftType.IsDynamic() || rightType.IsDynamic());
if (result == BinaryOperatorKind.Error)
{
if (leftType.IsDynamic() && !rightType.IsPointerType() && !rightType.IsRestrictedType())
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Dynamic, leftType, rightType, leftType);
}
else if (rightType.IsDynamic() && !leftType.IsPointerType() && !leftType.IsRestrictedType())
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Dynamic, leftType, rightType, rightType);
}
else if ((op == BinaryOperatorKind.Equal || op == BinaryOperatorKind.NotEqual) &&
leftType.IsReferenceType && rightType.IsReferenceType &&
(leftType == rightType || compilation.Conversions.ClassifyConversion(leftType, rightType, ref useSiteDiagnostics).IsReference))
{
if (leftType.IsDelegateType() && rightType.IsDelegateType())
{
Assert.Equal(leftType, rightType);
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Delegate,
leftType, // TODO: this feels like a spec violation
leftType, // TODO: this feels like a spec violation
compilation.GetSpecialType(SpecialType.System_Boolean));
}
else if (leftType.SpecialType == SpecialType.System_Delegate && rightType.SpecialType == SpecialType.System_Delegate)
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Delegate,
compilation.GetSpecialType(SpecialType.System_Delegate), compilation.GetSpecialType(SpecialType.System_Delegate),
compilation.GetSpecialType(SpecialType.System_Boolean));
}
else
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Object, compilation.ObjectType, compilation.ObjectType,
compilation.GetSpecialType(SpecialType.System_Boolean));
}
}
else if (op == BinaryOperatorKind.Addition &&
((leftType.IsStringType() && !rightType.IsPointerType()) || (!leftType.IsPointerType() && rightType.IsStringType())))
{
Assert.False(leftType.IsStringType() && rightType.IsStringType());
if (leftType.IsStringType())
{
signature = new BinaryOperatorSignature(op | BinaryOperatorKind.String, leftType, compilation.ObjectType, leftType);
}
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()))))
{
示例14: CalculateReturnType
private static void CalculateReturnType(
CSharpCompilation compilation,
DiagnosticBag diagnostics,
out TypeSymbol resultType,
out TypeSymbol returnType)
{
var submissionReturnTypeOpt = compilation.ScriptCompilationInfo?.ReturnTypeOpt;
var taskT = compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task_T);
var useSiteDiagnostic = taskT.GetUseSiteDiagnostic();
if (useSiteDiagnostic != null)
{
diagnostics.Add(useSiteDiagnostic, NoLocation.Singleton);
}
// If no explicit return type is set on ScriptCompilationInfo, default to
// System.Object from the target corlib. This allows cross compiling scripts
// to run on a target corlib that may differ from the host compiler's corlib.
// cf. https://github.com/dotnet/roslyn/issues/8506
resultType = (object)submissionReturnTypeOpt == null
? compilation.GetSpecialType(SpecialType.System_Object)
: compilation.GetTypeByReflectionType(submissionReturnTypeOpt, diagnostics);
returnType = taskT.Construct(resultType);
}
示例15: CalculateReturnType
private static TypeSymbol CalculateReturnType(CSharpCompilation compilation, BoundStatement bodyOpt)
{
if (bodyOpt == null)
{
// If the method doesn't do anything, then it doesn't return anything.
return compilation.GetSpecialType(SpecialType.System_Void);
}
switch (bodyOpt.Kind)
{
case BoundKind.ReturnStatement:
return ((BoundReturnStatement)bodyOpt).ExpressionOpt.Type;
case BoundKind.ExpressionStatement:
case BoundKind.LocalDeclaration:
case BoundKind.MultipleLocalDeclarations:
return compilation.GetSpecialType(SpecialType.System_Void);
default:
throw ExceptionUtilities.UnexpectedValue(bodyOpt.Kind);
}
}