本文整理汇总了C#中Binder.WithUnsafeRegionIfNecessary方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.WithUnsafeRegionIfNecessary方法的具体用法?C# Binder.WithUnsafeRegionIfNecessary怎么用?C# Binder.WithUnsafeRegionIfNecessary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binder
的用法示例。
在下文中一共展示了Binder.WithUnsafeRegionIfNecessary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SourcePropertySymbol
// CONSIDER: if the parameters were computed lazily, ParameterCount could be overridden to fall back on the syntax (as in SourceMemberMethodSymbol).
private SourcePropertySymbol(
SourceMemberContainerTypeSymbol containingType,
Binder bodyBinder,
BasePropertyDeclarationSyntax syntax,
string name,
Location location,
DiagnosticBag diagnostics)
{
// This has the value that IsIndexer will ultimately have, once we've populated the fields of this object.
bool isIndexer = syntax.Kind() == SyntaxKind.IndexerDeclaration;
var interfaceSpecifier = GetExplicitInterfaceSpecifier(syntax);
bool isExplicitInterfaceImplementation = (interfaceSpecifier != null);
_location = location;
_containingType = containingType;
_syntaxRef = syntax.GetReference();
SyntaxTokenList modifiers = syntax.Modifiers;
bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers);
bodyBinder = bodyBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.SuppressConstraintChecks, this);
bool modifierErrors;
_modifiers = MakeModifiers(modifiers, isExplicitInterfaceImplementation, isIndexer, location, diagnostics, out modifierErrors);
this.CheckAccessibility(location, diagnostics);
this.CheckModifiers(location, isIndexer, diagnostics);
if (isIndexer && !isExplicitInterfaceImplementation)
{
// Evaluate the attributes immediately in case the IndexerNameAttribute has been applied.
// NOTE: we want IsExplicitInterfaceImplementation, IsOverride, Locations, and the syntax reference
// to be initialized before we pass this symbol to LoadCustomAttributes.
// CONSIDER: none of the information from this early binding pass is cached. Everything will
// be re-bound when someone calls GetAttributes. If this gets to be a problem, we could
// always use the real attribute bag of this symbol and modify LoadAndValidateAttributes to
// handle partially filled bags.
CustomAttributesBag<CSharpAttributeData> temp = null;
LoadAndValidateAttributes(OneOrMany.Create(this.CSharpSyntaxNode.AttributeLists), ref temp, earlyDecodingOnly: true);
if (temp != null)
{
Debug.Assert(temp.IsEarlyDecodedWellKnownAttributeDataComputed);
var propertyData = (PropertyEarlyWellKnownAttributeData)temp.EarlyDecodedWellKnownAttributeData;
if (propertyData != null)
{
_sourceName = propertyData.IndexerName;
}
}
}
string aliasQualifierOpt;
string memberName = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(bodyBinder, interfaceSpecifier, name, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt);
_sourceName = _sourceName ?? memberName; //sourceName may have been set while loading attributes
_name = isIndexer ? ExplicitInterfaceHelpers.GetMemberName(WellKnownMemberNames.Indexer, _explicitInterfaceType, aliasQualifierOpt) : _sourceName;
_isExpressionBodied = false;
bool hasAccessorList = syntax.AccessorList != null;
var propertySyntax = syntax as PropertyDeclarationSyntax;
var arrowExpression = propertySyntax != null
? propertySyntax.ExpressionBody
: ((IndexerDeclarationSyntax)syntax).ExpressionBody;
bool hasExpressionBody = arrowExpression != null;
bool hasInitializer = !isIndexer && propertySyntax.Initializer != null;
bool notRegularProperty = (!IsAbstract && !IsExtern && !isIndexer && hasAccessorList);
AccessorDeclarationSyntax getSyntax = null;
AccessorDeclarationSyntax setSyntax = null;
if (hasAccessorList)
{
foreach (var accessor in syntax.AccessorList.Accessors)
{
if (accessor.Kind() == SyntaxKind.GetAccessorDeclaration &&
(getSyntax == null || getSyntax.Keyword.Span.IsEmpty))
{
getSyntax = accessor;
}
else if (accessor.Kind() == SyntaxKind.SetAccessorDeclaration &&
(setSyntax == null || setSyntax.Keyword.Span.IsEmpty))
{
setSyntax = accessor;
}
else
{
continue;
}
if (accessor.Body != null)
{
notRegularProperty = false;
}
}
}
else
{
notRegularProperty = false;
}
if (hasInitializer)
//.........这里部分代码省略.........
示例2: SourceMemberMethodSymbol
private SourceMemberMethodSymbol(
NamedTypeSymbol containingType,
TypeSymbol explicitInterfaceType,
string name,
Location location,
Binder bodyBinder,
MethodDeclarationSyntax syntax,
MethodKind methodKind,
DiagnosticBag diagnostics) :
base(containingType,
syntax.GetReference(),
// Prefer a block body if both exist
syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(),
location)
{
_name = name;
_explicitInterfaceType = explicitInterfaceType;
SyntaxTokenList modifiers = syntax.Modifiers;
// The following two values are used to compute and store the initial value of the flags
// However, these two components are placeholders; the correct value will be
// computed lazily later and then the flags will be fixed up.
const bool returnsVoid = false;
var firstParam = syntax.ParameterList.Parameters.FirstOrDefault();
bool isExtensionMethod = firstParam != null &&
!firstParam.IsArgList &&
firstParam.Modifiers.Any(SyntaxKind.ThisKeyword);
bool modifierErrors;
var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors);
var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual
this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers);
// NOTE: by creating a WithMethodTypeParametersBinder, we are effectively duplicating the
// functionality of the BinderFactory. Unfortunately, we cannot use the BinderFactory
// because it depends on having access to the member list of our containing type and
// that list cannot be complete because we're not finished constructing this member.
// TODO: at least keep this in sync with BinderFactory.VisitMethodDeclaration.
bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers);
Binder withTypeParamsBinder;
if (syntax.Arity == 0)
{
withTypeParamsBinder = bodyBinder;
_typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
var parameterBinder = new WithMethodTypeParametersBinder(this, bodyBinder);
withTypeParamsBinder = parameterBinder;
_typeParameters = MakeTypeParameters(syntax, diagnostics);
}
bool hasBlockBody = syntax.Body != null;
_isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null;
if (hasBlockBody || _isExpressionBodied)
{
CheckModifiersForBody(location, diagnostics);
}
var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers);
if (info != null)
{
diagnostics.Add(info, location);
}
if (this.IsPartial)
{
// Partial methods must be completed early because they are matched up
// by signature while producing the enclosing type's member list. However,
// that means any type parameter constraints will be bound before the method
// is added to the containing type. To enable binding of constraints before the
// .ctor completes we hold on to the current binder while the .ctor is executing.
// If we change the handling of partial methods, so that partial methods are
// completed lazily, the 'constraintClauseBinder' field should be removed.
_constraintClauseBinder = withTypeParamsBinder;
state.NotePartComplete(CompletionPart.StartMethodChecks);
MethodChecks(syntax, withTypeParamsBinder, diagnostics);
state.NotePartComplete(CompletionPart.FinishMethodChecks);
_constraintClauseBinder = null;
}
}