本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetWellKnownTypeMember方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.GetWellKnownTypeMember方法的具体用法?C# CSharpCompilation.GetWellKnownTypeMember怎么用?C# CSharpCompilation.GetWellKnownTypeMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.GetWellKnownTypeMember方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConstructedCompareExchangeMethod
/// <summary>
/// Get the MethodSymbol for System.Threading.Interlocked.CompareExchange<T> for a given T.
/// </summary>
private static MethodSymbol GetConstructedCompareExchangeMethod(TypeSymbol typeArg, CSharpCompilation compilation, Location errorLocation, DiagnosticBag diagnostics)
{
MethodSymbol compareExchangeDefinition = (MethodSymbol)compilation.GetWellKnownTypeMember(WellKnownMember.System_Threading_Interlocked__CompareExchange_T);
if ((object)compareExchangeDefinition == null)
{
MemberDescriptor memberDescriptor = WellKnownMembers.GetDescriptor(WellKnownMember.System_Threading_Interlocked__CompareExchange_T);
WellKnownType containingType = (WellKnownType)memberDescriptor.DeclaringTypeId;
diagnostics.Add(ErrorCode.ERR_MissingPredefinedMember, errorLocation, containingType.GetMetadataName(), memberDescriptor.Name);
return null;
}
return compareExchangeDefinition.Construct(ImmutableArray.Create<TypeSymbol>(typeArg));
}
示例2: MakeSubmissionInitialization
/// <summary>
/// Generates a submission initialization part of a Script type constructor that represents an interactive submission.
/// </summary>
/// <remarks>
/// The constructor takes a parameter of type Roslyn.Scripting.Session - the session reference.
/// It adds the object being constructed into the session by calling Microsoft.CSharp.RuntimeHelpers.SessionHelpers.SetSubmission,
/// and retrieves strongly typed references on all previous submission script classes whose members are referenced by this submission.
/// The references are stored to fields of the submission (<paramref name="synthesizedFields"/>).
/// </remarks>
private static ImmutableArray<BoundStatement> MakeSubmissionInitialization(CSharpSyntaxNode syntax, MethodSymbol submissionConstructor, SynthesizedSubmissionFields synthesizedFields, CSharpCompilation compilation)
{
Debug.Assert(submissionConstructor.ParameterCount == 2);
BoundStatement[] result = new BoundStatement[1 + synthesizedFields.Count];
var sessionReference = new BoundParameter(syntax, submissionConstructor.Parameters[0]) { WasCompilerGenerated = true };
var submissionGetter = (MethodSymbol)compilation.GetWellKnownTypeMember(
WellKnownMember.Microsoft_CSharp_RuntimeHelpers_SessionHelpers__GetSubmission
);
var submissionAdder = (MethodSymbol)compilation.GetWellKnownTypeMember(
WellKnownMember.Microsoft_CSharp_RuntimeHelpers_SessionHelpers__SetSubmission
);
// TODO: report missing adder/getter
Debug.Assert((object)submissionAdder != null && (object)submissionGetter != null);
var intType = compilation.GetSpecialType(SpecialType.System_Int32);
var thisReference = new BoundThisReference(syntax, submissionConstructor.ContainingType) { WasCompilerGenerated = true };
int i = 0;
// hostObject = (THostObject)SessionHelpers.SetSubmission(<session>, <slot index>, this);
var slotIndex = compilation.GetSubmissionSlotIndex();
Debug.Assert(slotIndex >= 0);
BoundExpression setSubmission = BoundCall.Synthesized(syntax,
null,
submissionAdder,
sessionReference,
new BoundLiteral(syntax, ConstantValue.Create(slotIndex), intType) { WasCompilerGenerated = true },
thisReference
);
var hostObjectField = synthesizedFields.GetHostObjectField();
if ((object)hostObjectField != null)
{
setSubmission = new BoundAssignmentOperator(syntax,
new BoundFieldAccess(syntax, thisReference, hostObjectField, ConstantValue.NotAvailable) { WasCompilerGenerated = true },
BoundConversion.Synthesized(syntax,
setSubmission,
Conversion.ExplicitReference,
false,
true,
ConstantValue.NotAvailable,
hostObjectField.Type
),
hostObjectField.Type
)
{ WasCompilerGenerated = true };
}
result[i++] = new BoundExpressionStatement(syntax, setSubmission) { WasCompilerGenerated = true };
foreach (var field in synthesizedFields.FieldSymbols)
{
var targetScriptClass = (ImplicitNamedTypeSymbol)field.Type;
var targetSubmissionId = targetScriptClass.DeclaringCompilation.GetSubmissionSlotIndex();
Debug.Assert(targetSubmissionId >= 0);
// this.<field> = (<FieldType>)SessionHelpers.GetSubmission(<session>, <i>);
result[i++] =
new BoundExpressionStatement(syntax,
new BoundAssignmentOperator(syntax,
new BoundFieldAccess(syntax, thisReference, field, ConstantValue.NotAvailable) { WasCompilerGenerated = true },
BoundConversion.Synthesized(syntax,
BoundCall.Synthesized(syntax,
null,
submissionGetter,
sessionReference,
new BoundLiteral(syntax, ConstantValue.Create(targetSubmissionId), intType) { WasCompilerGenerated = true }),
Conversion.ExplicitReference,
false,
true,
ConstantValue.NotAvailable,
targetScriptClass
),
targetScriptClass
)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
}
Debug.Assert(i == result.Length);
return result.AsImmutableOrNull();
}
示例3: 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);
///
/// Note, if System.Threading.Interlocked.CompareExchange<T> is not available,
/// we emit the following code and mark the method Synchronized (unless it is a struct).
///
/// _event = (DelegateType)Delegate.Combine(_event, value); //Remove for -=
///
/// </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);
SpecialMember updateMethodId = isAddMethod ? SpecialMember.System_Delegate__Combine : SpecialMember.System_Delegate__Remove;
MethodSymbol updateMethod = (MethodSymbol)compilation.GetSpecialTypeMember(updateMethodId);
BoundStatement @return = new BoundReturnStatement(syntax,
expressionOpt: null)
{ WasCompilerGenerated = true };
if (updateMethod == null)
{
MemberDescriptor memberDescriptor = SpecialMembers.GetDescriptor(updateMethodId);
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_MissingPredefinedMember,
memberDescriptor.DeclaringTypeMetadataName,
memberDescriptor.Name),
syntax.Location));
return BoundBlock.SynthesizedNoLocals(syntax, @return);
}
Binder.ReportUseSiteDiagnostics(updateMethod, diagnostics, syntax);
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 };
BoundExpression delegateUpdate;
MethodSymbol compareExchangeMethod = (MethodSymbol)compilation.GetWellKnownTypeMember(WellKnownMember.System_Threading_Interlocked__CompareExchange_T);
if ((object)compareExchangeMethod == null)
{
// (DelegateType)Delegate.Combine(_event, value)
delegateUpdate = BoundConversion.SynthesizedNonUserDefined(syntax,
operand: BoundCall.Synthesized(syntax,
receiverOpt: null,
method: updateMethod,
arguments: ImmutableArray.Create<BoundExpression>(boundBackingField, boundParameter)),
kind: ConversionKind.ExplicitReference,
type: delegateType);
// _event = (DelegateType)Delegate.Combine(_event, value);
BoundStatement eventUpdate = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundBackingField,
right: delegateUpdate,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
return BoundBlock.SynthesizedNoLocals(syntax,
statements: ImmutableArray.Create<BoundStatement>(
eventUpdate,
@return));
}
compareExchangeMethod = compareExchangeMethod.Construct(ImmutableArray.Create<TypeSymbol>(delegateType));
Binder.ReportUseSiteDiagnostics(compareExchangeMethod, diagnostics, syntax);
GeneratedLabelSymbol loopLabel = new GeneratedLabelSymbol("loop");
const int numTemps = 3;
//.........这里部分代码省略.........