本文整理汇总了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)));
}
}
}
示例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());
}
}
}
示例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()))));
}
}
}