Beispiel #1
0
        private LogicalType GetTypeInternal(TypeAndNamespace typeAndNamespace, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin)
        {
            Dictionary <TypeAndNamespace, LogicalType> typeTable;

            lock (_lookUpLock)
            {
                typeTable = encoded ? _userEncodedTypesByType : _userLiteralTypesByType;

                if (0 != (originsToSearch & TypeOrigin.Intrinsic) && s_intrinsicsByType.ContainsKey(typeAndNamespace.Type))
                {
                    typeOrigin = TypeOrigin.Intrinsic;
                    return(s_intrinsicsByType[typeAndNamespace.Type]);
                }
                else if (0 != (originsToSearch & TypeOrigin.User) && typeTable.ContainsKey(typeAndNamespace))
                {
                    typeOrigin = TypeOrigin.User;
                    return(typeTable[typeAndNamespace]);
                }
                else
                {
                    typeOrigin = TypeOrigin.None;
                    return(null);
                }
            }
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            if (!(obj is TypeAndNamespace))
            {
                return(false);
            }
            TypeAndNamespace other = (TypeAndNamespace)obj;

            return(Type == other.Type && DefaultNamespace == other.DefaultNamespace);
        }
Beispiel #3
0
 private LogicalType GetType(TypeAndNamespace typeAndNamespace, bool encoded, TypeOrigin originsToSearch, out TypeOrigin typeOrigin)
 {
     // If a specific namespace is needed, check to see whether the type sought after is
     // a one-namespace-fits-all and has already been reflected.
     if (typeAndNamespace.DefaultNamespace != null)
     { // looking for a specific namespace
         // does a one-size-fits-all exist?
         LogicalType lType = GetTypeInternal(new TypeAndNamespace(typeAndNamespace.Type, null), encoded, originsToSearch, out typeOrigin);
         if (lType != null)
         {
             return(lType);
         }
     }
     // The sought for type either hasn't been reflected over, or must be prepared
     // for each namespace it appears in.  Search for the specific one and return result.
     return(GetTypeInternal(typeAndNamespace, encoded, originsToSearch, out typeOrigin));
 }
Beispiel #4
0
        /// <summary>
        /// Adds a LogicalType to the TypeContainer. The LogicalType is mapped by
        /// Framework Type, i.e FX Type => LogicalType, as well as by XmlQualifiedName,
        /// i.e (Name:Namespace) => LogicalType.
        /// </summary>
        public void AddType(LogicalType lType, string name, string ns, bool encoded)
        {
            Dictionary <TypeAndNamespace, LogicalType> typesByTypeTable;
            Dictionary <XmlQualifiedName, LogicalType> typesByNameTable;
            bool             allowTypeMapping, allowNameMapping;
            XmlQualifiedName typeQName;
            TypeAndNamespace typeAndNamespace;

            // Most type should avoid the null namespace, but some types (like XmlNode)
            // really don't have any need for a ns because they are inherently portable
            // by carrying all their namespace info with them.
            Debug.Assert(ns != null || lType.NamespaceIsPortable, "A non-portable type MUST specify a namespace.");

            lock (_lookUpLock)
            {
                if (encoded)
                {
                    typesByTypeTable = _userEncodedTypesByType;
                    typesByNameTable = _userEncodedTypesByQName;
                }
                else
                {
                    typesByTypeTable = _userLiteralTypesByType;
                    typesByNameTable = _userLiteralTypesByQName;
                }

                allowTypeMapping = (lType.MappingFlags & TypeMappingFlags.AllowTypeMapping) != 0;
                allowNameMapping = (lType.MappingFlags & TypeMappingFlags.AllowNameMapping) != 0;
                typeQName        = new XmlQualifiedName(name, ns);
                typeAndNamespace = new TypeAndNamespace(lType.Type, lType.NamespaceIsPortable ? null : ns);

                //if we're allowed to map the C# type to the LogicalType
                if (allowTypeMapping)
                {
                    // Don't add the type yet.  Verify that I can also add it to the type table before committing it.
                    if (typesByTypeTable.ContainsKey(typeAndNamespace))
                    {
                        Debug.WriteLine("Adding " + ns + ":" + lType.Type + " twice.");
                        throw new InvalidOperationException(SR.Format(SR.XmlS_TwoMappings_1, lType.Type));
                    }
                    // We should never have both a null namespace for a type in our table and a non-null namespace.
                    // We should EITHER have the type in our table at most once, with the null namespace;
                    //           OR we should have the type in our table any number of times, all with non-null namespaces.
                    Debug.Assert(!(typeAndNamespace.DefaultNamespace != null &&
                                   typesByTypeTable.ContainsKey(new TypeAndNamespace(typeAndNamespace.Type, null))));
                }

                //If we're allowed to map the qname to this LogicalType
                if (allowNameMapping)
                {
                    if (typesByNameTable.ContainsKey(typeQName))
                    {
                        Debug.WriteLine("Two types in " + lType.Namespace + ":" + lType.Name);
                        throw new InvalidOperationException(SR.Format(SR.XmlS_TwoMappings_1, typeQName));
                    }
                    typesByNameTable[typeQName] = lType;
                }

                if (allowTypeMapping)
                {
                    typesByTypeTable[typeAndNamespace] = lType;
                }

                if (encoded && !_userEncodedNamespaces.Contains(ns))
                {
                    _userEncodedNamespaces.Add(ns);
                }
            }
        }