本文整理汇总了C#中LookupOptions.ThrowIfInvalid方法的典型用法代码示例。如果您正苦于以下问题:C# LookupOptions.ThrowIfInvalid方法的具体用法?C# LookupOptions.ThrowIfInvalid怎么用?C# LookupOptions.ThrowIfInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LookupOptions
的用法示例。
在下文中一共展示了LookupOptions.ThrowIfInvalid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LookupSymbolsInternal
/// <summary>
/// Gets the available named symbols in the context of the specified location and optional
/// container. Only symbols that are accessible and visible from the given location are
/// returned.
/// </summary>
/// <param name="position">The character position for determining the enclosing declaration
/// scope and accessibility.</param>
/// <param name="container">The container to search for symbols within. If null then the
/// enclosing declaration scope around position is used.</param>
/// <param name="name">The name of the symbol to find. If null is specified then symbols
/// with any names are returned.</param>
/// <param name="options">Additional options that affect the lookup process.</param>
/// <param name="useBaseReferenceAccessibility">Ignore 'throughType' in accessibility checking.
/// Used in checking accessibility of symbols accessed via 'MyBase' or 'base'.</param>
/// <remarks>
/// The "position" is used to determine what variables are visible and accessible. Even if
/// "container" is specified, the "position" location is significant for determining which
/// members of "containing" are accessible.
/// </remarks>
/// <exception cref="ArgumentException">Throws an argument exception if the passed lookup options are invalid.</exception>
private ImmutableArray<Symbol> LookupSymbolsInternal(
int position,
NamespaceOrTypeSymbol container,
string name,
LookupOptions options,
bool useBaseReferenceAccessibility)
{
Debug.Assert((options & LookupOptions.UseBaseReferenceAccessibility) == 0, "Use the useBaseReferenceAccessibility parameter.");
if (useBaseReferenceAccessibility)
{
options |= LookupOptions.UseBaseReferenceAccessibility;
}
Debug.Assert(!options.IsAttributeTypeLookup()); // Not exposed publicly.
options.ThrowIfInvalid();
SyntaxToken token;
position = CheckAndAdjustPosition(position, out token);
if ((object)container == null || container.Kind == SymbolKind.Namespace)
{
options &= ~LookupOptions.IncludeExtensionMethods;
}
var binder = GetEnclosingBinder(position);
if (binder == null)
{
return ImmutableArray<Symbol>.Empty;
}
if (useBaseReferenceAccessibility)
{
Debug.Assert((object)container == null);
TypeSymbol containingType = binder.ContainingType;
TypeSymbol baseType = null;
// For a script class or a submission class base should have no members.
if ((object)containingType != null && containingType.Kind == SymbolKind.NamedType && ((NamedTypeSymbol)containingType).IsScriptClass)
{
return ImmutableArray<Symbol>.Empty;
}
if ((object)containingType == null || (object)(baseType = containingType.BaseTypeNoUseSiteDiagnostics) == null)
{
throw new ArgumentException(
"Not a valid position for a call to LookupBaseMembers (must be in a type with a base type)",
nameof(position));
}
container = baseType;
}
if (!binder.IsInMethodBody &&
(options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) == 0)
{
// Method type parameters are not in scope outside a method
// body unless the position is either:
// a) in a type-only context inside an expression, or
// b) inside of an XML name attribute in an XML doc comment.
var parentExpr = token.Parent as ExpressionSyntax;
if (parentExpr != null && !(parentExpr.Parent is XmlNameAttributeSyntax) && !SyntaxFacts.IsInTypeOnlyContext(parentExpr))
{
options |= LookupOptions.MustNotBeMethodTypeParameter;
}
}
var info = LookupSymbolsInfo.GetInstance();
if ((object)container == null)
{
binder.AddLookupSymbolsInfo(info, options);
}
else
{
binder.AddMemberLookupSymbolsInfo(info, container, options, binder);
}
var results = ArrayBuilder<Symbol>.GetInstance(info.Count);
if (name == null)
{
//.........这里部分代码省略.........