コード例 #1
0
 private static JsonDataContract CreateJsonDataContract(int id, DataContract traditionalDataContract)
 {
     lock (createDataContractLock)
     {
         JsonDataContract contract = dataContractCache[id];
         if (contract == null)
         {
             Type type = traditionalDataContract.GetType();
             if (type == typeof(ObjectDataContract))
             {
                 contract = new JsonObjectDataContract(traditionalDataContract);
             }
             else if (type == typeof(StringDataContract))
             {
                 contract = new JsonStringDataContract((StringDataContract)traditionalDataContract);
             }
             else if (type == typeof(UriDataContract))
             {
                 contract = new JsonUriDataContract((UriDataContract)traditionalDataContract);
             }
             else if (type == typeof(QNameDataContract))
             {
                 contract = new JsonQNameDataContract((QNameDataContract)traditionalDataContract);
             }
             else if (type == typeof(ByteArrayDataContract))
             {
                 contract = new JsonByteArrayDataContract((ByteArrayDataContract)traditionalDataContract);
             }
             else if (traditionalDataContract.IsPrimitive || (traditionalDataContract.UnderlyingType == Globals.TypeOfXmlQualifiedName))
             {
                 contract = new JsonDataContract(traditionalDataContract);
             }
             else if (type == typeof(ClassDataContract))
             {
                 contract = new JsonClassDataContract((ClassDataContract)traditionalDataContract);
             }
             else if (type == typeof(EnumDataContract))
             {
                 contract = new JsonEnumDataContract((EnumDataContract)traditionalDataContract);
             }
             else if ((type == typeof(GenericParameterDataContract)) || (type == typeof(SpecialTypeDataContract)))
             {
                 contract = new JsonDataContract(traditionalDataContract);
             }
             else if (type == typeof(CollectionDataContract))
             {
                 contract = new JsonCollectionDataContract((CollectionDataContract)traditionalDataContract);
             }
             else
             {
                 if (type != typeof(XmlDataContract))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("traditionalDataContract", System.Runtime.Serialization.SR.GetString("JsonTypeNotSupportedByDataContractJsonSerializer", new object[] { traditionalDataContract.UnderlyingType }));
                 }
                 contract = new JsonXmlDataContract((XmlDataContract)traditionalDataContract);
             }
         }
         return(contract);
     }
 }
