本文整理汇总了C#中CSharpCompilation.GetWellKnownType方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.GetWellKnownType方法的具体用法?C# CSharpCompilation.GetWellKnownType怎么用?C# CSharpCompilation.GetWellKnownType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.GetWellKnownType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: 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));
}
}
示例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 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));
}
}
示例4: RewriteLocal
internal override BoundExpression RewriteLocal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax)
{
Debug.Assert(this.Name == this.Name.ToLowerInvariant());
var method = container.GetOrAddSynthesizedMethod(
this.Name,
(c, n, s) =>
{
var returnType = compilation.GetWellKnownType(WellKnownType.System_Exception);
return new PlaceholderMethodSymbol(
c,
s,
n,
returnType,
m => ImmutableArray<ParameterSymbol>.Empty);
});
var call = BoundCall.Synthesized(syntax, receiverOpt: null, method: method);
return ConvertToLocalType(compilation, call, this.Type);
}
示例5: 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));
}
示例6: VerifyUnverifiableCodeAttribute
internal static void VerifyUnverifiableCodeAttribute(CSharpAttributeData moduleAttribute, CSharpCompilation compilation)
{
Assert.Equal(compilation.GetWellKnownType(WellKnownType.System_Security_UnverifiableCodeAttribute), moduleAttribute.AttributeClass);
Assert.Equal(compilation.GetWellKnownTypeMember(WellKnownMember.System_Security_UnverifiableCodeAttribute__ctor), moduleAttribute.AttributeConstructor);
Assert.Equal(0, moduleAttribute.CommonConstructorArguments.Length);
Assert.Equal(0, moduleAttribute.CommonNamedArguments.Length);
}
示例7: 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);
}
示例8: 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);
}
}
示例9: IsGenericTaskReturningAsync
/// <summary>
/// Returns whether this method is async and returns a generic task.
/// </summary>
public static bool IsGenericTaskReturningAsync(this MethodSymbol method, CSharpCompilation compilation)
{
return method.IsAsync
&& (object)method.ReturnType != null
&& method.ReturnType.Kind == SymbolKind.NamedType
&& ((NamedTypeSymbol)method.ReturnType).ConstructedFrom == compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task_T);
}
示例10: IsTaskReturningAsync
/// <summary>
/// Returns whether this method is async and returns a task.
/// </summary>
public static bool IsTaskReturningAsync(this MethodSymbol method, CSharpCompilation compilation)
{
return method.IsAsync
&& method.ReturnType == compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task);
}
示例11: 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);
}
示例12: CalculateReturnType
private static void CalculateReturnType(
CSharpCompilation compilation,
DiagnosticBag diagnostics,
out TypeSymbol resultType,
out TypeSymbol returnType)
{
var submissionReturnType = compilation.SubmissionReturnType;
if (submissionReturnType == null)
{
resultType = null;
returnType = compilation.GetSpecialType(SpecialType.System_Void);
}
else
{
var taskT = compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task_T);
var useSiteDiagnostic = taskT.GetUseSiteDiagnostic();
if (useSiteDiagnostic != null)
{
diagnostics.Add(useSiteDiagnostic, NoLocation.Singleton);
}
resultType = compilation.GetTypeByReflectionType(submissionReturnType, diagnostics);
returnType = taskT.Construct(resultType);
}
}