Exemple #1
0
        /// <summary>
        /// Initializes TypeResolver instance
        /// </summary>
        internal TypeResolver(Perspective perspective, ParserOptions parserOptions)
        {
            EntityUtil.CheckArgumentNull(perspective, "perspective");

            _perspective            = perspective;
            _parserOptions          = parserOptions;
            _aliasedNamespaces      = new Dictionary <string, MetadataNamespace>(parserOptions.NameComparer);
            _namespaces             = new HashSet <MetadataNamespace>(MetadataMember.CreateMetadataMemberNameEqualityComparer(parserOptions.NameComparer));
            _functionDefinitions    = new Dictionary <string, List <InlineFunctionInfo> >(parserOptions.NameComparer);
            _includeInlineFunctions = true;
            _resolveLeftMostUnqualifiedNameAsNamespaceOnly = false;
        }
Exemple #2
0
        internal MetadataMember ResolveMetadataMemberAccess(MetadataMember qualifier, string name, ErrorContext errCtx)
        {
            string fullName = GetFullName(qualifier.Name, name);

            if (qualifier.MetadataMemberClass == MetadataMemberClass.Namespace)
            {
                //
                // Try resolving as a type.
                //
                MetadataType type;
                if (TryGetTypeFromMetadata(fullName, out type))
                {
                    return(type);
                }

                //
                // Try resolving as a function.
                //
                MetadataFunctionGroup function;
                if (TryGetFunctionFromMetadata(qualifier.Name, name, out function))
                {
                    return(function);
                }

                //
                // Otherwise, resolve as a namespace.
                //
                return(new MetadataNamespace(fullName));
            }
            else if (qualifier.MetadataMemberClass == MetadataMemberClass.Type)
            {
                var type = (MetadataType)qualifier;
                if (TypeSemantics.IsEnumerationType(type.TypeUsage))
                {
                    EnumMember member;
                    if (_perspective.TryGetEnumMember((EnumType)type.TypeUsage.EdmType, name, _parserOptions.NameComparisonCaseInsensitive /*ignoreCase*/, out member))
                    {
                        Debug.Assert(member != null, "member != null");
                        Debug.Assert(_parserOptions.NameComparer.Equals(name, member.Name), "_parserOptions.NameComparer.Equals(name, member.Name)");
                        return(new MetadataEnumMember(fullName, type.TypeUsage, member));
                    }
                    else
                    {
                        throw EntityUtil.EntitySqlError(errCtx, Strings.NotAMemberOfType(name, qualifier.Name));
                    }
                }
            }

            throw EntityUtil.EntitySqlError(errCtx, Strings.InvalidMetadataMemberClassResolution(
                                                qualifier.Name, qualifier.MetadataMemberClassName, MetadataNamespace.NamespaceClassName));
        }