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


C# TypeMap.SubstituteType方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap.SubstituteType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeMap.SubstituteType方法的具体用法?C# TypeMap.SubstituteType怎么用?C# TypeMap.SubstituteType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap的用法示例。


在下文中一共展示了TypeMap.SubstituteType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToOtherMethod

 internal static LocalSymbol ToOtherMethod(this LocalSymbol local, MethodSymbol method, TypeMap typeMap)
 {
     var l = local as EELocalSymbolBase;
     if ((object)l != null)
     {
         return l.ToOtherMethod(method, typeMap);
     }
     var type = typeMap.SubstituteType(local.Type);
     return new EELocalSymbol(method, local.Locations, local.Name, -1, local.DeclarationKind, type.Type, local.RefKind, local.IsPinned, local.IsCompilerGenerated, local.CanScheduleToStack);
 }
开发者ID:noahfalk,项目名称:roslyn,代码行数:10,代码来源:EELocalSymbolBase.cs

示例2: TypeMap

        public void TypeMap()
        {
            var source = @"
struct S<T> where T : struct
{
}
";

            var comp = CreateCompilationWithMscorlib(source);
            comp.VerifyDiagnostics();

            var intType = comp.GetSpecialType(SpecialType.System_Int32);
            var customModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateOptional(intType));

            var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
            var typeParamType = structType.TypeParameters.Single();

            var pointerType = new PointerTypeSymbol(typeParamType, customModifiers); // NOTE: We're constructing this manually, since it's illegal.
            var arrayType = new ArrayTypeSymbol(comp.Assembly, typeParamType, customModifiers); // This is legal, but we're already manually constructing types.

            var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create<TypeSymbol>(intType));

            var substitutedPointerType = (PointerTypeSymbol)typeMap.SubstituteType(pointerType);
            var substitutedArrayType = (ArrayTypeSymbol)typeMap.SubstituteType(arrayType);

            // The map changed the types.
            Assert.Equal(intType, substitutedPointerType.PointedAtType);
            Assert.Equal(intType, substitutedArrayType.ElementType);

            // The map preserved the custom modifiers.
            Assert.Equal(customModifiers, substitutedPointerType.CustomModifiers);
            Assert.Equal(customModifiers, substitutedArrayType.CustomModifiers);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:ModifierTests.cs

示例3: MakeHoistedLocalField

        private SynthesizedFieldSymbolBase MakeHoistedLocalField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
        {
            Debug.Assert(local.SynthesizedLocalKind == SynthesizedLocalKind.None ||
                         local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass);

            int index = nextLocalNumber++;

            // Special Case: There's logic in the EE to recognize locals that have been captured by a lambda
            // and would have been hoisted for the state machine.  Basically, we just hoist the local containing
            // the instance of the lambda display class and retain its original name (rather than using an
            // iterator local name).  See FUNCBRECEE::ImportIteratorMethodInheritedLocals.
            string fieldName = (local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass)
                ? GeneratedNames.MakeLambdaDisplayClassStorageName(index)
                : GeneratedNames.MakeHoistedLocalFieldName(local.Name, index);

            return F.StateMachineField(TypeMap.SubstituteType(type), fieldName, index);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:17,代码来源:StateMachineRewriter.cs

示例4: ToOtherMethod

 internal override EELocalSymbolBase ToOtherMethod(MethodSymbol method, TypeMap typeMap)
 {
     var type = typeMap.SubstituteType(_type);
     return new EELocalSymbol(method, _locations, _nameOpt, _ordinal, _declarationKind, type.Type, _refKind, _isPinned, _isCompilerGenerated, _canScheduleToStack);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:5,代码来源:EELocalSymbol.cs

示例5: SubstituteField

 private static FieldSymbol SubstituteField(FieldSymbol field, TypeMap typeMap)
 {
     Debug.Assert(!field.IsStatic);
     Debug.Assert(!field.IsReadOnly);
     Debug.Assert(field.CustomModifiers.Length == 0);
     // CONSIDER: Instead of digging fields out of the unsubstituted type and then performing substitution
     // on each one individually, we could dig fields out of the substituted type.
     return new EEDisplayClassFieldSymbol(typeMap.SubstituteNamedType(field.ContainingType), field.Name, typeMap.SubstituteType(field.Type));
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:9,代码来源:DisplayClassVariable.cs

示例6: TryCreate

        internal static bool TryCreate(SyntheticBoundNodeFactory F, MethodSymbol method, TypeMap typeMap, out AsyncMethodBuilderMemberCollection collection)
        {
            if (method.IsVoidReturningAsync())
            {
                return TryCreate(
                    F: F,

                    builderType: F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncVoidMethodBuilder),
                    resultType: F.SpecialType(SpecialType.System_Void),

                    setException: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetException,
                    setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetResult,
                    awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__AwaitOnCompleted,
                    awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__AwaitUnsafeOnCompleted,
                    start: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__Start_T,
                    setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncVoidMethodBuilder__SetStateMachine,
                    task: null,
                    collection: out collection);
            }

            if (method.IsTaskReturningAsync(F.Compilation))
            {
                NamedTypeSymbol builderType = F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder);

                PropertySymbol task;
                if (!TryGetWellKnownPropertyAsMember(F, WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__Task, builderType, out task))
                {
                    collection = default(AsyncMethodBuilderMemberCollection);
                    return false;
                }

                return TryCreate(
                    F: F,

                    builderType: F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder),
                    resultType: F.SpecialType(SpecialType.System_Void),

                    setException: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetException,
                    setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetResult,
                    awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__AwaitOnCompleted,
                    awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__AwaitUnsafeOnCompleted,
                    start: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__Start_T,
                    setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder__SetStateMachine,
                    task: task,
                    collection: out collection);
            }

            if (method.IsGenericTaskReturningAsync(F.Compilation))
            {
                TypeSymbol resultType = method.ReturnType.GetMemberTypeArgumentsNoUseSiteDiagnostics().Single();

                if (resultType.IsDynamic())
                {
                    resultType = F.SpecialType(SpecialType.System_Object);
                }

                if (typeMap != null)
                {
                    resultType = typeMap.SubstituteType(resultType).Type;
                }

                NamedTypeSymbol builderType = F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T).Construct(resultType);

                PropertySymbol task;
                if (!TryGetWellKnownPropertyAsMember(F, WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__Task, builderType, out task))
                {
                    collection = default(AsyncMethodBuilderMemberCollection);
                    return false;
                }

                return TryCreate(
                    F: F,

                    builderType: builderType,
                    resultType: resultType,

                    setException: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetException,
                    setResult: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetResult,
                    awaitOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__AwaitOnCompleted,
                    awaitUnsafeOnCompleted: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__AwaitUnsafeOnCompleted,
                    start: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__Start_T,
                    setStateMachine: WellKnownMember.System_Runtime_CompilerServices_AsyncTaskMethodBuilder_T__SetStateMachine,
                    task: task,
                    collection: out collection);
            }

            throw ExceptionUtilities.UnexpectedValue(method);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:88,代码来源:AsyncMethodBuilderMemberCollection.cs

