本文整理汇总了C#中NamespaceDeclaration.GetAliasNamed方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclaration.GetAliasNamed方法的具体用法?C# NamespaceDeclaration.GetAliasNamed怎么用?C# NamespaceDeclaration.GetAliasNamed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceDeclaration
的用法示例。
在下文中一共展示了NamespaceDeclaration.GetAliasNamed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveUsing
//^ ensures result == null || result is ITypeDefinition || result is INamespaceDefinition || result is ITypeGroup ||
//^ (!restrictToNamespacesAndTypes && result is INamespaceMember);
/// <summary>
/// Returns either null or the namespace member (group) that binds to this name.
/// This implementation of this method ignores global methods and variables, as is the case for C#. //TODO: is this really the case?
/// </summary>
/// <param name="namespaceDeclaration">The namespace to use to resolve this name.</param>
/// <param name="restrictToNamespacesAndTypes">True if only namespaces and types should be considered when resolving this name.</param>
/*?*/
protected override object ResolveUsing(NamespaceDeclaration namespaceDeclaration, bool restrictToNamespacesAndTypes)
{
// Overrides the SimpleName's corresponding method so that we can handle the scope encoding
// (the mangled C type names to encode scope information)
string lookupNameString = this.Name.Value;
// loop until we have tried every parent scope
while (true) {
IScope<INamespaceMember> scope = namespaceDeclaration.UnitNamespace;
IName lookupName = this.NameTable.GetNameFor(lookupNameString);
AliasDeclaration/*?*/ aliasDeclaration = null;
UnitSetAliasDeclaration/*?*/ unitSetAliasDeclaration = null;
if (!this.NamespaceDeclIsBusy(namespaceDeclaration))
namespaceDeclaration.GetAliasNamed(lookupName, this.IgnoreCase, ref aliasDeclaration, ref unitSetAliasDeclaration);
IEnumerable<INamespaceMember> members = scope.GetMembersNamed(lookupName, this.IgnoreCase);
INamespaceTypeDefinition/*?*/ namespaceTypeDefinition = null;
INamespaceDefinition/*?*/ nestedNamespaceDefinition = null;
foreach (INamespaceMember member in members) {
nestedNamespaceDefinition = member as INamespaceDefinition;
if (nestedNamespaceDefinition != null) {
//TODO: if aliasDeclaration != null give an ambiguous reference error
return nestedNamespaceDefinition;
}
if (namespaceTypeDefinition == null) {
namespaceTypeDefinition = member as INamespaceTypeDefinition;
if (namespaceTypeDefinition != null && (aliasDeclaration == null || namespaceTypeDefinition.IsGeneric)) break;
//carry on in case there is a generic type with this name. If not there is an ambiguity between the type and the alias.
}
}
if (namespaceTypeDefinition != null) {
//TODO: if aliasDeclaration != null give an ambiguous reference error if namespaceTypeDef is not generic
if (this.Name.Value == lookupNameString) {
return new NamespaceTypeGroup(this, scope, this);
}
VccSimpleName newSimpleName = new VccSimpleName(lookupName, this.sourceLocation);
newSimpleName.SetContainingBlock(this.ContainingBlock);
return new NamespaceTypeGroup(this, scope, newSimpleName);
}
if (this.NamespaceDeclIsBusy(namespaceDeclaration)) {
//Have to ignore using statements.
scope = namespaceDeclaration.UnitSetNamespace;
members = scope.GetMembersNamed(lookupName, this.IgnoreCase);
} else {
if (aliasDeclaration != null) return aliasDeclaration.ResolvedNamespaceOrType;
if (unitSetAliasDeclaration != null) {
IUnitSetNamespace usns = unitSetAliasDeclaration.UnitSet.UnitSetNamespaceRoot;
//^ assume usns is INamespaceDefinition; //IUnitSetNamespace : INamespaceDefinition
return usns;
}
scope = namespaceDeclaration.Scope;
members = scope.GetMembersNamed(lookupName, this.IgnoreCase); //Considers types that were imported into the namespace via using statements
}
foreach (INamespaceMember member in members) {
if (nestedNamespaceDefinition == null) nestedNamespaceDefinition = member as INamespaceDefinition;
namespaceTypeDefinition = member as INamespaceTypeDefinition;
if (namespaceTypeDefinition != null) return new NamespaceTypeGroup(this, scope, this);
}
if (nestedNamespaceDefinition != null) return nestedNamespaceDefinition;
// Test to see if we have reached the outermost scope, in which case lookupNameString
// is not a mangled one.
if (!lookupNameString.Contains("^")) break;
lookupNameString = LexicalScope.LexicalScopeOf(lookupNameString) == "" ? LexicalScope.UnmangledName(lookupNameString) : LexicalScope.MangledNameWithOuterLexcialScope(lookupNameString);
}
// The following (looking the name up in the nested namespace)
// may not apply to the C case. Keep it here anyway.
NestedNamespaceDeclaration/*?*/ nestedNamespace = namespaceDeclaration as NestedNamespaceDeclaration;
if (nestedNamespace != null) return this.ResolveUsing(nestedNamespace.ContainingNamespaceDeclaration, restrictToNamespacesAndTypes);
return null;
}