本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSpecialTypeMember方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.GetSpecialTypeMember方法的具体用法?C# CSharpCompilation.GetSpecialTypeMember怎么用?C# CSharpCompilation.GetSpecialTypeMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.GetSpecialTypeMember方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructFieldLikeEventAccessorBody_Regular
/// <summary>
/// Generate a thread-safe accessor for a regular field-like event.
///
/// DelegateType tmp0 = _event; //backing field
/// DelegateType tmp1;
/// DelegateType tmp2;
/// do {
/// tmp1 = tmp0;
/// tmp2 = (DelegateType)Delegate.Combine(tmp1, value); //Remove for -=
/// tmp0 = Interlocked.CompareExchange<DelegateType>(ref _event, tmp2, tmp1);
/// } while ((object)tmp0 != (object)tmp1);
/// </summary>
internal static BoundBlock ConstructFieldLikeEventAccessorBody_Regular(SourceEventSymbol eventSymbol, bool isAddMethod, CSharpCompilation compilation, DiagnosticBag diagnostics)
{
CSharpSyntaxNode syntax = eventSymbol.CSharpSyntaxNode;
TypeSymbol delegateType = eventSymbol.Type;
MethodSymbol accessor = isAddMethod ? eventSymbol.AddMethod : eventSymbol.RemoveMethod;
ParameterSymbol thisParameter = accessor.ThisParameter;
TypeSymbol boolType = compilation.GetSpecialType(SpecialType.System_Boolean);
MethodSymbol updateMethod = (MethodSymbol)compilation.GetSpecialTypeMember(isAddMethod ? SpecialMember.System_Delegate__Combine : SpecialMember.System_Delegate__Remove);
MethodSymbol compareExchangeMethod = GetConstructedCompareExchangeMethod(delegateType, compilation, accessor.Locations[0], diagnostics);
if ((object)compareExchangeMethod == null)
{
return new BoundBlock(syntax,
locals: ImmutableArray<LocalSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(
new BoundReturnStatement(syntax,
expressionOpt: null)
{ WasCompilerGenerated = true }))
{ WasCompilerGenerated = true };
}
GeneratedLabelSymbol loopLabel = new GeneratedLabelSymbol("loop");
const int numTemps = 3;
LocalSymbol[] tmps = new LocalSymbol[numTemps];
BoundLocal[] boundTmps = new BoundLocal[numTemps];
for (int i = 0; i < numTemps; i++)
{
tmps[i] = new SynthesizedLocal(accessor, delegateType, SynthesizedLocalKind.LoweringTemp);
boundTmps[i] = new BoundLocal(syntax, tmps[i], null, delegateType);
}
BoundThisReference fieldReceiver = eventSymbol.IsStatic ?
null :
new BoundThisReference(syntax, thisParameter.Type) { WasCompilerGenerated = true };
BoundFieldAccess boundBackingField = new BoundFieldAccess(syntax,
receiver: fieldReceiver,
fieldSymbol: eventSymbol.AssociatedField,
constantValueOpt: null)
{ WasCompilerGenerated = true };
BoundParameter boundParameter = new BoundParameter(syntax,
parameterSymbol: accessor.Parameters[0])
{ WasCompilerGenerated = true };
// tmp0 = _event;
BoundStatement tmp0Init = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[0],
right: boundBackingField,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// LOOP:
BoundStatement loopStart = new BoundLabelStatement(syntax,
label: loopLabel)
{ WasCompilerGenerated = true };
// tmp1 = tmp0;
BoundStatement tmp1Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[1],
right: boundTmps[0],
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// (DelegateType)Delegate.Combine(tmp1, value)
BoundExpression delegateUpdate = BoundConversion.SynthesizedNonUserDefined(syntax,
operand: BoundCall.Synthesized(syntax,
receiverOpt: null,
method: updateMethod,
arguments: ImmutableArray.Create<BoundExpression>(boundTmps[1], boundParameter)),
kind: ConversionKind.ExplicitReference,
type: delegateType);
// tmp2 = (DelegateType)Delegate.Combine(tmp1, value);
BoundStatement tmp2Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[2],
right: delegateUpdate,
type: delegateType)
//.........这里部分代码省略.........