private List <Type> GetKnownTypesFromContext(XmlObjectSerializerContext context, IList <Type> serializerKnownTypeList)
        {
            List <Type> knownTypesList = new List <Type>();

            if (context != null)
            {
                List <XmlQualifiedName> stableNames = new List <XmlQualifiedName>();
                Dictionary <XmlQualifiedName, DataContract>[] entries = context.scopedKnownTypes.dataContractDictionaries;
                if (entries != null)
                {
                    for (int i = 0; i < entries.Length; i++)
                    {
                        Dictionary <XmlQualifiedName, DataContract> entry = entries[i];
                        if (entry != null)
                        {
                            foreach (KeyValuePair <XmlQualifiedName, DataContract> pair in entry)
                            {
                                if (!stableNames.Contains(pair.Key))
                                {
                                    stableNames.Add(pair.Key);
                                    knownTypesList.Add(pair.Value.UnderlyingType);
                                }
                            }
                        }
                    }
                }
                if (serializerKnownTypeList != null)
                {
                    knownTypesList.AddRange(serializerKnownTypeList);
                }
            }
            return(knownTypesList);
        }
Пример #2
0
 protected void PushKnownDataContracts(XmlObjectSerializerContext context)
 {
     if (KnownDataContracts != null)
     {
         context.scopedKnownTypes.Push(KnownDataContracts);
     }
 }
Пример #3
0
 private List<Type> GetKnownTypesFromContext(XmlObjectSerializerContext context, IList<Type> serializerKnownTypeList)
 {
     List<Type> knownTypesList = new List<Type>();
     if (context != null)
     {
         List<XmlQualifiedName> stableNames = new List<XmlQualifiedName>();
         Dictionary<XmlQualifiedName, DataContract>[] entries = context.scopedKnownTypes.dataContractDictionaries;
         if (entries != null)
         {
             for (int i = 0; i < entries.Length; i++)
             {
                 Dictionary<XmlQualifiedName, DataContract> entry = entries[i];
                 if (entry != null)
                 {
                     foreach (KeyValuePair<XmlQualifiedName, DataContract> pair in entry)
                     {
                         if (!stableNames.Contains(pair.Key))
                         {
                             stableNames.Add(pair.Key);
                             knownTypesList.Add(pair.Value.UnderlyingType);
                         }
                     }
                 }
             }
         }
         if (serializerKnownTypeList != null)
         {
             knownTypesList.AddRange(serializerKnownTypeList);
         }
     }
     return knownTypesList;
 }
Пример #4
0
        internal static DataContract?ResolveJsonDataContractFromRootDataContract(XmlObjectSerializerContext context, XmlQualifiedName typeQName, DataContract rootTypeDataContract)
        {
            if (rootTypeDataContract.StableName == typeQName)
            {
                return(rootTypeDataContract);
            }

            CollectionDataContract?collectionContract = rootTypeDataContract as CollectionDataContract;

            while (collectionContract != null)
            {
                DataContract itemContract;
                if (collectionContract.ItemType.IsGenericType &&
                    collectionContract.ItemType.GetGenericTypeDefinition() == typeof(KeyValue <,>))
                {
                    itemContract = context.GetDataContract(Globals.TypeOfKeyValuePair.MakeGenericType(collectionContract.ItemType.GetGenericArguments()));
                }
                else
                {
                    itemContract = context.GetDataContract(context.GetSurrogatedType(collectionContract.ItemType));
                }
                if (itemContract.StableName == typeQName)
                {
                    return(itemContract);
                }
                collectionContract = itemContract as CollectionDataContract;
            }
            return(null);
        }
Пример #5
0
 protected void PopKnownDataContracts(XmlObjectSerializerContext context)
 {
     if (this.KnownDataContracts != null)
     {
         context.scopedKnownTypes.Pop();
     }
 }
        internal static DataContract ResolveJsonDataContractFromRootDataContract(XmlObjectSerializerContext context, XmlQualifiedName typeQName, DataContract rootTypeDataContract)
        {
            if (rootTypeDataContract.StableName == typeQName)
                return rootTypeDataContract;

            CollectionDataContract collectionContract = rootTypeDataContract as CollectionDataContract;
            while (collectionContract != null)
            {
                DataContract itemContract;
                if (collectionContract.ItemType.IsGenericType
                    && collectionContract.ItemType.GetGenericTypeDefinition() == typeof(KeyValue<,>))
                {
                    itemContract = context.GetDataContract(Globals.TypeOfKeyValuePair.MakeGenericType(collectionContract.ItemType.GetGenericArguments()));
                }
                else
                {
                    itemContract = context.GetDataContract(context.GetSurrogatedType(collectionContract.ItemType));
                }
                if (itemContract.StableName == typeQName)
                {
                    return itemContract;
                }
                collectionContract = itemContract as CollectionDataContract;
            }
            return null;
        }