本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetWellKnownType方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCompilation.GetWellKnownType方法的具体用法?C# CSharpCompilation.GetWellKnownType怎么用?C# CSharpCompilation.GetWellKnownType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.CSharpCompilation
的用法示例。
在下文中一共展示了CSharpCompilation.GetWellKnownType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsNonAgileFieldAccess
/// <remarks>
/// Based on OutputContext::IsNonAgileField.
/// </remarks>
internal static bool IsNonAgileFieldAccess(BoundFieldAccess fieldAccess, CSharpCompilation compilation)
{
// Warn if taking the address of a non-static field with a receiver other than this (possibly cast)
// and a type that descends from System.MarshalByRefObject.
if (IsInstanceFieldAccessWithNonThisReceiver(fieldAccess))
{
// NOTE: We're only trying to produce a warning, so there's no point in producing an
// error if the well-known type we need for the check is missing.
NamedTypeSymbol marshalByRefType = compilation.GetWellKnownType(WellKnownType.System_MarshalByRefObject);
TypeSymbol baseType = fieldAccess.FieldSymbol.ContainingType;
while ((object)baseType != null)
{
if (baseType == marshalByRefType)
{
return true;
}
// NOTE: We're only trying to produce a warning, so there's no point in producing a
// use site diagnostic if we can't walk up the base type hierarchy.
baseType = baseType.BaseTypeNoUseSiteDiagnostics;
}
}
return false;
}
示例2: SetScriptInitializerReturnType
private static void SetScriptInitializerReturnType(
CSharpCompilation compilation,
SynthesizedInteractiveInitializerMethod scriptInitializer,
ImmutableArray<ImmutableArray<FieldOrPropertyInitializer>> fieldInitializers,
DiagnosticBag diagnostics)
{
bool isAsync = scriptInitializer.IsSubmissionInitializer && fieldInitializers.Any(i => i.Any(ContainsAwaitsVisitor.ContainsAwait));
var resultType = scriptInitializer.ResultType;
TypeSymbol returnType;
if ((object)resultType == null)
{
Debug.Assert(!isAsync);
returnType = compilation.GetSpecialType(SpecialType.System_Void);
}
else if (!isAsync)
{
returnType = resultType;
}
else
{
var taskT = compilation.GetWellKnownType(WellKnownType.System_Threading_Tasks_Task_T);
var useSiteDiagnostic = taskT.GetUseSiteDiagnostic();
if (useSiteDiagnostic != null)
{
diagnostics.Add(useSiteDiagnostic, NoLocation.Singleton);
}
returnType = taskT.Construct(resultType);
}
scriptInitializer.SetReturnType(isAsync, returnType);
}