本文整理匯總了C#中System.Runtime.Serialization.DataContract.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# DataContract.GetType方法的具體用法?C# DataContract.GetType怎麽用?C# DataContract.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Runtime.Serialization.DataContract
的用法示例。
在下文中一共展示了DataContract.GetType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: VerifyObjectCompatibilityWithInterface
private static void VerifyObjectCompatibilityWithInterface(DataContract contract, object graph, Type declaredType)
{
Type type = contract.GetType();
if ((type == typeof(XmlDataContract)) && !Globals.TypeOfIXmlSerializable.IsAssignableFrom(declaredType))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("XmlObjectAssignedToIncompatibleInterface", new object[] { graph.GetType(), declaredType })));
}
if ((type == typeof(CollectionDataContract)) && !CollectionDataContract.IsCollectionInterface(declaredType))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("CollectionAssignedToIncompatibleInterface", new object[] { graph.GetType(), declaredType })));
}
}
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:12,代碼來源:XmlObjectSerializerWriteContextComplexJson.cs
示例2: CreateJsonDataContract
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: CreateJsonDataContract
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;
}
}