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))); } } }
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()); } } }
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())))); } } }