/// <summary> /// Given a property value returns the text value to be used in EPM. /// </summary> /// <param name="propertyValue">The value of the property.</param> /// <returns>The text representation of the value, or the method throws if the text representation was not possible to obtain.</returns> internal static string GetPropertyValueAsText(object propertyValue) { DebugUtils.CheckNoExternalCallers(); if (propertyValue == null) { return(null); } return(AtomValueUtils.ConvertPrimitiveToString(propertyValue)); }
/// <summary> /// Writes the value of a primitive instance annotation. /// </summary> /// <param name="primitiveValue">The primitive value to write.</param> /// <param name="expectedTypeReference">The expected type of the annotation from the metadata.</param> private void WritePrimitiveInstanceAnnotationValue(ODataPrimitiveValue primitiveValue, IEdmTypeReference expectedTypeReference) { object clrValue = primitiveValue.Value; IEdmPrimitiveTypeReference primitiveTypeReference = EdmLibraryExtensions.GetPrimitiveTypeReference(clrValue.GetType()); string attributeValueNotationName = AtomInstanceAnnotation.LookupAttributeValueNotationNameByEdmTypeKind(primitiveTypeReference.PrimitiveKind()); // Some primitive values can be specified more concisely via an attribute rather than in the content of the xml element. This is called "attribute value notation". // If we're writing a type that supports this, then we always prefer attribute value notation over writing the value in the element content. if (attributeValueNotationName != null) { if (expectedTypeReference != null) { ValidationUtils.ValidateIsExpectedPrimitiveType(primitiveValue.Value, primitiveTypeReference, expectedTypeReference); } this.XmlWriter.WriteAttributeString(attributeValueNotationName, AtomValueUtils.ConvertPrimitiveToString(clrValue)); } else { this.WritePrimitiveValue(clrValue, /*collectionValidator*/ null, expectedTypeReference, primitiveValue.GetAnnotation <SerializationTypeNameAnnotation>()); } }