本文整理汇总了C#中Microsoft.OData.Core.ODataComplexValue类的典型用法代码示例。如果您正苦于以下问题:C# ODataComplexValue类的具体用法?C# ODataComplexValue怎么用?C# ODataComplexValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataComplexValue类属于Microsoft.OData.Core命名空间,在下文中一共展示了ODataComplexValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AssertODataComplexValueAreEqual
private static void AssertODataComplexValueAreEqual(ODataComplexValue expectedComplexValue, ODataComplexValue actualComplexValue)
{
Assert.IsNotNull(expectedComplexValue);
Assert.IsNotNull(actualComplexValue);
Assert.AreEqual(expectedComplexValue.TypeName, actualComplexValue.TypeName);
AssertODataPropertiesAreEqual(expectedComplexValue.Properties, actualComplexValue.Properties);
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:7,代码来源:ODataValueAssertEqualHelper.cs
示例2: ODataJsonLightInheritComplexCollectionWriterTests
public ODataJsonLightInheritComplexCollectionWriterTests()
{
collectionStartWithoutSerializationInfo = new ODataCollectionStart();
collectionStartWithSerializationInfo = new ODataCollectionStart();
collectionStartWithSerializationInfo.SetSerializationInfo(new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(ns.Address)" });
address = new ODataComplexValue { Properties = new[]
{
new ODataProperty { Name = "Street", Value = "1 Microsoft Way" },
new ODataProperty { Name = "Zipcode", Value = 98052 },
new ODataProperty { Name = "State", Value = new ODataEnumValue("WA", "ns.StateEnum") },
new ODataProperty { Name = "City", Value = "Shanghai" }
}, TypeName = "TestNamespace.DerivedAddress" };
items = new[] { address };
EdmComplexType addressType = new EdmComplexType("ns", "Address");
addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(isNullable: true)));
addressType.AddProperty(new EdmStructuralProperty(addressType, "Zipcode", EdmCoreModel.Instance.GetInt32(isNullable: true)));
var stateEnumType = new EdmEnumType("ns", "StateEnum", isFlags: true);
stateEnumType.AddMember("IL", new EdmIntegerConstant(1));
stateEnumType.AddMember("WA", new EdmIntegerConstant(2));
addressType.AddProperty(new EdmStructuralProperty(addressType, "State", new EdmEnumTypeReference(stateEnumType, true)));
EdmComplexType derivedAddressType = new EdmComplexType("ns", "DerivedAddress", addressType, false);
derivedAddressType.AddProperty(new EdmStructuralProperty(derivedAddressType, "City", EdmCoreModel.Instance.GetString(isNullable: true)));
addressTypeReference = new EdmComplexTypeReference(addressType, isNullable: false);
derivedAddressTypeReference = new EdmComplexTypeReference(derivedAddressType, isNullable: false);
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:30,代码来源:ODataJsonLightInheritComplexCollectionWriterTests.cs
示例3: MultipleTypeCustomInstanceAnnotationsOnErrorShouldRoundtrip
public void MultipleTypeCustomInstanceAnnotationsOnErrorShouldRoundtrip()
{
var originalInt = new KeyValuePair<string, ODataValue>("int.error", new ODataPrimitiveValue(1));
var originalDouble = new KeyValuePair<string, ODataValue>("double.error", new ODataPrimitiveValue(double.NaN));
DateTimeOffset dateTimeOffset = new DateTimeOffset(2012, 10, 10, 12, 12, 59, new TimeSpan());
var originalDateTimeOffset = new KeyValuePair<string, ODataValue>("DateTimeOffset.error", new ODataPrimitiveValue(dateTimeOffset));
Date date = new Date(2014, 12, 12);
var originalDate = new KeyValuePair<string, ODataValue>("Date.error", new ODataPrimitiveValue(date));
TimeOfDay time = new TimeOfDay(10, 12, 3, 9);
var originaltime = new KeyValuePair<string, ODataValue>("TimeOfDay.error", new ODataPrimitiveValue(time));
TimeSpan timeSpan = new TimeSpan(12345);
var originalTimeSpan = new KeyValuePair<string, ODataValue>("TimeSpan.error", new ODataPrimitiveValue(timeSpan));
GeographyPoint geographyPoint = GeographyPoint.Create(32.0, -100.0);
var originalGeography = new KeyValuePair<string, ODataValue>("Geography.error", new ODataPrimitiveValue(geographyPoint));
var originalNull = new KeyValuePair<string, ODataValue>("null.error", new ODataNullValue());
var complexValue = new ODataComplexValue
{
TypeName = "ns.ErrorDetails",
Properties = new[] { new ODataProperty { Name = "ErrorDetailName", Value = "inner property value" } }
};
var originalComplex = new KeyValuePair<string, ODataValue>("sample.error", complexValue);
var error = this.WriteThenReadErrorWithInstanceAnnotation(originalInt, originalDouble, originalDate, originalDateTimeOffset, originaltime, originalTimeSpan, originalGeography, originalNull, originalComplex);
var annotation = RunBasicVerificationAndGetAnnotationValue("int.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(1);
annotation = RunBasicVerificationAndGetAnnotationValue("double.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(double.NaN);
annotation = RunBasicVerificationAndGetAnnotationValue("Date.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(date);
annotation = RunBasicVerificationAndGetAnnotationValue("DateTimeOffset.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(dateTimeOffset);
annotation = RunBasicVerificationAndGetAnnotationValue("TimeOfDay.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(time);
annotation = RunBasicVerificationAndGetAnnotationValue("TimeSpan.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(timeSpan);
annotation = RunBasicVerificationAndGetAnnotationValue("Geography.error", error);
annotation.Should().BeOfType<ODataPrimitiveValue>();
annotation.As<ODataPrimitiveValue>().Value.Should().Be(geographyPoint);
annotation = RunBasicVerificationAndGetAnnotationValue("null.error", error);
annotation.Should().BeOfType<ODataNullValue>();
annotation = RunBasicVerificationAndGetAnnotationValue("sample.error", error);
annotation.Should().BeOfType<ODataComplexValue>();
annotation.As<ODataComplexValue>().Properties.First().Value.Should().Be("inner property value");
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:60,代码来源:CustomInstanceAnnotationRoundtrippingTests.cs
示例4: ReadComplexValue
/// <summary>
/// Deserializes the given <paramref name="complexValue"/> under the given <paramref name="readContext"/>.
/// </summary>
/// <param name="complexValue">The complex value to deserialize.</param>
/// <param name="complexType">The EDM type of the complex value to read.</param>
/// <param name="readContext">The deserializer context.</param>
/// <returns>The deserialized complex value.</returns>
public virtual object ReadComplexValue(ODataComplexValue complexValue, IEdmComplexTypeReference complexType,
ODataDeserializerContext readContext)
{
if (complexValue == null)
{
throw Error.ArgumentNull("complexValue");
}
if (readContext == null)
{
throw Error.ArgumentNull("readContext");
}
if (readContext.Model == null)
{
throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
}
object complexResource = CreateResource(complexType, readContext);
foreach (ODataProperty complexProperty in complexValue.Properties)
{
DeserializationHelpers.ApplyProperty(complexProperty, complexType, complexResource, DeserializerProvider, readContext);
}
return complexResource;
}
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:32,代码来源:ODataComplexTypeDeserializer.cs
示例5: DefaultValuesAndPropertiesGetterAndSetterTest
public void DefaultValuesAndPropertiesGetterAndSetterTest()
{
ODataComplexValue odataComplexValue = new ODataComplexValue();
this.Assert.IsNull(odataComplexValue.Properties, "Expected null default value for property 'Properties'.");
List<ODataProperty> properties = new List<ODataProperty>();
odataComplexValue.Properties = properties;
this.Assert.AreSame(odataComplexValue.Properties, properties, "Expected reference equal values for property 'Properties'.");
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:8,代码来源:ODataComplexValueTests.cs
示例6: PropertySettersNullTest
public void PropertySettersNullTest()
{
ODataComplexValue odataComplexValue = new ODataComplexValue()
{
Properties = new List<ODataProperty>()
};
odataComplexValue.Properties = null;
this.Assert.IsNull(odataComplexValue.Properties, "Expected null value for property 'Properties'.");
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:9,代码来源:ODataComplexValueTests.cs
示例7: ComplexWithPrimitiveValueShouldMaterialize
public void ComplexWithPrimitiveValueShouldMaterialize()
{
ODataComplexValue pointComplexValue = new ODataComplexValue() {Properties = new ODataProperty[] {new ODataProperty() {Name = "X", Value = 15}, new ODataProperty() {Name = "Y", Value = 18}}};
this.CreatePrimitiveValueMaterializationPolicy().MaterializeComplexTypeProperty(typeof(CollectionValueMaterializationPolicyTests.Point), pointComplexValue);
pointComplexValue.HasMaterializedValue().Should().BeTrue();
var point = pointComplexValue.GetMaterializedValue().As<CollectionValueMaterializationPolicyTests.Point>();
point.X.Should().Be(15);
point.Y.Should().Be(18);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:9,代码来源:ComplexValueMaterializationPolicyTests.cs
示例8: ComplexTypeRoundtripAtomTest
public void ComplexTypeRoundtripAtomTest()
{
var age = new ODataProperty() { Name = "Age", Value = (Int16)18 };
var email = new ODataProperty() { Name = "Email", Value = "[email protected]" };
var tel = new ODataProperty() { Name = "Tel", Value = "0123456789" };
var id = new ODataProperty() { Name = "ID", Value = Guid.Empty };
ODataComplexValue complexValue = new ODataComplexValue() { TypeName = "NS.PersonalInfo", Properties = new[] { age, email, tel, id } };
this.VerifyComplexTypeRoundtrip(complexValue, "NS.PersonalInfo");
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs
示例9: ComplexTypeCollectionRoundtripAtomTest
public void ComplexTypeCollectionRoundtripAtomTest()
{
ODataComplexValue subject0 = new ODataComplexValue() { TypeName = "NS.Subject", Properties = new[] { new ODataProperty() { Name = "Name", Value = "English" }, new ODataProperty() { Name = "Score", Value = (Int16)98 } } };
ODataComplexValue subject1 = new ODataComplexValue() { TypeName = "NS.Subject", Properties = new[] { new ODataProperty() { Name = "Name", Value = "Math" }, new ODataProperty() { Name = "Score", Value = (Int16)90 } } };
ODataCollectionValue complexCollectionValue = new ODataCollectionValue { TypeName = "Collection(NS.Subject)", Items = new[] { subject0, subject1 } };
ODataFeedAndEntrySerializationInfo info = new ODataFeedAndEntrySerializationInfo() {
NavigationSourceEntityTypeName = subject0.TypeName,
NavigationSourceName = "Subjects",
ExpectedTypeName = subject0.TypeName
};
this.VerifyTypeCollectionRoundtrip(complexCollectionValue, "Subjects", info);
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:13,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs
示例10: TestBaseLine
private void TestBaseLine(ODataComplexValue val, string resVcf, string resJson)
{
// Write json, compare with baseline
Assert.AreEqual(
TestHelper.GetResourceString(resJson),
TestHelper.GetToplevelPropertyPayloadString(val),
"Json baseline");
// Write vcf, compare with baseline
Assert.AreEqual(
TestHelper.GetResourceString(resVcf),
TestHelper.GetToplevelPropertyPayloadString(val, "text/x-vCard", VCardMediaTypeResolver.Instance),
"Vcf baseline");
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:14,代码来源:ODataVCardScenarioTests.cs
示例11: PropertyGettersAndSettersTest
public void PropertyGettersAndSettersTest()
{
string name1 = "ODataPrimitiveProperty";
object value1 = "Hello world";
ODataProperty primitiveProperty = new ODataProperty()
{
Name = name1,
Value = value1,
};
this.Assert.AreEqual(name1, primitiveProperty.Name, "Expected equal name values.");
this.Assert.AreSame(value1, primitiveProperty.Value, "Expected reference equal values for property 'Value'.");
string name2 = "ODataComplexProperty";
ODataComplexValue value2 = new ODataComplexValue()
{
Properties = new[]
{
new ODataProperty() { Name = "One", Value = 1 },
new ODataProperty() { Name = "Two", Value = 2 },
}
};
ODataProperty complexProperty = new ODataProperty()
{
Name = name2,
Value = value2,
};
this.Assert.AreEqual(name2, complexProperty.Name, "Expected equal name values.");
this.Assert.AreSame(value2, complexProperty.Value, "Expected reference equal values for property 'Value'.");
string name3 = "ODataCollectionProperty";
ODataCollectionValue value3 = new ODataCollectionValue()
{
Items = new[] { 1, 2, 3 }
};
ODataProperty multiValueProperty = new ODataProperty()
{
Name = name3,
Value = value3,
};
this.Assert.AreEqual(name3, multiValueProperty.Name, "Expected equal name values.");
this.Assert.AreSame(value3, multiValueProperty.Value, "Expected reference equal values for property 'Value'.");
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:48,代码来源:ODataPropertyTests.cs
示例12: CreateStructuredEdmValue
internal static IEdmValue CreateStructuredEdmValue(ODataComplexValue complexValue, IEdmComplexTypeReference complexType)
{
if (complexType != null)
{
object typeAnnotation = ReflectionUtils.CreateInstance(
odataTypeAnnotationType,
new Type[] { typeof(IEdmComplexTypeReference) },
complexType);
complexValue.SetAnnotation(typeAnnotation);
}
return (IEdmValue)ReflectionUtils.CreateInstance(
odataEdmStructuredValueType,
new Type[] { typeof(ODataComplexValue) },
complexValue);
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:ODataEdmValueUtils.cs
示例13: ReadInline_Calls_ReadComplexValue
public void ReadInline_Calls_ReadComplexValue()
{
// Arrange
ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
Mock<ODataComplexTypeDeserializer> deserializer = new Mock<ODataComplexTypeDeserializer>(deserializerProvider);
ODataComplexValue item = new ODataComplexValue();
ODataDeserializerContext readContext = new ODataDeserializerContext();
deserializer.CallBase = true;
deserializer.Setup(d => d.ReadComplexValue(item, _addressEdmType, readContext)).Returns(42).Verifiable();
// Act
object result = deserializer.Object.ReadInline(item, _addressEdmType, readContext);
// Assert
deserializer.Verify();
Assert.Equal(42, result);
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:18,代码来源:ODataComplexTypeDeserializerTests.cs
示例14: WriteEntryAndComplex
public void WriteEntryAndComplex()
{
Action<ODataJsonLightOutputContext> test = outputContext =>
{
var entry = new ODataEntry();
var complex = new ODataComplexValue() {Properties = new List<ODataProperty>() {new ODataProperty() {Name = "Name", Value = "ComplexName"}}};
entry.Properties = new List<ODataProperty>() {new ODataProperty() {Name = "ID", Value = 1}, new ODataProperty() {Name = "complexProperty", Value = complex}};
var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
parameterWriter.WriteStart();
var entryWriter = parameterWriter.CreateEntryWriter("entry");
entryWriter.WriteStart(entry);
entryWriter.WriteEnd();
parameterWriter.WriteValue("complex", complex);
parameterWriter.WriteEnd();
parameterWriter.Flush();
};
WriteAndValidate(test, "{\"entry\":{\"ID\":1,\"complexProperty\":{\"Name\":\"ComplexName\"}},\"complex\":{\"Name\":\"ComplexName\"}}", writingResponse: false);
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:20,代码来源:ODataJsonLightParameterWriterTests.cs
示例15: ODataAvroWriterTests
static ODataAvroWriterTests()
{
var type = new EdmEntityType("NS", "SimpleEntry");
type.AddStructuralProperty("TBoolean", EdmPrimitiveTypeKind.Boolean, true);
type.AddStructuralProperty("TInt32", EdmPrimitiveTypeKind.Int32, true);
type.AddStructuralProperty("TCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt64(false))));
var cpx = new EdmComplexType("NS", "SimpleComplex");
cpx.AddStructuralProperty("TBinary", EdmPrimitiveTypeKind.Binary, true);
cpx.AddStructuralProperty("TString", EdmPrimitiveTypeKind.String, true);
type.AddStructuralProperty("TComplex", new EdmComplexTypeReference(cpx, true));
TestEntityType = type;
binary0 = new byte[] { 4, 7 };
complexValue0 = new ODataComplexValue()
{
Properties = new[]
{
new ODataProperty {Name = "TBinary", Value = binary0 ,},
new ODataProperty {Name = "TString", Value = "iamstr",},
},
TypeName = "NS.SimpleComplex"
};
longCollection0 = new[] {7L, 9L};
var collectionValue0 = new ODataCollectionValue { Items = longCollection0 };
entry0 = new ODataEntry
{
Properties = new[]
{
new ODataProperty {Name = "TBoolean", Value = true,},
new ODataProperty {Name = "TInt32", Value = 32,},
new ODataProperty {Name = "TComplex", Value = complexValue0,},
new ODataProperty {Name = "TCollection", Value = collectionValue0 },
},
TypeName = "NS.SimpleEntry"
};
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:38,代码来源:ODataAvroWriterTests.cs
示例16: MaterializeComplexTypeProperty
/// <summary>Materializes a complex type property.</summary>
/// <param name="propertyType">Type of the complex type to set.</param>
/// <param name="complexValue">The OData complex value.</param>
internal void MaterializeComplexTypeProperty(Type propertyType, ODataComplexValue complexValue)
{
//// TODO: we decide whether the type is primitive or complex only based on the payload. If there is a mismatch we throw a random exception.
//// We should have a similar check to the one we have for non-projection codepath here.
if (complexValue == null || complexValue.HasMaterializedValue())
{
return;
}
ClientTypeAnnotation complexType = null;
// TODO: We should call type resolver for complex types for projections if they are not instantiated by the user directly
// with "new" operator. At the moment we don't do it at all. Let's be consistent for Collections and call type
// resolver as we do in DirectMaterializationPlan (even though this is only for negative cases for Collections as property.IsCollection
// must have been false otherwise we would have not end up here).
// This bug is about investigating when we actually do call type resolver and fix it so that we call it when needed and don't
// call it when we should not (i.e. it should not be called for types created with "new" operator").
if (!string.IsNullOrEmpty(complexValue.TypeName))
{
complexType = this.MaterializerContext.ResolveTypeForMaterialization(propertyType, complexValue.TypeName);
}
else
{
ClientEdmModel edmModel = this.MaterializerContext.Model;
complexType = edmModel.GetClientTypeAnnotation(edmModel.GetOrCreateEdmType(propertyType));
}
object complexInstance = this.CreateNewInstance(complexType.EdmType.ToEdmTypeReference(true), complexType.ElementType);
this.MaterializeDataValues(complexType, complexValue.Properties, this.MaterializerContext.IgnoreMissingProperties);
this.ApplyDataValues(complexType, complexValue.Properties, complexInstance);
complexValue.SetMaterializedValue(complexInstance);
if (!this.MaterializerContext.Context.DisableInstanceAnnotationMaterialization)
{
this.InstanceAnnotationMaterializationPolicy.SetInstanceAnnotations(complexValue, complexInstance);
}
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:40,代码来源:ComplexValueMaterializationPolicy.cs
示例17: ReadComplexValue_CanReadDerivedComplexValue
public void ReadComplexValue_CanReadDerivedComplexValue()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.ComplexType<Address>();
IEdmModel model = builder.GetEdmModel();
IEdmComplexTypeReference addressEdmType = model.GetEdmTypeReference(typeof(Address)).AsComplex();
DefaultODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();
ODataComplexTypeDeserializer deserializer = new ODataComplexTypeDeserializer(deserializerProvider);
ODataComplexValue complexValue = new ODataComplexValue
{
Properties = new[]
{
new ODataProperty { Name = "Street", Value = "12"},
new ODataProperty { Name = "City", Value = "Redmond"},
new ODataProperty { Name = "UsProp", Value = "UsPropertyValue"}
},
TypeName = typeof(UsAddress).FullName
};
ODataDeserializerContext readContext = new ODataDeserializerContext { Model = model };
// Act
object address = deserializer.ReadComplexValue(complexValue, addressEdmType, readContext);
// Assert
Assert.NotNull(address);
UsAddress usAddress = Assert.IsType<UsAddress>(address);
Assert.Equal(usAddress.Street, "12");
Assert.Equal(usAddress.City, "Redmond");
Assert.Null(usAddress.Country);
Assert.Null(usAddress.State);
Assert.Null(usAddress.ZipCode);
Assert.Equal("UsPropertyValue", usAddress.UsProp);
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:37,代码来源:ODataComplexTypeDeserializerTests.cs
示例18: ReadComplexValue
/// <summary>
/// Deserializes the given <paramref name="complexValue"/> under the given <paramref name="readContext"/>.
/// </summary>
/// <param name="complexValue">The complex value to deserialize.</param>
/// <param name="complexType">The EDM type of the complex value to read.</param>
/// <param name="readContext">The deserializer context.</param>
/// <returns>The deserialized complex value.</returns>
public virtual object ReadComplexValue(ODataComplexValue complexValue, IEdmComplexTypeReference complexType,
ODataDeserializerContext readContext)
{
if (complexValue == null)
{
throw Error.ArgumentNull("complexValue");
}
if (readContext == null)
{
throw Error.ArgumentNull("readContext");
}
if (readContext.Model == null)
{
throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
}
if (!String.IsNullOrEmpty(complexValue.TypeName) && complexType.FullName() != complexValue.TypeName)
{
// received a derived complex type in a base type deserializer.
IEdmModel model = readContext.Model;
if (model == null)
{
throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
}
IEdmComplexType actualType = model.FindType(complexValue.TypeName) as IEdmComplexType;
if (actualType == null)
{
throw new ODataException(Error.Format(SRResources.ComplexTypeNotInModel, complexValue.TypeName));
}
if (actualType.IsAbstract)
{
string message = Error.Format(SRResources.CannotInstantiateAbstractComplexType,
complexValue.TypeName);
throw new ODataException(message);
}
IEdmTypeReference actualComplexType = new EdmComplexTypeReference(actualType, isNullable: false);
ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(actualComplexType);
if (deserializer == null)
{
throw new SerializationException(
Error.Format(SRResources.TypeCannotBeDeserialized, actualComplexType.FullName(),
typeof(ODataMediaTypeFormatter).Name));
}
object resource = deserializer.ReadInline(complexValue, actualComplexType, readContext);
EdmStructuredObject structuredObject = resource as EdmStructuredObject;
if (structuredObject != null)
{
structuredObject.ExpectedEdmType = complexType.ComplexDefinition();
}
return resource;
}
else
{
object complexResource = CreateResource(complexType, readContext);
foreach (ODataProperty complexProperty in complexValue.Properties)
{
DeserializationHelpers.ApplyProperty(complexProperty, complexType, complexResource,
DeserializerProvider, readContext);
}
return complexResource;
}
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:78,代码来源:ODataComplexTypeDeserializer.cs
示例19: WriteObject_Calls_CreateODataComplexValue
public void WriteObject_Calls_CreateODataComplexValue()
{
// Arrange
MemoryStream stream = new MemoryStream();
IODataResponseMessage message = new ODataMessageWrapper(stream);
ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
settings.SetServiceDocumentUri(new Uri("http://any/"));
settings.SetContentType(ODataFormat.Atom);
ODataMessageWriter messageWriter = new ODataMessageWriter(message, settings);
Mock<ODataComplexTypeSerializer> serializer = new Mock<ODataComplexTypeSerializer>(new DefaultODataSerializerProvider());
ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "ComplexPropertyName", Model = _model };
object graph = new object();
ODataComplexValue complexValue = new ODataComplexValue
{
TypeName = "NS.Name",
Properties = new[] { new ODataProperty { Name = "Property1", Value = 42 } }
};
serializer.CallBase = true;
serializer.Setup(s => s.CreateODataComplexValue(graph, It.Is<IEdmComplexTypeReference>(e => e.Definition == _addressType), writeContext))
.Returns(complexValue).Verifiable();
// Act
serializer.Object.WriteObject(graph, typeof(Address), messageWriter, writeContext);
// Assert
serializer.Verify();
stream.Seek(0, SeekOrigin.Begin);
XElement element = XElement.Load(stream);
Assert.Equal("value", element.Name.LocalName);
Assert.Equal("#NS.Name", element.Attributes().Single(a => a.Name.LocalName == "type").Value);
Assert.Equal(1, element.Descendants().Count());
Assert.Equal("42", element.Descendants().Single().Value);
Assert.Equal("Property1", element.Descendants().Single().Name.LocalName);
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:35,代码来源:ODataComplexTypeSerializerTests.cs
示例20: CreateODataComplexValue
/// <summary>
/// Creates an <see cref="ODataComplexValue"/> for the object represented by <paramref name="graph"/>.
/// </summary>
/// <param name="graph">The value of the <see cref="ODataComplexValue"/> to be created.</param>
/// <param name="complexType">The EDM complex type of the object.</param>
/// <param name="writeContext">The serializer context.</param>
/// <returns>The created <see cref="ODataComplexValue"/>.</returns>
public virtual ODataComplexValue CreateODataComplexValue(object graph, IEdmComplexTypeReference complexType,
ODataSerializerContext writeContext)
{
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
if (graph == null || graph is NullEdmComplexObject)
{
return null;
}
IEdmComplexObject complexObject = graph as IEdmComplexObject ?? new TypedEdmComplexObject(graph, complexType, writeContext.Model);
List<ODataProperty> propertyCollection = new List<ODataProperty>();
foreach (IEdmProperty property in complexType.ComplexDefinition().Properties())
{
IEdmTypeReference propertyType = property.Type;
ODataEdmTypeSerializer propertySerializer = SerializerProvider.GetEdmTypeSerializer(propertyType);
if (propertySerializer == null)
{
throw Error.NotSupported(SRResources.TypeCannotBeSerialized, propertyType.FullName(), typeof(ODataOutputFormatter).Name);
}
object propertyValue;
if (complexObject.TryGetPropertyValue(property.Name, out propertyValue))
{
if (propertyType != null && propertyType.IsComplex())
{
IEdmTypeReference actualType = writeContext.GetEdmType(propertyValue, propertyValue.GetType());
if (actualType != null && propertyType != actualType)
{
propertyType = actualType;
}
}
propertyCollection.Add(
propertySerializer.CreateProperty(propertyValue, propertyType, property.Name, writeContext));
}
}
// Try to add the dynamic properties if the complex type is open.
if (complexType.ComplexDefinition().IsOpen)
{
List<ODataProperty> dynamicProperties =
AppendDynamicProperties(complexObject, complexType, writeContext, propertyCollection, new string[0]);
if (dynamicProperties != null)
{
propertyCollection.AddRange(dynamicProperties);
}
}
string typeName = complexType.FullName();
ODataComplexValue value = new ODataComplexValue()
{
Properties = propertyCollection,
TypeName = typeName
};
AddTypeNameAnnotationAsNeeded(value, writeContext.MetadataLevel);
return value;
}
开发者ID:genusP,项目名称:WebApi,代码行数:72,代码来源:ODataComplexTypeSerializer.cs
注:本文中的Microsoft.OData.Core.ODataComplexValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论