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


C# ModuleCompilationState.TryGetStateMachineType方法代码示例

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


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

示例1: AddSynthesizedAttributes

        internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes)
        {
            base.AddSynthesizedAttributes(compilationState, ref attributes);

            if (this.IsAsync || this.IsIterator)
            {
                var compilation = this.DeclaringCompilation;

                // The async state machine type is not synthesized until the async method body is rewritten. If we are
                // only emitting metadata the method body will not have been rewritten, and the async state machine
                // type will not have been created. In this case, omit the attribute.
                NamedTypeSymbol stateMachineType;
                if (compilationState.TryGetStateMachineType(this, out stateMachineType))
                {
                    WellKnownMember ctor = this.IsAsync ?
                        WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor :
                        WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor;

                    var arg = new TypedConstant(compilation.GetWellKnownType(WellKnownType.System_Type), TypedConstantKind.Type, stateMachineType.GetUnboundGenericTypeOrSelf());

                    AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(ctor, ImmutableArray.Create(arg)));
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:24,代码来源:SourceMethodSymbol.cs

示例2: AddSynthesizedAttributes

        internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes)
        {
            base.AddSynthesizedAttributes(compilationState, ref attributes);

            if (this.IsAsync || this.IsIterator)
            {
                var compilation = this.DeclaringCompilation;

                // The async state machine type is not synthesized until the async method body is rewritten. If we are
                // only emitting metadata the method body will not have been rewritten, and the async state machine
                // type will not have been created. In this case, omit the attribute.
                NamedTypeSymbol stateMachineType;
                if (compilationState.TryGetStateMachineType(this, out stateMachineType))
                {
                    WellKnownMember ctor = this.IsAsync ?
                        WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor :
                        WellKnownMember.System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor;

                    var arg = new TypedConstant(compilation.GetWellKnownType(WellKnownType.System_Type), TypedConstantKind.Type, stateMachineType.GetUnboundGenericTypeOrSelf());

                    AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(ctor, ImmutableArray.Create(arg)));
                }

                if (this.IsAsync)
                {
                    // Async kick-off method calls MoveNext, which contains user code. 
                    // This means we need to emit DebuggerStepThroughAttribute in order
                    // to have correct stepping behavior during debugging.
                    AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDebuggerStepThroughAttribute());
                }
            }
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:32,代码来源:SourceMethodSymbol.cs

示例3: AddSynthesizedAttributes

        internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes)
        {
            base.AddSynthesizedAttributes(compilationState, ref attributes);

            if (this.IsAsync)
            {
                var compilation = this.DeclaringCompilation;

                AddSynthesizedAttribute(ref attributes, compilation.SynthesizeAttribute(
                    WellKnownMember.System_Diagnostics_DebuggerStepThroughAttribute__ctor));

                // The async state machine type is not synthesized until the async method body is rewritten. If we are
                // only emitting metadata the method body will not have been rewritten, and the async state machine
                // type will not have been created. In this case, omit the AsyncStateMachineAttribute.
                NamedTypeSymbol asyncStateMachineType;
                if (compilationState.TryGetStateMachineType(this, out asyncStateMachineType))
                {
                    AddSynthesizedAttribute(ref attributes, compilation.SynthesizeAttribute(
                       WellKnownMember.System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor,
                       ImmutableArray.Create(
                           new TypedConstant(
                               compilation.GetWellKnownType(WellKnownType.System_Type),
                               TypedConstantKind.Type,
                               asyncStateMachineType.ConstructUnboundGenericType()))));   
                }
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:27,代码来源:SourceMethodSymbol.cs


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