コード例 #2
0
ファイル: JsonDataContract.cs プロジェクト: johnhhm/corefx
 private static JsonDataContract CreateJsonDataContract(int id, DataContract traditionalDataContract)
 {
     lock (s_createDataContractLock)
     {
         JsonDataContract dataContract = s_dataContractCache[id];
         if (dataContract == null)
         {
             Type traditionalDataContractType = traditionalDataContract.GetType();
             if (traditionalDataContractType == typeof(ObjectDataContract))
             {
                 dataContract = new JsonObjectDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(StringDataContract))
             {
                 dataContract = new JsonStringDataContract((StringDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(UriDataContract))
             {
                 dataContract = new JsonUriDataContract((UriDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(QNameDataContract))
             {
                 dataContract = new JsonQNameDataContract((QNameDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(ByteArrayDataContract))
             {
                 dataContract = new JsonByteArrayDataContract((ByteArrayDataContract)traditionalDataContract);
             }
             else if (traditionalDataContract.IsPrimitive ||
                 traditionalDataContract.UnderlyingType == Globals.TypeOfXmlQualifiedName)
             {
                 dataContract = new JsonDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(ClassDataContract))
             {
                 dataContract = new JsonClassDataContract((ClassDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(EnumDataContract))
             {
                 dataContract = new JsonEnumDataContract((EnumDataContract)traditionalDataContract);
             }
             else if ((traditionalDataContractType == typeof(GenericParameterDataContract)) ||
                 (traditionalDataContractType == typeof(SpecialTypeDataContract)))
             {
                 dataContract = new JsonDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(CollectionDataContract))
             {
                 dataContract = new JsonCollectionDataContract((CollectionDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(XmlDataContract))
             {
                 dataContract = new JsonXmlDataContract((XmlDataContract)traditionalDataContract);
             }
             else
             {
                 throw new ArgumentException(SR.Format(SR.JsonTypeNotSupportedByDataContractJsonSerializer, traditionalDataContract.UnderlyingType), "traditionalDataContract");
             }
         }
         return dataContract;
     }
 }
コード例 #3
0
ファイル: JsonDataContract.cs プロジェクト: pgovind/runtime
 private static JsonDataContract CreateJsonDataContract(int id, DataContract traditionalDataContract)
 {
     lock (s_createDataContractLock)
     {
         JsonDataContract dataContract = s_dataContractCache[id];
         if (dataContract == null)
         {
             Type traditionalDataContractType = traditionalDataContract.GetType();
             if (traditionalDataContractType == typeof(ObjectDataContract))
             {
                 dataContract = new JsonObjectDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(StringDataContract))
             {
                 dataContract = new JsonStringDataContract((StringDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(UriDataContract))
             {
                 dataContract = new JsonUriDataContract((UriDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(QNameDataContract))
             {
                 dataContract = new JsonQNameDataContract((QNameDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(ByteArrayDataContract))
             {
                 dataContract = new JsonByteArrayDataContract((ByteArrayDataContract)traditionalDataContract);
             }
             else if (traditionalDataContract.IsPrimitive ||
                      traditionalDataContract.UnderlyingType == Globals.TypeOfXmlQualifiedName)
             {
                 dataContract = new JsonDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(ClassDataContract))
             {
                 dataContract = new JsonClassDataContract((ClassDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(EnumDataContract))
             {
                 dataContract = new JsonEnumDataContract((EnumDataContract)traditionalDataContract);
             }
             else if ((traditionalDataContractType == typeof(GenericParameterDataContract)) ||
                      (traditionalDataContractType == typeof(SpecialTypeDataContract)))
             {
                 dataContract = new JsonDataContract(traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(CollectionDataContract))
             {
                 dataContract = new JsonCollectionDataContract((CollectionDataContract)traditionalDataContract);
             }
             else if (traditionalDataContractType == typeof(XmlDataContract))
             {
                 dataContract = new JsonXmlDataContract((XmlDataContract)traditionalDataContract);
             }
             else
             {
                 throw new ArgumentException(SR.Format(SR.JsonTypeNotSupportedByDataContractJsonSerializer, traditionalDataContract.UnderlyingType), nameof(traditionalDataContract));
             }
         }
         return(dataContract);
     }
 }
 private static JsonDataContract CreateJsonDataContract(int id, DataContract traditionalDataContract)
 {
     lock (createDataContractLock)
     {
         JsonDataContract contract = dataContractCache[id];
         if (contract == null)
         {
             Type type = traditionalDataContract.GetType();
             if (type == typeof(ObjectDataContract))
             {
                 contract = new JsonObjectDataContract(traditionalDataContract);
             }
             else if (type == typeof(StringDataContract))
             {
                 contract = new JsonStringDataContract((StringDataContract) traditionalDataContract);
             }
             else if (type == typeof(UriDataContract))
             {
                 contract = new JsonUriDataContract((UriDataContract) traditionalDataContract);
             }
             else if (type == typeof(QNameDataContract))
             {
                 contract = new JsonQNameDataContract((QNameDataContract) traditionalDataContract);
             }
             else if (type == typeof(ByteArrayDataContract))
             {
                 contract = new JsonByteArrayDataContract((ByteArrayDataContract) traditionalDataContract);
             }
             else if (traditionalDataContract.IsPrimitive || (traditionalDataContract.UnderlyingType == Globals.TypeOfXmlQualifiedName))
             {
                 contract = new JsonDataContract(traditionalDataContract);
             }
             else if (type == typeof(ClassDataContract))
             {
                 contract = new JsonClassDataContract((ClassDataContract) traditionalDataContract);
             }
             else if (type == typeof(EnumDataContract))
             {
                 contract = new JsonEnumDataContract((EnumDataContract) traditionalDataContract);
             }
             else if ((type == typeof(GenericParameterDataContract)) || (type == typeof(SpecialTypeDataContract)))
             {
                 contract = new JsonDataContract(traditionalDataContract);
             }
             else if (type == typeof(CollectionDataContract))
             {
                 contract = new JsonCollectionDataContract((CollectionDataContract) traditionalDataContract);
             }
             else
             {
                 if (type != typeof(XmlDataContract))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("traditionalDataContract", System.Runtime.Serialization.SR.GetString("JsonTypeNotSupportedByDataContractJsonSerializer", new object[] { traditionalDataContract.UnderlyingType }));
                 }
                 contract = new JsonXmlDataContract((XmlDataContract) traditionalDataContract);
             }
         }
         return contract;
     }
 }