private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; var dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if (!dic.ContainsKey("_dataIdType_") || !dic.ContainsKey("_dataId_") || !dic.ContainsKey("_interfaceType_") || !dic.ContainsKey("_dataScope_") || !dic.ContainsKey("_localeScope_")) { if (throwException) { throw new ArgumentException("The argument is not a serialized " + nameof(DataSourceId), nameof(serializedDataSourceId)); } return(false); } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdTypeName = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName = dic.ContainsKey("_providerName_") ? StringConversionServices.DeserializeValueString(dic["_providerName_"]) : DataProviderRegistry.DefaultDynamicTypeDataProviderName; string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException($"The type '{interfaceTypeName}' could not be found"); } return(false); } Type dataIdType = TypeManager.TryGetType(dataIdTypeName); if (dataIdType == null) { if (throwException) { throw new InvalidOperationException($"The type '{dataIdTypeName}' could not be found"); } return(false); } serializedDataId = FixSerializedDataId(serializedDataId, interfaceType); IDataId dataId = SerializationFacade.Deserialize <IDataId>(dataIdType, serializedDataId); CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }
private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if ((dic.ContainsKey("_dataIdType_") == false) || (dic.ContainsKey("_dataId_") == false) || (dic.ContainsKey("_interfaceType_") == false) || (dic.ContainsKey("_dataScope_") == false) || (dic.ContainsKey("_localeScope_") == false)) { if (throwException) { throw new ArgumentException("The serializedDataSourceId is not a serialized data source id", "serializedDataSourceId"); } else { return(false); } } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName; if (dic.ContainsKey("_providerName_")) { providerName = StringConversionServices.DeserializeValueString(dic["_providerName_"]); } else { providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName; } string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } return(false); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataId); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", interfaceType)); } return(false); } CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }