本文整理汇总了C#中ODataProperty类的典型用法代码示例。如果您正苦于以下问题:C# ODataProperty类的具体用法?C# ODataProperty怎么用?C# ODataProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataProperty类属于命名空间,在下文中一共展示了ODataProperty类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToSetThePropertySerializationInfo
public void ShouldBeAbleToSetThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SetSerializationInfo(serializationInfo);
property.SerializationInfo.Should().BeSameAs(serializationInfo);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:ODataObjectModelExtensionTests.cs
示例2: WriteTopLevelProperty
/// <summary>
/// Write an <see cref="ODataProperty" /> to the given stream. This method creates an
/// async buffered stream and writes the property to it.
/// </summary>
/// <param name="property">The property to write.</param>
internal void WriteTopLevelProperty(ODataProperty property)
{
Debug.Assert(property != null, "property != null");
Debug.Assert(!(property.Value is ODataStreamReferenceValue), "!(property.Value is ODataStreamReferenceValue)");
this.WriteTopLevelPayload(
() =>
{
this.JsonWriter.StartObjectScope();
ODataPayloadKind kind = this.JsonLightOutputContext.MessageWriterSettings.IsIndividualProperty ? ODataPayloadKind.IndividualProperty : ODataPayloadKind.Property;
ODataContextUrlInfo contextInfo = ODataContextUrlInfo.Create(property.ODataValue, this.JsonLightOutputContext.MessageWriterSettings.ODataUri, this.Model);
this.WriteContextUriProperty(kind, () => contextInfo);
// Note we do not allow named stream properties to be written as top level property.
this.JsonLightValueSerializer.AssertRecursionDepthIsZero();
this.WriteProperty(
property,
null /*owningType*/,
true /* isTopLevel */,
false /* allowStreamProperty */,
this.CreateDuplicatePropertyNamesChecker(),
null /* projectedProperties */);
this.JsonLightValueSerializer.AssertRecursionDepthIsZero();
this.JsonWriter.EndObjectScope();
});
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:33,代码来源:ODataJsonLightPropertySerializer.cs
示例3: ShouldBeAbleToClearThePropertySerializationInfo
public void ShouldBeAbleToClearThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SerializationInfo = serializationInfo;
property.SetSerializationInfo(null);
property.SerializationInfo.Should().BeNull();
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:8,代码来源:ODataObjectModelExtensionTests.cs
示例4: ComputeStreamPropertyRelation
/// <summary>
/// Creates the value for the stream property's link relation attribute.
/// </summary>
/// <param name="streamProperty">The stream property to create the relation for.</param>
/// <param name="forEditLink">'true' if the relation is computed for an edit link; otherwise 'false'.</param>
/// <returns>The relation attribute value for the stream property's link relation.</returns>
internal static string ComputeStreamPropertyRelation(ODataProperty streamProperty, bool forEditLink)
{
Debug.Assert(streamProperty != null, "streamProperty != null");
Debug.Assert(!string.IsNullOrEmpty(streamProperty.Name), "!string.IsNullOrEmpty(streamProperty.Name)");
string segmentName = forEditLink ? AtomConstants.ODataStreamPropertyEditMediaRelatedLinkRelationPrefix : AtomConstants.ODataStreamPropertyMediaResourceRelatedLinkRelationPrefix;
return string.Join("", new string[] { segmentName, streamProperty.Name });
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:14,代码来源:AtomUtils.cs
示例5: 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:larsenjo,项目名称:odata.net,代码行数:11,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs
示例6: ShouldBeAbleToWriteInstanceAnnotationsInResponse
public void ShouldBeAbleToWriteInstanceAnnotationsInResponse()
{
ODataProperty property = new ODataProperty()
{
Name = "Prop",
Value = Guid.Empty,
InstanceAnnotations = new Collection<ODataInstanceAnnotation>
{
new ODataInstanceAnnotation("Annotation.1", new ODataPrimitiveValue(true)),
new ODataInstanceAnnotation("Annotation.2", new ODataPrimitiveValue(123))
}
};
WriteAndValidate(outputContext => outputContext.WriteProperty(property), "{\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Guid\",\"@Annotation.1\":true,\"@Annotation.2\":123,\"value\":\"00000000-0000-0000-0000-000000000000\"}");
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:14,代码来源:ODataJsonLightOutputContextTests.cs
示例7: WriteTopLevelProperty
/// <summary>
/// Writes a single property in ATOM format.
/// </summary>
/// <param name="property">The property to write out.</param>
internal void WriteTopLevelProperty(ODataProperty property)
{
this.WritePayloadStart();
this.AssertRecursionDepthIsZero();
this.WriteProperty(
property,
null /*owningType*/,
true /* isTopLevel */,
false /* isWritingCollection */,
null /* beforePropertyAction */,
this.CreateDuplicatePropertyNamesChecker(),
null /* projectedProperties */);
this.AssertRecursionDepthIsZero();
this.WritePayloadEnd();
}
开发者ID:TomDu,项目名称:odata.net,代码行数:19,代码来源:ODataAtomPropertyAndValueSerializer.cs
示例8: ValidateProperty
/// <summary>
/// Validates an <see cref="ODataProperty"/> to ensure all required information is specified.
/// </summary>
/// <param name="property">The property to validate.</param>
internal static void ValidateProperty(ODataProperty property)
{
DebugUtils.CheckNoExternalCallers();
if (property == null)
{
throw new ODataException(Strings.ODataWriter_PropertyMustNotBeNull);
}
// Properties must have a non-empty name
if (string.IsNullOrEmpty(property.Name))
{
throw new ODataException(Strings.ODataWriter_PropertiesMustHaveNonEmptyName);
}
}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:19,代码来源:ValidationUtils.cs
示例9: JsonPaddingEnabledWithUserSpecifiedContentType
public void JsonPaddingEnabledWithUserSpecifiedContentType()
{
var settings = new ODataMessageWriterSettings {JsonPCallback = "functionName", DisableMessageStreamDisposal = true};
settings.SetServiceDocumentUri(new Uri("http://stuff"));
IODataResponseMessage message = new InMemoryMessage {StatusCode = 200, Stream = new MemoryStream()};
message.SetHeader("Content-Type", "application/json");
var property = new ODataProperty {Name = "PropertyName", Value = "value"};
using (var writer = new ODataMessageWriter(message, settings))
{
writer.WriteProperty(property);
}
var responseStream = message.GetStream();
responseStream.Position = 0;
var responseString = new StreamReader(responseStream).ReadToEnd();
responseString.Should().Be("functionName({\"@odata.context\":\"http://stuff/$metadata#Edm.String\",\"value\":\"value\"})");
message.GetHeader("Content-Type").Should().StartWith("text/javascript");
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:19,代码来源:WriterSmokeTests.cs
示例10: WritePropertyStart
/// <summary>
/// Writes the property start element.
/// </summary>
/// <param name="beforePropertyCallback">Action called before anything else is written (if it's not null).</param>
/// <param name="property">The odata property to write.</param>
/// <param name="isWritingCollection">true if we are writing a collection instead of an entry.</param>
/// <param name="isTopLevel">true if writing a top-level property payload; otherwise false.</param>
private void WritePropertyStart(Action beforePropertyCallback, ODataProperty property, bool isWritingCollection, bool isTopLevel)
{
this.WritePropertyStart(beforePropertyCallback, property.Name, property.ODataValue, isWritingCollection, isTopLevel);
}
开发者ID:TomDu,项目名称:odata.net,代码行数:11,代码来源:ODataAtomPropertyAndValueSerializer.cs
示例11: ComputeStreamPropertyRelation
/// <summary>
/// Creates the value for the stream property's link relation attribute.
/// </summary>
/// <param name="streamProperty">The stream property to create the relation for.</param>
/// <param name="forEditLink">'true' if the relation is computed for an edit link; otherwise 'false'.</param>
/// <returns>The relation attribute value for the stream property's link relation.</returns>
internal static string ComputeStreamPropertyRelation(ODataProperty streamProperty, bool forEditLink)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(streamProperty != null, "streamProperty != null");
Debug.Assert(!string.IsNullOrEmpty(streamProperty.Name), "!string.IsNullOrEmpty(streamProperty.Name)");
string segmentName = forEditLink ? AtomConstants.ODataStreamPropertyEditMediaSegmentName : AtomConstants.ODataStreamPropertyMediaResourceSegmentName;
return string.Join("/", new string[] { AtomConstants.ODataNamespace, segmentName, streamProperty.Name });
}
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:15,代码来源:AtomUtils.cs
示例12: ODataPropertyTests
public ODataPropertyTests()
{
this.property = new ODataProperty();
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:4,代码来源:ODataPropertyTests.cs
示例13: IsOpenProperty
/// <summary>
/// Test to see if <paramref name="property"/> is an open property or not.
/// </summary>
/// <param name="property">The property in question.</param>
/// <param name="owningType">The owning type of the property.</param>
/// <param name="edmProperty">The metadata of the property.</param>
/// <returns>true if the property is an open property; false if it is not, or if openness cannot be determined</returns>
private bool IsOpenProperty(ODataProperty property, IEdmStructuredType owningType, IEdmProperty edmProperty)
{
Debug.Assert(property != null, "property != null");
if (property.SerializationInfo != null)
{
return property.SerializationInfo.PropertyKind == ODataPropertyKind.Open;
}
return (!this.WritingResponse && owningType == null) // Treat property as dynamic property when writing request and owning type is null
|| (owningType != null && owningType.IsOpen && edmProperty == null);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:18,代码来源:ODataJsonLightPropertySerializer.cs
示例14: WriteProperty
/// <summary>
/// Writes a single property in ATOM format.
/// </summary>
/// <param name="writer">The <see cref="XmlWriter"/> to write to.</param>
/// <param name="metadata">The metadata provider to use or null if no metadata is available.</param>
/// <param name="property">The property to write out.</param>
/// <param name="owningType">The type owning the property (or null if no metadata is available).</param>
/// <param name="version">The protocol version used for writing.</param>
/// <param name="isTopLevel">True if writing a top-level property payload; otherwise false.</param>
/// <param name="isWritingCollection">True if we are writing a collection instead of an entry.</param>
/// <param name="epmValueCache">Cache of values used in EPM so that we avoid multiple enumerations of properties/items. (can be null)</param>
/// <param name="epmParentSourcePathSegment">The EPM source path segment which points to the property which sub-property we're writing. (can be null)</param>
internal static void WriteProperty(
XmlWriter writer,
DataServiceMetadataProviderWrapper metadata,
ODataProperty property,
ResourceType owningType,
ODataVersion version,
bool isTopLevel,
bool isWritingCollection,
EpmValueCache epmValueCache,
EpmSourcePathSegment epmParentSourcePathSegment)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(writer != null, "writer != null");
ValidationUtils.ValidateProperty(property);
ResourceProperty resourceProperty = ValidationUtils.ValidatePropertyDefined(property.Name, owningType);
EpmSourcePathSegment epmSourcePathSegment = null;
if (epmParentSourcePathSegment != null)
{
epmSourcePathSegment = epmParentSourcePathSegment.SubProperties.Where(subProperty => subProperty.PropertyName == property.Name).FirstOrDefault();
}
object value = property.Value;
// TODO: If we implement validation or type conversions the value needs to be converted here
// since the next method call needs to know if the value is a string or not in some cases.
// If EPM tells us to skip this property in content, then we're done here.
if (!ShouldWritePropertyInContent(value, epmSourcePathSegment, version))
{
return;
}
// <d:propertyname>
writer.WriteStartElement(
isWritingCollection ? string.Empty : AtomConstants.ODataNamespacePrefix,
property.Name,
AtomConstants.ODataNamespace);
if (isTopLevel)
{
WriteDefaultNamespaceAttributes(writer, DefaultNamespaceFlags.OData | DefaultNamespaceFlags.ODataMetadata);
}
// Null property value.
if (value == null)
{
// verify that MultiValue properties are not null
if (resourceProperty != null && resourceProperty.Kind == ResourcePropertyKind.MultiValue)
{
throw new ODataException(Strings.ODataWriter_MultiValuePropertiesMustNotHaveNullValue(resourceProperty.Name));
}
ODataAtomWriterUtils.WriteNullAttribute(writer);
}
else
{
ODataComplexValue complexValue = value as ODataComplexValue;
ResourceType resourcePropertyType = resourceProperty == null ? null : resourceProperty.ResourceType;
bool isOpenPropertyType = owningType != null && owningType.IsOpenType && resourceProperty == null;
// Complex properties are written recursively.
if (complexValue != null)
{
WriteComplexValue(writer, metadata, complexValue, resourcePropertyType, isOpenPropertyType, isWritingCollection, version, epmValueCache, epmSourcePathSegment);
}
else
{
ODataMultiValue multiValue = value as ODataMultiValue;
if (multiValue != null)
{
ODataVersionChecker.CheckMultiValueProperties(version, property.Name);
WriteMultiValue(writer, metadata, multiValue, resourcePropertyType, isOpenPropertyType, isWritingCollection, version, epmValueCache, epmSourcePathSegment);
}
else
{
WritePrimitiveValue(writer, value, resourcePropertyType);
}
}
}
// </d:propertyname>
writer.WriteEndElement();
}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:97,代码来源:ODataAtomWriterUtils.cs
示例15: WritePropertyImplementation
/// <summary>
/// Writes an <see cref="ODataProperty"/> as message payload.
/// </summary>
/// <param name="property">The property to write.</param>
private void WritePropertyImplementation(ODataProperty property)
{
ODataJsonLightPropertySerializer jsonLightPropertySerializer = new ODataJsonLightPropertySerializer(this, /*initContextUriBuilder*/ true);
jsonLightPropertySerializer.WriteTopLevelProperty(property);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:9,代码来源:ODataJsonLightOutputContext.cs
示例16: FlagsEnumAsTopLevelProperty_StrAsValue_StrAsTypeName
public void FlagsEnumAsTopLevelProperty_StrAsValue_StrAsTypeName()
{
WriteToMessageWriterAndVerifyPayload(
contentType: "application/xml;",
writerAction: (writer) =>
{
ODataProperty property = new ODataProperty()
{
Name = "MyColorPropertyName",
Value = new ODataEnumValue(Color.Red.ToString(), "NS.EnumUndefinedTypename")
};
writer.WriteProperty(property);
},
expectedPayload: "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<m:value xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:georss=\"http://www.georss.org/georss\" " +
"xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#NS.EnumUndefinedTypename\" m:type=\"#NS.EnumUndefinedTypename\" " +
"xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\">" +
"Red" +
"</m:value>"
);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:21,代码来源:ODataAtomWriterEnumIntegrationTests.cs
示例17: ReadProperty
/// <summary>
/// Reads a property.
/// </summary>
/// <param name="isTop">whether it is the top level</param>
/// <param name="expectedPropertyName">The expected property name to be read from the payload (or null if no expected property name was specified).</param>
/// <param name="expectedPropertyTypeReference">The expected type reference of the property value.</param>
/// <param name="nullValueReadBehaviorKind">Behavior to use when reading null value for the property.</param>
/// <returns>The ODataProperty representing the property in question; if null is returned from this method it means that the property is to be ignored.</returns>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - The XML element representing the property to read.
/// Note that the method does NOT check for the property name neither it resolves the property against metadata.
/// Post-Condition: Any - The node after the property.
/// </remarks>
private ODataProperty ReadProperty(
bool isTop,
string expectedPropertyName,
IEdmTypeReference expectedPropertyTypeReference,
ODataNullValueBehaviorKind nullValueReadBehaviorKind)
{
Debug.Assert(
expectedPropertyTypeReference == null || expectedPropertyTypeReference.IsODataPrimitiveTypeKind() || expectedPropertyTypeReference.IsODataEnumTypeKind() ||
expectedPropertyTypeReference.IsODataComplexTypeKind() || expectedPropertyTypeReference.IsNonEntityCollectionType(),
"Only primitive, Enum, complex and collection types can be read by this method.");
this.AssertXmlCondition(XmlNodeType.Element);
this.XmlReader.AssertNotBuffering();
ODataProperty property = new ODataProperty();
string propertyName = null;
if (!isTop)
{
propertyName = this.XmlReader.LocalName;
ValidationUtils.ValidatePropertyName(propertyName);
ReaderValidationUtils.ValidateExpectedPropertyName(expectedPropertyName, propertyName);
}
property.Name = propertyName;
object propertyValue = this.ReadNonEntityValueImplementation(
expectedPropertyTypeReference,
/*duplicatePropertyNamesChecker*/ null,
/*collectionValidator*/ null,
nullValueReadBehaviorKind == ODataNullValueBehaviorKind.Default,
propertyName);
if (nullValueReadBehaviorKind == ODataNullValueBehaviorKind.IgnoreValue && propertyValue == null)
{
property = null;
}
else
{
property.Value = propertyValue;
}
// Read past the end tag of the property or the start tag if the element is empty.
this.XmlReader.Read();
this.XmlReader.AssertNotBuffering();
return property;
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:59,代码来源:ODataAtomPropertyAndValueDeserializer.cs
示例18: FlagsEnumAsTopLevelProperty_StrAsValue_StrAsTypeName_FullMetadata
public void FlagsEnumAsTopLevelProperty_StrAsValue_StrAsTypeName_FullMetadata()
{
ReadFromMessageReaderAndVerifyPayload(
payload: "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<m:value xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:georss=\"http://www.georss.org/georss\" " +
"xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/test/$metadata#NS.Color\" m:type=\"#NS.Color\" " +
"xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\">" +
"Red" +
"</m:value>",
readerAction: (reader) =>
{
ODataProperty expectedProperty = new ODataProperty()
{
Name = null,
Value = new ODataEnumValue(Color.Red.ToString(), "NS.Color")
};
ODataProperty property = reader.ReadProperty();
TestUtils.AssertODataPropertyAreEqual(expectedProperty, property);
}
);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:21,代码来源:ODataAtomReaderEnumIntegrationTests.cs
示例19: WriteProperty
private void WriteProperty(
ODataProperty property,
IEdmStructuredType owningType,
bool isTopLevel,
bool allowStreamProperty,
DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
ProjectedPropertiesAnnotation projectedProperties)
{
WriterValidationUtils.ValidatePropertyNotNull(property);
string propertyName = property.Name;
if (projectedProperties.ShouldSkipProperty(propertyName))
{
return;
}
WriterValidationUtils.ValidatePropertyName(propertyName, bypassValidation);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(property);
if (property.InstanceAnnotations.Any())
{
if (isTopLevel)
{
this.InstanceAnnotationWriter.WriteInstanceAnnotations(property.InstanceAnnotations);
}
else
{
this.InstanceAnnotationWriter.WriteInstanceAnnotations(property.InstanceAnnotations, propertyName);
}
}
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(
propertyName,
owningType,
!this.bypassValidation);
IEdmTypeReference propertyTypeReference = edmProperty == null ? null : edmProperty.Type;
ODataValue value = property.ODataValue;
ODataStreamReferenceValue streamReferenceValue = value as ODataStreamReferenceValue;
if (streamReferenceValue != null)
{
if (!allowStreamProperty)
{
throw new ODataException(ODataErrorStrings.ODataWriter_StreamPropertiesMustBePropertiesOfODataEntry(propertyName));
}
Debug.Assert(owningType == null || owningType.IsODataEntityTypeKind(), "The metadata should not allow named stream properties to be defined on a non-entity type.");
Debug.Assert(!isTopLevel, "Stream properties are not allowed at the top level.");
WriterValidationUtils.ValidateStreamReferenceProperty(property, edmProperty, this.WritingResponse, this.bypassValidation);
this.WriteStreamReferenceProperty(propertyName, streamReferenceValue);
return;
}
string wirePropertyName = isTopLevel ? JsonLightConstants.ODataValuePropertyName : propertyName;
if (value is ODataNullValue || value == null)
{
WriterValidationUtils.ValidateNullPropertyValue(propertyTypeReference, propertyName, this.MessageWriterSettings.WriterBehavior, this.Model, this.bypassValidation);
if (isTopLevel)
{
// Write the special null marker for top-level null properties.
this.ODataAnnotationWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataNull);
this.JsonWriter.WriteValue(true);
}
else
{
this.JsonWriter.WriteName(wirePropertyName);
this.JsonLightValueSerializer.WriteNullValue();
}
return;
}
bool isOpenPropertyType = this.IsOpenProperty(property, owningType, edmProperty);
if (isOpenPropertyType && this.JsonLightOutputContext.MessageWriterSettings.EnableFullValidation)
{
ValidationUtils.ValidateOpenPropertyValue(propertyName, value);
}
ODataComplexValue complexValue = value as ODataComplexValue;
if (complexValue != null)
{
if (!isTopLevel)
{
this.JsonWriter.WriteName(wirePropertyName);
}
this.JsonLightValueSerializer.WriteComplexValue(complexValue, propertyTypeReference, isTopLevel, isOpenPropertyType, this.CreateDuplicatePropertyNamesChecker());
return;
}
IEdmTypeReference typeFromValue = TypeNameOracle.ResolveAndValidateTypeNameForValue(this.Model, propertyTypeReference, value, isOpenPropertyType);
ODataEnumValue enumValue = value as ODataEnumValue;
if (enumValue != null)
{
// This is a work around, needTypeOnWire always = true for client side:
// ClientEdmModel's reflection can't know a property is open type even if it is, so here
// make client side always write 'odata.type' for enum.
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ODataJsonLightPropertySerializer.cs
示例20: ReadTopLevelPropertyImplementation
/// <summary>
/// This method creates an reads the property from the input and
/// returns an <see cref="ODataProperty"/> representing the read property.
/// </summary>
/// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param>
/// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use.</param>
/// <returns>An <see cref="ODataProperty"/> representing the read property.</returns>
/// <remarks>
/// The method assumes that the ReadPayloadStart has already been called and it will not call ReadPayloadEnd.
/// </remarks>
private ODataProperty ReadTopLevelPropertyImplementation(IEdmTypeReference expectedPropertyTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
{
Debug.Assert(
expectedPropertyTypeReference == null || !expectedPropertyTypeReference.IsODataEntityTypeKind(),
"If the expected type is specified it must not be an entity type.");
Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
expectedPropertyTypeReference = this.UpdateExpectedTypeBasedOnContextUri(expectedPropertyTypeReference);
object propertyValue = missingPropertyValue;
var customInstanceAnnotations = new Collection<ODataInstanceAnnotation>();
// Check for the special top-level null marker
if (this.IsTopLevelNullValue())
{
// NOTE: when reading a null value we will never ask the type resolver (if present) to resolve the
// type; we always fall back to the expected type.
ReaderValidationUtils.ValidateNullValue(
this.Model,
expectedPropertyTypeReference,
this.MessageReaderSettings,
/*validateNullValue*/ true,
/*propertyName*/ null);
// We don't allow properties or non-custom annotations in the null payload.
this.ValidateNoPropertyInNullPayload(duplicatePropertyNamesChecker);
propertyValue = null;
}
else
{
string payloadTypeName = null;
if (this.ReadingComplexProperty(duplicatePropertyNamesChecker, expectedPropertyTypeReference, out payloadTypeName))
{
// Figure out whether we are reading a complex property or not; complex properties are not wrapped while all others are.
// Since we don't have metadata in all cases (open properties), we have to detect the type in some cases.
this.AssertJsonCondition(JsonNodeType.Property, JsonNodeType.EndObject);
// Now read the property value
propertyValue = this.ReadNonEntityValue(
payloadTypeName,
expectedPropertyTypeReference,
duplicatePropertyNamesChecker,
/*collectionValidator*/ null,
/*validateNullValue*/ true,
/*isTopLevelPropertyValue*/ true,
/*insideComplexValue*/ true,
/*propertyName*/ null);
}
else
{
bool isReordering = this.JsonReader is ReorderingJsonReader;
Func<string, object> propertyAnnotationReaderForTopLevelProperty =
annotationName => { throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedODataPropertyAnnotation(annotationName)); };
// Read through all top-level properties, ignore the ones with reserved names (i.e., reserved
// characters in their name) and throw if we find none or more than one properties without reserved name.
while (this.JsonReader.NodeType == JsonNodeType.Property)
{
this.ProcessProperty(
duplicatePropertyNamesChecker,
propertyAnnotationReaderForTopLevelProperty,
(propertyParsingResult, propertyName) =>
{
switch (propertyParsingResult)
{
case PropertyParsingResult.ODataInstanceAnnotation:
if (string.CompareOrdinal(ODataAnnotationNames.ODataType, propertyName) == 0)
{
// When we are not using the reordering reader we have to ensure that the 'odata.type' property appears before
// the 'value' property; otherwise we already scanned ahead and read the type name and have to now
// ignore it (even if it is after the 'value' property).
if (isReordering)
{
this.JsonReader.SkipValue();
}
else
{
if (!object.ReferenceEquals(missingPropertyValue, propertyValue))
{
throw new ODataException(
ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_TypePropertyAfterValueProperty(ODataAnnotationNames.ODataType, JsonLightConstants.ODataValuePropertyName));
}
payloadTypeName = this.ReadODataTypeAnnotationValue();
}
}
else
{
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:odata.net,代码行数:101,代码来源:ODataJsonLightPropertyAndValueDeserializer.cs
注:本文中的ODataProperty类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论