示例7: ToOtherMethod

 internal override EELocalSymbolBase ToOtherMethod(MethodSymbol method, TypeMap typeMap)
 {
     var type = typeMap.SubstituteType(_type);
     return new EELocalConstantSymbol(method, _name, type, _value);
 }
开发者ID:daking2014,项目名称:roslyn,代码行数:5,代码来源:EELocalConstantSymbol.cs

示例8: CreateInitialProxies

        private void CreateInitialProxies(
           TypeMap TypeMap,
           IOrderedEnumerable<Symbol> captured,
           MultiDictionary<Symbol, CSharpSyntaxNode> locations)
        {
            foreach (var sym in captured)
            {
                var local = sym as LocalSymbol;
                if ((object)local != null && local.DeclarationKind != LocalDeclarationKind.CompilerGenerated)
                {
                    Debug.Assert(local.RefKind == RefKind.None); // there are no user-declared ref variables
                    MakeInitialProxy(TypeMap, locations, local);
                    continue;
                }

                var parameter = sym as ParameterSymbol;
                if ((object)parameter != null)
                {
                    if (parameter.IsThis)
                    {
                        var proxyField = F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyName(), isPublic: true);
                        variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));

                        if (PreserveInitialLocals)
                        {
                            var initialThis = method.ContainingType.IsStructType() ? 
                                F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyProxyName(), isPublic: true) : proxyField;

                            initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(initialThis));
                        }
                    }
                    else
                    {
                        var proxyField = F.StateMachineField(TypeMap.SubstituteType(parameter.Type), parameter.Name, isPublic: true);
                        variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));

                        if (PreserveInitialLocals)
                        {
                            string proxyName = GeneratedNames.IteratorParameterProxyName(parameter.Name);
                            initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(
                                F.StateMachineField(TypeMap.SubstituteType(parameter.Type), proxyName, isPublic: true)));
                        }
                        if (parameter.Type.IsRestrictedType())
                        {
                            // CS4013: Instance of type '{0}' cannot be used inside an anonymous function, query expression, iterator block or async method
                            diagnostics.Add(ErrorCode.ERR_SpecialByRefInLambda, parameter.Locations[0], parameter.Type);
                        }
                    }
                }
            }
        }
开发者ID:pheede,项目名称:roslyn,代码行数:51,代码来源:StateMachineRewriter.cs

示例9: MakeHoistedField

        private SynthesizedFieldSymbolBase MakeHoistedField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
        {
            Debug.Assert(local.DeclarationKind != LocalDeclarationKind.CompilerGenerated);
            int index = nextLocalNumber++;

            // Special Case: There's logic in the EE to recognize locals that have been captured by a lambda
            // and would have been hoisted for the state machine.  Basically, we just hoist the local containing
            // the instance of the lambda display class and retain its original name (rather than using an
            // iterator local name).  See FUNCBRECEE::ImportIteratorMethodInheritedLocals.
            string fieldName = local.DeclarationKind == LocalDeclarationKind.CompilerGeneratedLambdaDisplayClassLocal
                ? local.Name
                : GeneratedNames.MakeIteratorLocalName(local.Name, index);
            return F.SynthesizeField(TypeMap.SubstituteType(type), fieldName, index, isPublic: true);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:StateMachineRewriter.cs


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