本文整理汇总了C#中IEdmPrimitiveTypeReference.ODataFullName方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference.ODataFullName方法的具体用法?C# IEdmPrimitiveTypeReference.ODataFullName怎么用?C# IEdmPrimitiveTypeReference.ODataFullName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmPrimitiveTypeReference
的用法示例。
在下文中一共展示了IEdmPrimitiveTypeReference.ODataFullName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertInt32Value
/// <summary>
/// Converts the given JSON int value to the expected type as per OData conversion rules for JSON values.
/// </summary>
/// <param name="intValue">Int32 value to the converted.</param>
/// <param name="targetType">Target type to which the int value needs to be converted.</param>
/// <param name="primitiveTypeReference">Type reference to which the value needs to be converted.</param>
/// <returns>Object which is in sync with the property type.</returns>
private static object ConvertInt32Value(int intValue, Type targetType, IEdmPrimitiveTypeReference primitiveTypeReference)
{
if (targetType == typeof(Int16))
{
return Convert.ToInt16(intValue);
}
if (targetType == typeof(Byte))
{
return Convert.ToByte(intValue);
}
if (targetType == typeof(SByte))
{
return Convert.ToSByte(intValue);
}
if (targetType == typeof(Single))
{
return Convert.ToSingle(intValue);
}
if (targetType == typeof(Double))
{
return Convert.ToDouble(intValue);
}
if (targetType == typeof(Decimal))
{
return Convert.ToDecimal(intValue);
}
if (targetType == typeof(Int64))
{
return Convert.ToInt64(intValue);
}
if (targetType != typeof(Int32))
{
throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_CannotConvertInt32(primitiveTypeReference.ODataFullName()));
}
return intValue;
}
示例2: GetPrimitiveTypeConversionException
/// <summary>
/// Creates an exception used when primitive type conversion fails.
/// </summary>
/// <param name="targetTypeReference">The target type reference to which the conversion failed.</param>
/// <param name="innerException">Possible inner exception with more information about the failure.</param>
/// <param name="stringValue">The string representation for the value.</param>
/// <returns>The exception object to throw.</returns>
internal static ODataException GetPrimitiveTypeConversionException(IEdmPrimitiveTypeReference targetTypeReference, Exception innerException, string stringValue)
{
Debug.Assert(targetTypeReference != null, "targetTypeReference != null");
return new ODataException(Strings.ReaderValidationUtils_CannotConvertPrimitiveValue(stringValue, targetTypeReference.ODataFullName()), innerException);
}
示例3: GetValueFromAttributeValueNotation
/// <summary>
/// Reads an annotation's value from the annotation value notation specified on the current element.
/// </summary>
/// <param name="expectedTypeReference">The expected type reference of the vocabulary term from the metadata.</param>
/// <param name="attributeValueNotationTypeReference">The type reference indicated by the name of the attribute used in attribute value notation.
/// For example, if the attribute was called "string", this will be a reference to the string type.</param>
/// <param name="attributeValueNotationAttributeName">The name of the attribute used by attribute avalue notation.</param>
/// <param name="attributeValueNotationAttributeValue">The value of the attribute used by attribute value notation.</param>
/// <param name="typeAttributeValue">The value of the "m:type" attribute on the annotation element.</param>
/// <param name="positionedOnEmptyElement">true if the annotation element is empty, false otherwise.</param>
/// <param name="model">The edm model instance.</param>
/// <param name="messageReaderSettings">The message reader settings instance.</param>
/// <returns>The primitive value represented on this element via attribute value notation.</returns>
private static ODataPrimitiveValue GetValueFromAttributeValueNotation(
IEdmTypeReference expectedTypeReference,
IEdmPrimitiveTypeReference attributeValueNotationTypeReference,
string attributeValueNotationAttributeName,
string attributeValueNotationAttributeValue,
string typeAttributeValue,
bool positionedOnEmptyElement,
IEdmModel model,
ODataMessageReaderSettings messageReaderSettings)
{
Debug.Assert(attributeValueNotationTypeReference != null, "attributeValueNotationTypeReference != null");
if (!positionedOnEmptyElement)
{
// If there is content in the body of the element, throw since it's ambiguous whether we should use the value from the attribute or the element content.
throw new ODataException(ODataErrorStrings.AtomInstanceAnnotation_AttributeValueNotationUsedOnNonEmptyElement(attributeValueNotationAttributeName));
}
// If both m:type is present and attribute value notation is being used, they must match.
// For example, if m:type is "Edm.Int32", but the "string" attribute is also present, we should throw.
if (typeAttributeValue != null && !string.Equals(attributeValueNotationTypeReference.Definition.ODataFullName(), typeAttributeValue, StringComparison.Ordinal))
{
throw new ODataException(ODataErrorStrings.AtomInstanceAnnotation_AttributeValueNotationUsedWithIncompatibleType(typeAttributeValue, attributeValueNotationAttributeName));
}
IEdmTypeReference targetTypeReference = ReaderValidationUtils.ResolveAndValidatePrimitiveTargetType(
expectedTypeReference,
EdmTypeKind.Primitive,
attributeValueNotationTypeReference.Definition,
attributeValueNotationTypeReference.ODataFullName(),
attributeValueNotationTypeReference.Definition,
model,
messageReaderSettings);
return new ODataPrimitiveValue(AtomValueUtils.ConvertStringToPrimitive(attributeValueNotationAttributeValue, targetTypeReference.AsPrimitive()));
}
示例4: ReadPrimitiveValue
/// <summary>
/// Reads a primitive value.
/// </summary>
/// <param name="insideJsonObjectValue">true if the reader is positioned on the first property of the value which is a JSON Object
/// (or the second property if the first one was odata.type).</param>
/// <param name="expectedValueTypeReference">The expected type reference of the value, or null if none is available.</param>
/// <param name="validateNullValue">true to validate null values; otherwise false.</param>
/// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
/// <returns>The value of the primitive value.</returns>
/// <remarks>
/// Pre-Condition: insideJsonObjectValue == false -> none - Fails if the current node is not a JsonNodeType.PrimitiveValue
/// insideJsonObjectValue == true -> JsonNodeType.Property or JsonNodeType.EndObject - the first property of the value object,
/// or the second property if first was odata.type, or the end-object.
/// Post-Condition: almost anything - the node after the primitive value.
/// </remarks>
private object ReadPrimitiveValue(bool insideJsonObjectValue, IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue, string propertyName)
{
object result;
if (expectedValueTypeReference != null && expectedValueTypeReference.IsSpatial())
{
result = ODataJsonReaderCoreUtils.ReadSpatialValue(
this.JsonReader,
insideJsonObjectValue,
this.JsonLightInputContext,
expectedValueTypeReference,
validateNullValue,
this.recursionDepth,
propertyName);
}
else
{
if (insideJsonObjectValue)
{
// We manually throw JSON exception here to get a nicer error message (we expect primitive value and got object).
// Otherwise the ReadPrimitiveValue would fail with something like "expected primitive value but found property/end object" which is rather confusing.
throw new ODataException(ODataErrorStrings.JsonReaderExtensions_UnexpectedNodeDetectedWithPropertyName(JsonNodeType.PrimitiveValue, JsonNodeType.StartObject, propertyName));
}
result = this.JsonReader.ReadPrimitiveValue();
if (expectedValueTypeReference != null)
{
if ((expectedValueTypeReference.IsDecimal() || expectedValueTypeReference.IsInt64())
&& result != null)
{
if ((result is string) ^ this.JsonReader.IsIeee754Compatible)
{
throw new ODataException(ODataErrorStrings.ODataJsonReaderUtils_ConflictBetweenInputFormatAndParameter(expectedValueTypeReference.ODataFullName()));
}
}
result = ODataJsonLightReaderUtils.ConvertValue(
result,
expectedValueTypeReference,
this.MessageReaderSettings,
validateNullValue,
propertyName,
this.Model.GetPayloadValueConverter());
}
else
{
if (result is Decimal)
{
// convert decimal back to double to follow legacy logic when target type is not specified and IEEE754Compatible=false.
// we may lose precision for some range of int64 and decimal.
return Convert.ToDouble((Decimal)result);
}
}
}
return result;
}
示例5: GetPrimitiveTypeConversionException
internal static ODataException GetPrimitiveTypeConversionException(IEdmPrimitiveTypeReference targetTypeReference, Exception innerException)
{
return new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_CannotConvertPrimitiveValue(targetTypeReference.ODataFullName()), innerException);
}