internal MetadataMember ResolveUnqualifiedName(string name, bool partOfQualifiedName, ErrorContext errCtx) { DebugCheck.NotEmpty(name); // // In the case of Name1.Name2...NameN and if backward compatibility mode is on, then resolve Name1 as namespace only, ignore any other possible resolutions. // var resolveAsNamespaceOnly = partOfQualifiedName && _resolveLeftMostUnqualifiedNameAsNamespaceOnly; // // In the case of Name1.Name2...NameN, ignore functions while resolving Name1: functions don't have members. // var includeFunctions = !partOfQualifiedName; // // Try resolving as an inline function. // InlineFunctionGroup inlineFunctionGroup; if (!resolveAsNamespaceOnly && includeFunctions && TryGetInlineFunction(name, out inlineFunctionGroup)) { return(inlineFunctionGroup); } // // Try resolving as a namespace alias. // MetadataNamespace aliasedNamespaceImport; if (_aliasedNamespaces.TryGetValue(name, out aliasedNamespaceImport)) { return(aliasedNamespaceImport); } if (!resolveAsNamespaceOnly) { // // Try resolving as a type or functionGroup in the global namespace or as an imported member. // Throw if ambiguous. // MetadataType type = null; MetadataFunctionGroup functionGroup = null; if (!TryGetTypeFromMetadata(name, out type)) { if (includeFunctions) { // // If name looks like a multipart identifier, try resolving it in the global namespace. // Escaped multipart identifiers usually appear in views: select [NS1.NS2.Product](...) from ... // var multipart = name.Split('.'); if (multipart.Length > 1 && multipart.All(p => p.Length > 0)) { var functionName = multipart[multipart.Length - 1]; var namespaceName = name.Substring(0, name.Length - functionName.Length - 1); TryGetFunctionFromMetadata(namespaceName, functionName, out functionGroup); } } } // // Try resolving as an imported member. // MetadataNamespace importedMemberNamespace = null; foreach (var namespaceImport in _namespaces) { var fullName = GetFullName(namespaceImport.Name, name); MetadataType importedType; if (TryGetTypeFromMetadata(fullName, out importedType)) { if (type == null && functionGroup == null) { type = importedType; importedMemberNamespace = namespaceImport; } else { throw AmbiguousMetadataMemberName(errCtx, name, namespaceImport, importedMemberNamespace); } } MetadataFunctionGroup importedFunctionGroup; if (includeFunctions && TryGetFunctionFromMetadata(namespaceImport.Name, name, out importedFunctionGroup)) { if (type == null && functionGroup == null) { functionGroup = importedFunctionGroup; importedMemberNamespace = namespaceImport; } else { throw AmbiguousMetadataMemberName(errCtx, name, namespaceImport, importedMemberNamespace); } } } if (type != null) { return(type); } if (functionGroup != null) { return(functionGroup); } } // // Otherwise, resolve as a namespace. // return(new MetadataNamespace(name)); }
internal MetadataMember ResolveUnqualifiedName( string name, bool partOfQualifiedName, ErrorContext errCtx) { bool flag1 = partOfQualifiedName && this._resolveLeftMostUnqualifiedNameAsNamespaceOnly; bool flag2 = !partOfQualifiedName; InlineFunctionGroup inlineFunctionGroup; if (!flag1 && flag2 && this.TryGetInlineFunction(name, out inlineFunctionGroup)) { return((MetadataMember)inlineFunctionGroup); } MetadataNamespace metadataNamespace; if (this._aliasedNamespaces.TryGetValue(name, out metadataNamespace)) { return((MetadataMember)metadataNamespace); } if (!flag1) { MetadataType type1 = (MetadataType)null; MetadataFunctionGroup functionGroup1 = (MetadataFunctionGroup)null; if (!this.TryGetTypeFromMetadata(name, out type1) && flag2) { string[] strArray = name.Split('.'); if (strArray.Length > 1 && ((IEnumerable <string>)strArray).All <string>((Func <string, bool>)(p => p.Length > 0))) { string functionName = strArray[strArray.Length - 1]; this.TryGetFunctionFromMetadata(name.Substring(0, name.Length - functionName.Length - 1), functionName, out functionGroup1); } } MetadataNamespace ns2 = (MetadataNamespace)null; foreach (MetadataNamespace ns1 in this._namespaces) { MetadataType type2; if (this.TryGetTypeFromMetadata(TypeResolver.GetFullName(ns1.Name, name), out type2)) { if (type1 != null || functionGroup1 != null) { throw TypeResolver.AmbiguousMetadataMemberName(errCtx, name, ns1, ns2); } type1 = type2; ns2 = ns1; } MetadataFunctionGroup functionGroup2; if (flag2 && this.TryGetFunctionFromMetadata(ns1.Name, name, out functionGroup2)) { if (type1 != null || functionGroup1 != null) { throw TypeResolver.AmbiguousMetadataMemberName(errCtx, name, ns1, ns2); } functionGroup1 = functionGroup2; ns2 = ns1; } } if (type1 != null) { return((MetadataMember)type1); } if (functionGroup1 != null) { return((MetadataMember)functionGroup1); } } return((MetadataMember) new MetadataNamespace(name)); }