当前位置: 首页>>代码示例>>C#>>正文


C# CSharpCompilation.GetWellKnownType方法代码示例

本文整理汇总了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));
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:TypedConstantTests.cs

示例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));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:53,代码来源:LocalDeclarationRewriter.cs

示例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));
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:47,代码来源:LocalDeclarationRewriter.cs

示例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);
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:18,代码来源:ExceptionLocalSymbol.cs

示例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));
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:23,代码来源:LocalDeclarationRewriter.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:AttributeTests_Synthesized.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:18,代码来源:AttributeTests_Synthesized.cs

示例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);
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:32,代码来源:WinMdEventTests.cs

示例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);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:10,代码来源:MethodSymbolExtensions.cs

示例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);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:MethodSymbolExtensions.cs

示例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);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:22,代码来源:SynthesizedInteractiveInitializerMethod.cs

示例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);
     }
 }
开发者ID:noahstein,项目名称:roslyn,代码行数:24,代码来源:SynthesizedInteractiveInitializerMethod.cs


注:本文中的CSharpCompilation.GetWellKnownType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。