private static void SetMaterializedValueCore(ODataAnnotatable annotatableObject, object materializedValue) { MaterializerPropertyValue annotation = new MaterializerPropertyValue { Value = materializedValue }; annotatableObject.SetAnnotation<MaterializerPropertyValue>(annotation); }
/// <summary> /// Write raw annotatoins if hte property value has any. /// </summary> /// <param name="property">The property.</param> /// <param name="isODataTypeWritten">Outputs if odata.type annotation has been written to the wire.</param> /// <returns>True if raw annotations have been written.</returns> private bool TryWriteRawAnnotations(ODataProperty property, out bool isODataTypeWritten) { ODataUntypedValue untypedValueTmp = property.Value as ODataUntypedValue; ODataAnnotatable annotatableValue = (ODataAnnotatable)untypedValueTmp ?? (ODataAnnotatable)property.ODataValue; isODataTypeWritten = false; if (annotatableValue != null) { ODataJsonLightRawAnnotationSet tmpSet = annotatableValue.GetAnnotation <ODataJsonLightRawAnnotationSet>(); if (tmpSet != null) { foreach (KeyValuePair <string, string> kvp in tmpSet.Annotations) { bool isODataType = string.Equals(kvp.Key, ODataAnnotationNames.ODataType, StringComparison.OrdinalIgnoreCase); if (isODataType && (annotatableValue is ODataComplexValue)) { continue; // skip odata.type for complex value } this.JsonWriter.WriteName(string.Format(CultureInfo.InvariantCulture, "{0}@{1}", property.Name, kvp.Key)); this.JsonWriter.WriteRawString(kvp.Value); if (isODataType) { isODataTypeWritten = true; } } return(true); } } return(false); }
public static T GetAnnotation <T>(this ODataAnnotatable annotatable) where T : class { ExceptionUtils.CheckArgumentNotNull(annotatable, "annotatable"); return(InternalDictionary <T> .GetAnnotation(annotatable)); }
/// <summary> /// Gets the <see cref="EntityType"/> of the specified entry or feed payload element. /// </summary> /// <param name="payloadElement">The payload element to get the entity type for.</param> /// <param name="model">The model to find the entity type in.</param> /// <returns>The <see cref="EntityType"/> of the <paramref name="payloadElement"/>.</returns> public static IEdmEntityType GetPayloadElementEntityType(ODataAnnotatable payloadElement, EdmModel model) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.Assert( payloadElement is ODataEntry || payloadElement is ODataFeed, "Can only determine entity type for entry or feed payloads."); ODataFeed feed = payloadElement as ODataFeed; if (feed != null) { // A feed doesn't know it's type. If it doesn't have any entries we can't determine the type. var feedentry = feed.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>().FirstOrDefault(); if (feedentry != null) { return(model.FindDeclaredType(feedentry.TypeName) as IEdmEntityType); } return(null); } ODataEntry entry = payloadElement as ODataEntry; if (entry != null) { return(model.FindDeclaredType(entry.TypeName) as IEdmEntityType); } return(null); }
/// <summary> /// Gets the materialized value. /// </summary> /// <param name="annotatableObject">The annotatable object.</param> /// <returns>The materialized value</returns> private static object GetMaterializedValueCore(ODataAnnotatable annotatableObject) { MaterializerPropertyValue value = annotatableObject.GetAnnotation <MaterializerPropertyValue>(); Debug.Assert(value != null, "MaterializedValue not set"); return(value.Value); }
public static T GetAnnotation <T>(this ODataAnnotatable annotatable) where T : class { Debug.Assert(annotatable != null, "annotatable != null"); return(InternalDictionary <T> .GetAnnotation(annotatable)); }
public static void SetAnnotation <T>(this ODataAnnotatable annotatable, T annotation) where T : class { Debug.Assert(annotatable != null, "annotatable != null"); Debug.Assert(annotation != null, "annotation != null"); InternalDictionary <T> .SetAnnotation(annotatable, annotation); }
private static void SetMaterializedValueCore(ODataAnnotatable annotatableObject, object materializedValue) { MaterializerPropertyValue annotation = new MaterializerPropertyValue { Value = materializedValue }; annotatableObject.SetAnnotation <MaterializerPropertyValue>(annotation); }
public static void SetAnnotation <T>(this ODataAnnotatable annotatable, T annotation) where T : class { ExceptionUtils.CheckArgumentNotNull(annotatable, "annotatable"); ExceptionUtils.CheckArgumentNotNull(annotation, "annotation"); InternalDictionary <T> .SetAnnotation(annotatable, annotation); }
/// <summary> /// Converts the SerializationTypeNameAnnotation from the <paramref name="odataAnnotatable"/> into a SerializationTypeNameTestAnnotation /// added to the <paramref name="payloadElement"/>. /// </summary> /// <param name="odataAnnotatable">The OData OM value to get the annotation from.</param> /// <param name="payloadElement">The payload element to add the converted annotation to.</param> private void ConvertSerializationTypeNameAnnotation(ODataAnnotatable odataAnnotatable, ODataPayloadElement payloadElement) { if (odataAnnotatable.TypeAnnotation != null) { payloadElement.AddAnnotation(new SerializationTypeNameTestAnnotation { TypeName = odataAnnotatable.TypeAnnotation.TypeName }); } }
/// <summary> /// Marks the annotatable object such that it will inherit annotations from a base annotatable. /// </summary> /// <typeparam name="T">The type of the annotatable object to mark.</typeparam> /// <param name="annotatable">The annotatable object to mark.</param> /// <param name="baseAnnotatable">The base annotatable to inherit annotations from.</param> /// <returns>The annotatable object itself for composability.</returns> public static T InheritAnnotationsFrom <T>(this T annotatable, ODataAnnotatable baseAnnotatable) where T : ODataAnnotatable { ExceptionUtilities.CheckArgumentNotNull(annotatable, "annotatable"); ExceptionUtilities.CheckArgumentNotNull(baseAnnotatable, "baseAnnotatable"); ExceptionUtilities.Assert( annotatable.GetAnnotation <ODataAnnotatable>() == null, "Can't mark instance to inherit annotations for a second time."); annotatable.SetAnnotation(baseAnnotatable); return(annotatable); }
/// <summary> /// Gets the EDM type of an OData instance from the <see cref="ODataTypeAnnotation"/> of the instance (if available). /// </summary> /// <param name="annotatable">The OData instance to get the EDM type for.</param> /// <returns>The EDM type of the <paramref name="annotatable"/> if available in the <see cref="ODataTypeAnnotation"/> annotation.</returns> internal static IEdmTypeReference GetEdmType(this ODataAnnotatable annotatable) { if (annotatable == null) { return(null); } ODataTypeAnnotation typeAnnotation = annotatable.GetAnnotation <ODataTypeAnnotation>(); return(typeAnnotation == null ? null : typeAnnotation.Type); }
/// <summary> /// Converts the SerializationTypeNameAnnotation from the <paramref name="odataAnnotatable"/> into a SerializationTypeNameTestAnnotation /// added to the <paramref name="payloadElement"/>. /// </summary> /// <param name="odataAnnotatable">The OData OM value to get the annotation from.</param> /// <param name="payloadElement">The payload element to add the converted annotation to.</param> private void ConvertSerializationTypeNameAnnotation(ODataAnnotatable odataAnnotatable, ODataPayloadElement payloadElement) { SerializationTypeNameAnnotation serializationTypeNameAnnotation = odataAnnotatable.GetAnnotation <SerializationTypeNameAnnotation>(); if (serializationTypeNameAnnotation != null) { payloadElement.AddAnnotation(new SerializationTypeNameTestAnnotation { TypeName = serializationTypeNameAnnotation.TypeName }); } }
public static T GetAnnotation(ODataAnnotatable annotatable) { T annotation; if (Dictionary.TryGetValue(annotatable, out annotation)) { return(annotation); } return(default(T)); }
/// <summary> /// Gets the EDM type of an OData instance from the <see cref="ODataTypeAnnotation"/> of the instance (if available). /// </summary> /// <param name="annotatable">The OData instance to get the EDM type for.</param> /// <returns>The EDM type of the <paramref name="annotatable"/> if available in the <see cref="ODataTypeAnnotation"/> annotation.</returns> internal static IEdmTypeReference GetEdmType(this ODataAnnotatable annotatable) { DebugUtils.CheckNoExternalCallers(); if (annotatable == null) { return(null); } ODataTypeAnnotation typeAnnotation = annotatable.GetAnnotation <ODataTypeAnnotation>(); return(typeAnnotation == null ? null : typeAnnotation.Type); }
/// <summary> /// Sets the value of the CustomState for the specified annotatable. /// </summary> /// <param name="annotatable">The annotatable instance to set the CustomState for.</param> /// <param name="value">The value of the CustomState to set, will overwrite any existing value.</param> internal static void SetCustomState(this ODataAnnotatable annotatable, object value) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(annotatable != null, "annotatable != null"); CustomStateAnnotation annotation = annotatable.GetAnnotation <CustomStateAnnotation>(); if (annotation == null) { annotation = new CustomStateAnnotation(); } annotation.Value = value; annotatable.SetAnnotation(annotation); }
/// <summary> /// Returns the value of the CustomState for the specified annotatable. /// </summary> /// <param name="annotatable">The annotatable instance to get the CustomState for.</param> /// <returns>The value of the CustomState.</returns> internal static object GetCustomState(this ODataAnnotatable annotatable) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(annotatable != null, "annotatable != null"); CustomStateAnnotation annotation = annotatable.GetAnnotation <CustomStateAnnotation>(); if (annotation == null) { return(null); } else { return(annotation.Value); } }
/// <summary> /// Gets annotation from the object including inherited annotations. /// </summary> /// <typeparam name="T">The type of the annotation to get.</typeparam> /// <param name="annotatable">The annotatable to get the annotation from.</param> /// <returns>The annotation instance or null if no such annotation was found.</returns> public static T GetInheritedAnnotation <T>(this ODataAnnotatable annotatable) where T : class { ExceptionUtilities.CheckArgumentNotNull(annotatable, "annotatable"); T result = annotatable.GetAnnotation <T>(); if (result == null) { ODataAnnotatable baseAnnotatable = annotatable.GetAnnotation <ODataAnnotatable>(); if (baseAnnotatable != null) { result = baseAnnotatable.GetAnnotation <T>(); } } return(result); }
/// <summary> /// Gets the <see cref="EntityType"/> of the specified entry or feed payload element. /// </summary> /// <param name="payloadElement">The payload element to get the entity type for.</param> /// <param name="model">The model to find the entity type in.</param> /// <returns>The <see cref="EntityType"/> of the <paramref name="payloadElement"/>.</returns> public static IEdmEntityType GetPayloadElementEntityType(ODataAnnotatable payloadElement, EdmModel model) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.Assert( payloadElement is ODataResource || payloadElement is ODataResourceSet, "Can only determine entity type for entry or feed payloads."); ODataResource entry = payloadElement as ODataResource; if (entry != null) { return(model.FindDeclaredType(entry.TypeName) as IEdmEntityType); } return(null); }
private static object GetMaterializedValueCore(ODataAnnotatable annotatableObject) { return annotatableObject.GetAnnotation<MaterializerPropertyValue>().Value; }
public static void SetAnnotation(ODataAnnotatable annotatable, T annotation) { Dictionary.Add(annotatable, annotation); }
private static bool HasMaterializedValueCore(ODataAnnotatable annotatableObject) { return(annotatableObject.GetAnnotation <MaterializerPropertyValue>() != null); }
public static void SetMaterializedValue(this ODataProperty property, object materializedValue) { ODataAnnotatable annotatableObject = (property.Value as ODataAnnotatable) ?? property; SetMaterializedValueCore(annotatableObject, materializedValue); }
private static object GetMaterializedValueCore(ODataAnnotatable annotatableObject) { return(annotatableObject.GetAnnotation <MaterializerPropertyValue>().Value); }
public static bool HasMaterializedValue(this ODataProperty property) { ODataAnnotatable annotatableObject = (property.Value as ODataAnnotatable) ?? property; return(HasMaterializedValueCore(annotatableObject)); }
public ODataAnnotatableTests() { this.annotatable = new ODataResourceSet(); }
public ODataAnnotatableTests() { this.annotatable = new ODataFeed(); }
/// <summary> /// Gets the materialized value. /// </summary> /// <param name="property">The property.</param> /// <returns>The materialized value.</returns> public static object GetMaterializedValue(this ODataProperty property) { ODataAnnotatable annotatableObject = property.Value as ODataAnnotatable ?? property; return(GetMaterializedValueCore(annotatableObject)); }
public void TestInit() { this.annotatable = new ODataFeed(); }
public static void SetAnnotation(ODataAnnotatable annotatable, T annotation) { Dictionary[annotatable] = annotation; }
/// <summary> /// Gets the materialized value. /// </summary> /// <param name="annotatableObject">The annotatable object.</param> /// <returns>The materialized value</returns> private static object GetMaterializedValueCore(ODataAnnotatable annotatableObject) { MaterializerPropertyValue value = annotatableObject.GetAnnotation<MaterializerPropertyValue>(); Debug.Assert(value != null, "MaterializedValue not set"); return value.Value; }
/// <summary> /// Determines whether a value has been materialized. /// </summary> /// <param name="annotatableObject">The annotatable object.</param> /// <returns><c>true</c> if the value has been materialized; otherwise, <c>false</c>.</returns> private static bool HasMaterializedValueCore(ODataAnnotatable annotatableObject) { return annotatableObject.GetAnnotation<MaterializerPropertyValue>() != null; }