本文整理汇总了C#中ODataProperty类的典型用法代码示例。如果您正苦于以下问题:C# ODataProperty类的具体用法?C# ODataProperty怎么用?C# ODataProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataProperty类属于命名空间,在下文中一共展示了ODataProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToSetThePropertySerializationInfo
public void ShouldBeAbleToSetThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SetSerializationInfo(serializationInfo);
property.SerializationInfo.Should().BeSameAs(serializationInfo);
}
示例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();
});
}
示例3: ShouldBeAbleToClearThePropertySerializationInfo
public void ShouldBeAbleToClearThePropertySerializationInfo()
{
ODataProperty property = new ODataProperty();
ODataPropertySerializationInfo serializationInfo = new ODataPropertySerializationInfo();
property.SerializationInfo = serializationInfo;
property.SetSerializationInfo(null);
property.SerializationInfo.Should().BeNull();
}
示例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 });
}
示例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");
}
示例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\"}");
}
示例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();
}
示例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);
}
}
示例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");
}
示例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);
}
示例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 });
}
示例12: ODataPropertyTests
public ODataPropertyTests()
{
this.property = new ODataProperty();
}
示例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);
}
示例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();
}
示例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);
}