本文整理汇总了C#中IEdmPrimitiveTypeReference.FullName方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference.FullName方法的具体用法?C# IEdmPrimitiveTypeReference.FullName怎么用?C# IEdmPrimitiveTypeReference.FullName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmPrimitiveTypeReference
的用法示例。
在下文中一共展示了IEdmPrimitiveTypeReference.FullName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataPrimitiveValue primitive, IEdmPrimitiveTypeReference primitiveType,
ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
// Note that this annotation should not be used for Atom or JSON verbose formats, as it will interfere with
// the correct default behavior for those formats.
Contract.Assert(primitive != null);
object value = primitive.Value;
// Only add an annotation if we want to override ODataLib's default type name serialization behavior.
if (ShouldAddTypeNameAnnotation(metadataLevel))
{
string typeName;
// Provide the type name to serialize (or null to force it not to serialize).
if (ShouldSuppressTypeNameSerialization(value, metadataLevel))
{
typeName = null;
}
else
{
typeName = primitiveType.FullName();
}
primitive.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
}
示例2: 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.FullName()));
}
}
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;
}
示例3: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataPrimitiveValue primitive, IEdmPrimitiveTypeReference primitiveType,
ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
Contract.Assert(primitive != null);
object value = primitive.Value;
string typeName = null; // Set null to force the type name not to serialize.
// Provide the type name to serialize.
if (!ShouldSuppressTypeNameSerialization(value, metadataLevel))
{
typeName = primitiveType.FullName();
}
primitive.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
示例4: 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.FullName()), innerException);
}
示例5: ParseTypedLiteral
private object ParseTypedLiteral(IEdmPrimitiveTypeReference targetTypeReference)
{
object obj2;
if (!UriPrimitiveTypeParser.TryUriStringToPrimitive(this.CurrentToken.Text, targetTypeReference, out obj2))
{
throw ParseError(Microsoft.Data.OData.Strings.UriQueryExpressionParser_UnrecognizedLiteral(targetTypeReference.FullName(), this.CurrentToken.Text, this.CurrentToken.Position, this.ExpressionText));
}
this.NextToken();
return obj2;
}
示例6: 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.FullTypeName(), typeAttributeValue, StringComparison.Ordinal))
{
throw new ODataException(ODataErrorStrings.AtomInstanceAnnotation_AttributeValueNotationUsedWithIncompatibleType(typeAttributeValue, attributeValueNotationAttributeName));
}
IEdmTypeReference targetTypeReference = ReaderValidationUtils.ResolveAndValidatePrimitiveTargetType(
expectedTypeReference,
EdmTypeKind.Primitive,
attributeValueNotationTypeReference.Definition,
attributeValueNotationTypeReference.FullName(),
attributeValueNotationTypeReference.Definition,
model,
messageReaderSettings);
return new ODataPrimitiveValue(AtomValueUtils.ConvertStringToPrimitive(attributeValueNotationAttributeValue, targetTypeReference.AsPrimitive()));
}
示例7: ParseTypedLiteral
/// <summary>
/// Parses typed literals.
/// </summary>
/// <param name="targetTypeReference">Expected type to be parsed.</param>
/// <returns>The literal token produced by building the given literal.</returns>
private object ParseTypedLiteral(IEdmPrimitiveTypeReference targetTypeReference)
{
object targetValue;
if (!UriPrimitiveTypeParser.TryUriStringToPrimitive(this.CurrentToken.Text, targetTypeReference, out targetValue))
{
string message = o.Strings.UriQueryExpressionParser_UnrecognizedLiteral(
targetTypeReference.FullName(),
this.CurrentToken.Text,
this.CurrentToken.Position,
this.ExpressionText);
throw ParseError(message);
}
this.NextToken();
return targetValue;
}
示例8: ParseTypedLiteral
/// <summary>
/// Parses typed literals.
/// </summary>
/// <param name="expressionLexer">The expression lexer.</param>
/// <param name="targetTypeReference">Expected type to be parsed.</param>
/// <returns>The literal token produced by building the given literal.</returns>
private static object ParseTypedLiteral(this ExpressionLexer expressionLexer, IEdmPrimitiveTypeReference targetTypeReference)
{
object targetValue;
string reason;
if (!UriPrimitiveTypeParser.TryUriStringToPrimitive(expressionLexer.CurrentToken.Text, targetTypeReference, out targetValue, out reason))
{
string message;
if (reason == null)
{
message = ODataErrorStrings.UriQueryExpressionParser_UnrecognizedLiteral(
targetTypeReference.FullName(),
expressionLexer.CurrentToken.Text,
expressionLexer.CurrentToken.Position,
expressionLexer.ExpressionText);
}
else
{
message = ODataErrorStrings.UriQueryExpressionParser_UnrecognizedLiteralWithReason(
targetTypeReference.FullName(),
expressionLexer.CurrentToken.Text,
expressionLexer.CurrentToken.Position,
expressionLexer.ExpressionText,
reason);
}
throw new ODataException(message);
}
expressionLexer.NextToken();
return targetValue;
}
示例9: EnsurePrimitiveType
/// <summary>
/// Ensures a primitive type reference for a given primitive type kind.
/// </summary>
/// <param name="type">The possibly null type reference.</param>
/// <param name="primitiveKindFromValue">The primitive type kind to ensure.</param>
/// <returns>An <see cref="IEdmPrimitiveTypeReference"/> instance created for the <paramref name="primitiveKindFromValue"/>
/// if <paramref name="type"/> is null; if <paramref name="type"/> is not null, validates it and then returns it.</returns>
private static IEdmPrimitiveTypeReference EnsurePrimitiveType(IEdmPrimitiveTypeReference type, EdmPrimitiveTypeKind primitiveKindFromValue)
{
if (type == null)
{
type = EdmCoreModel.Instance.GetPrimitive(primitiveKindFromValue, /*isNullable*/ true);
}
else
{
EdmPrimitiveTypeKind primitiveKindFromType = type.PrimitiveDefinition().PrimitiveKind;
if (primitiveKindFromType != primitiveKindFromValue)
{
string typeName = type.FullName();
if (typeName == null)
{
throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKindNoTypeName(primitiveKindFromType.ToString(), primitiveKindFromValue.ToString()));
}
throw new ODataException(ErrorStrings.EdmValueUtils_IncorrectPrimitiveTypeKind(typeName, primitiveKindFromValue.ToString(), primitiveKindFromType.ToString()));
}
}
return type;
}
示例10: 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.FullName()));
}
return intValue;
}