本文整理汇总了C#中IEdmPrimitiveTypeReference类的典型用法代码示例。如果您正苦于以下问题:C# IEdmPrimitiveTypeReference类的具体用法?C# IEdmPrimitiveTypeReference怎么用?C# IEdmPrimitiveTypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IEdmPrimitiveTypeReference类属于命名空间,在下文中一共展示了IEdmPrimitiveTypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateODataPrimitiveValue
/// <summary>
/// Creates an <see cref="ODataPrimitiveValue"/> for the object represented by <paramref name="graph"/>.
/// </summary>
/// <param name="graph">The primitive value.</param>
/// <param name="primitiveType">The EDM primitive type of the value.</param>
/// <param name="writeContext">The serializer write context.</param>
/// <returns>The created <see cref="ODataPrimitiveValue"/>.</returns>
public override ODataPrimitiveValue CreateODataPrimitiveValue(
object graph,
IEdmPrimitiveTypeReference primitiveType,
ODataSerializerContext writeContext)
{
// The EDM type of the "graph" would override the EDM type of the property when
// OData Web API infers the primitiveType. Thus for "graph" of System.DateTime,
// the primitiveType is always Edm.DateTimeOffset.
//
// In EF, System.DateTime is used for SqlDate, SqlDateTime and SqlDateTime2.
// All of them have no time zone information thus it is safe to clear the time
// zone when converting the "graph" to a DateTimeOffset.
if (primitiveType != null && primitiveType.IsDateTimeOffset() && graph is DateTime)
{
// If DateTime.Kind equals Local, offset should equal the offset of the system's local time zone
if (((DateTime)graph).Kind == DateTimeKind.Local)
{
graph = new DateTimeOffset((DateTime)graph, TimeZoneInfo.Local.GetUtcOffset((DateTime)graph));
}
else
{
graph = new DateTimeOffset((DateTime)graph, TimeSpan.Zero);
}
}
return base.CreateODataPrimitiveValue(graph, primitiveType, writeContext);
}
示例2: ValueTypeMatchesJsonType
/// <summary>
/// Determines if the given primitive value is of a basic type where we can rely on just the JSON representation to convey type information.
/// If so, we don't have to write the type name.
/// </summary>
/// <param name="primitiveValue">The primitive value in question.</param>
/// <param name="valueTypeReference">The type of the primitive value.</param>
/// <returns>true if the given primitive value is of a basic JSON type, false otherwise.</returns>
internal static bool ValueTypeMatchesJsonType(ODataPrimitiveValue primitiveValue, IEdmPrimitiveTypeReference valueTypeReference)
{
#if ODATALIB
#endif
switch (valueTypeReference.PrimitiveKind())
{
// If the value being serialized is of a basic type where we can rely on just the JSON representation to convey type information, then never write the type name.
case EdmPrimitiveTypeKind.Int32:
case EdmPrimitiveTypeKind.String:
case EdmPrimitiveTypeKind.Boolean:
return true;
case EdmPrimitiveTypeKind.Double:
double doubleValue = (double)primitiveValue.Value;
// If a double value is positive infinity, negative infinity, or NaN, we serialize the double as a string.
// Thus the reader can't infer the type from the JSON representation, and we must write the type name explicitly
// (i.e., if the property is open or the property type is assumed to be unknown, as is the case when writing in full metadata mode).
return !IsDoubleValueSerializedAsString(doubleValue);
default:
return false;
}
}
示例3: GetBinaryOperatorResultType
/// <summary>
/// Compute the result type of a binary operator based on the type of its operands and the operator kind.
/// </summary>
/// <param name="typeReference">The type reference of the operators.</param>
/// <param name="operatorKind">The kind of operator.</param>
/// <returns>The result type reference of the binary operator.</returns>
internal static IEdmPrimitiveTypeReference GetBinaryOperatorResultType(IEdmPrimitiveTypeReference typeReference, BinaryOperatorKind operatorKind)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(typeReference != null, "type != null");
switch (operatorKind)
{
case BinaryOperatorKind.Or: // fall through
case BinaryOperatorKind.And: // fall through
case BinaryOperatorKind.Equal: // fall through
case BinaryOperatorKind.NotEqual: // fall through
case BinaryOperatorKind.GreaterThan: // fall through
case BinaryOperatorKind.GreaterThanOrEqual: // fall through
case BinaryOperatorKind.LessThan: // fall through
case BinaryOperatorKind.LessThanOrEqual:
return EdmCoreModel.Instance.GetBoolean(typeReference.IsNullable);
case BinaryOperatorKind.Add: // fall through
case BinaryOperatorKind.Subtract: // fall through
case BinaryOperatorKind.Multiply: // fall through
case BinaryOperatorKind.Divide: // fall through
case BinaryOperatorKind.Modulo:
return typeReference;
default:
throw new ODataException(Strings.General_InternalError(InternalErrorCodes.QueryNodeUtils_BinaryOperatorResultType_UnreachableCodepath));
}
}
示例4: CreateODataPrimitiveValue
/// <summary>
/// Creates an <see cref="ODataPrimitiveValue"/> for the object represented by <paramref name="graph"/>.
/// </summary>
/// <param name="graph">The primitive value.</param>
/// <param name="primitiveType">The EDM primitive type of the value.</param>
/// <param name="writeContext">The serializer write context.</param>
/// <returns>The created <see cref="ODataPrimitiveValue"/>.</returns>
public virtual ODataPrimitiveValue CreateODataPrimitiveValue(object graph, IEdmPrimitiveTypeReference primitiveType,
ODataSerializerContext writeContext)
{
ODataMetadataLevel metadataLevel = writeContext != null ? writeContext.MetadataLevel : ODataMetadataLevel.Default;
// TODO: Bug 467598: validate the type of the object being passed in here with the underlying primitive type.
return CreatePrimitive(graph, primitiveType, metadataLevel);
}
示例5: ReadPrimitiveValue
internal static object ReadPrimitiveValue(XmlReader reader, IEdmPrimitiveTypeReference primitiveTypeReference)
{
object obj2;
if (!PrimitiveConverter.Instance.TryTokenizeFromXml(reader, EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference), out obj2))
{
return ConvertStringToPrimitive(reader.ReadElementContentValue(), primitiveTypeReference);
}
return obj2;
}
示例6: ConvertPrimitiveValue
/// <summary>
/// Converts a primitive OData value to the corresponding <see cref="IEdmDelayedValue"/>.
/// </summary>
/// <param name="primitiveValue">The primitive OData value to convert.</param>
/// <param name="type">The <see cref="IEdmTypeReference"/> for the primitive value (if available).</param>
/// <returns>An <see cref="IEdmDelayedValue"/> for the <paramref name="primitiveValue"/>.</returns>
internal static IEdmDelayedValue ConvertPrimitiveValue(object primitiveValue, IEdmPrimitiveTypeReference type)
{
#if !ASTORIA_CLIENT
#endif
Debug.Assert(primitiveValue != null, "primitiveValue != null");
TypeCode typeCode = PlatformHelpers.GetTypeCode(primitiveValue.GetType());
switch (typeCode)
{
case TypeCode.Boolean:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Boolean);
return new EdmBooleanConstant(type, (bool)primitiveValue);
case TypeCode.Byte:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Byte);
return new EdmIntegerConstant(type, (byte)primitiveValue);
case TypeCode.SByte:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.SByte);
return new EdmIntegerConstant(type, (sbyte)primitiveValue);
case TypeCode.Int16:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int16);
return new EdmIntegerConstant(type, (Int16)primitiveValue);
case TypeCode.Int32:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int32);
return new EdmIntegerConstant(type, (Int32)primitiveValue);
case TypeCode.Int64:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Int64);
return new EdmIntegerConstant(type, (Int64)primitiveValue);
case TypeCode.Decimal:
IEdmDecimalTypeReference decimalType = (IEdmDecimalTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Decimal);
return new EdmDecimalConstant(decimalType, (decimal)primitiveValue);
case TypeCode.Single:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Single);
return new EdmFloatingConstant(type, (Single)primitiveValue);
case TypeCode.Double:
type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Double);
return new EdmFloatingConstant(type, (double)primitiveValue);
case TypeCode.String:
IEdmStringTypeReference stringType = (IEdmStringTypeReference)EnsurePrimitiveType(type, EdmPrimitiveTypeKind.String);
return new EdmStringConstant(stringType, (string)primitiveValue);
default:
return ConvertPrimitiveValueWithoutTypeCode(primitiveValue, type);
}
}
示例7: ReadPrimitiveValue
/// <summary>
/// Reads a value of an XML element and converts it to the target primitive value.
/// </summary>
/// <param name="reader">The XML reader to read the value from.</param>
/// <param name="primitiveTypeReference">The primitive type reference to convert the value to.</param>
/// <returns>The primitive value read.</returns>
/// <remarks>This method does not read null values, it only reads the actual element value (not its attributes).</remarks>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - the element to read the value for.
/// XmlNodeType.Attribute - an attribute on the element to read the value for.
/// Post-Condition: XmlNodeType.Element - the element was empty.
/// XmlNodeType.EndElement - the element had some value.
/// </remarks>
internal static object ReadPrimitiveValue(XmlReader reader, IEdmPrimitiveTypeReference primitiveTypeReference)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(reader != null, "reader != null");
object spatialValue;
if (!PrimitiveConverter.Instance.TryTokenizeFromXml(reader, EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference), out spatialValue))
{
string stringValue = reader.ReadElementContentValue();
return ConvertStringToPrimitive(stringValue, primitiveTypeReference);
}
return spatialValue;
}
示例8: ConvertToTaupoPrimitiveDataType
public static DataType ConvertToTaupoPrimitiveDataType(IEdmPrimitiveTypeReference edmPrimitiveTypeReference)
{
PrimitiveDataType result = null;
EdmPrimitiveTypeKind primitiveKind = edmPrimitiveTypeReference.PrimitiveKind();
if (!facetlessDataTypeLookup.TryGetValue(primitiveKind, out result))
{
switch (primitiveKind)
{
case EdmPrimitiveTypeKind.Binary:
var edmBinary = edmPrimitiveTypeReference.AsBinary();
result = EdmDataTypes.Binary(edmBinary.MaxLength);
break;
case EdmPrimitiveTypeKind.DateTimeOffset:
var edmDateTimeOffset = edmPrimitiveTypeReference.AsTemporal();
result = EdmDataTypes.DateTimeOffset(edmDateTimeOffset.Precision);
break;
case EdmPrimitiveTypeKind.Decimal:
var edmDecimal = edmPrimitiveTypeReference.AsDecimal();
result = EdmDataTypes.Decimal(edmDecimal.Precision, edmDecimal.Scale);
break;
case EdmPrimitiveTypeKind.String:
var edmString = edmPrimitiveTypeReference.AsString();
var maxLength = edmString.MaxLength;
if (edmString.IsUnbounded == true)
{
maxLength = MaxLengthMaxTaupoDefaultValue;
}
result = EdmDataTypes.String(maxLength, edmString.IsUnicode);
break;
case EdmPrimitiveTypeKind.Duration:
var edmTime = edmPrimitiveTypeReference.AsTemporal();
result = EdmDataTypes.Time(edmTime.Precision);
break;
default:
throw new TaupoInvalidOperationException("unexpected Edm Primitive Type Kind: " + primitiveKind);
}
}
return result.Nullable(edmPrimitiveTypeReference.IsNullable);
}
示例9: ReadSpatialValue
/// <summary>
/// Try and parse spatial type from the json payload.
/// </summary>
/// <param name="jsonReader">The JSON reader to read from.</param>
/// <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="inputContext">The input context with all the settings.</param>
/// <param name="expectedValueTypeReference">Expected edm property type.</param>
/// <param name="validateNullValue">true to validate null values; otherwise false.</param>
/// <param name="recursionDepth">The recursion depth to start with.</param>
/// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
/// <returns>An instance of the spatial type.</returns>
internal static ISpatial ReadSpatialValue(
BufferingJsonReader jsonReader,
bool insideJsonObjectValue,
ODataInputContext inputContext,
IEdmPrimitiveTypeReference expectedValueTypeReference,
bool validateNullValue,
int recursionDepth,
string propertyName)
{
Debug.Assert(jsonReader != null, "jsonReader != null");
Debug.Assert(inputContext != null, "inputContext != null");
Debug.Assert(expectedValueTypeReference != null, "expectedValueTypeReference != null");
Debug.Assert(expectedValueTypeReference.IsSpatial(), "TryParseSpatialType must be called only with spatial types");
// Spatial value can be either null constant or a JSON object
// If it's a null primitive value, report a null value.
if (!insideJsonObjectValue && TryReadNullValue(jsonReader, inputContext, expectedValueTypeReference, validateNullValue, propertyName))
{
return null;
}
Microsoft.Spatial.ISpatial spatialValue = null;
if (insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.StartObject)
{
IDictionary<string, object> jsonObject = ReadObjectValue(jsonReader, insideJsonObjectValue, inputContext, recursionDepth);
Microsoft.Spatial.GeoJsonObjectFormatter jsonObjectFormatter =
Microsoft.Spatial.SpatialImplementation.CurrentImplementation.CreateGeoJsonObjectFormatter();
if (EdmLibraryExtensions.IsGeographyType(expectedValueTypeReference))
{
spatialValue = jsonObjectFormatter.Read<Microsoft.Spatial.Geography>(jsonObject);
}
else
{
spatialValue = jsonObjectFormatter.Read<Microsoft.Spatial.Geometry>(jsonObject);
}
}
if (spatialValue == null)
{
throw new ODataException(ODataErrorStrings.ODataJsonReaderCoreUtils_CannotReadSpatialPropertyValue);
}
return spatialValue;
}
示例10: CreateODataPrimitiveValue
public override ODataPrimitiveValue CreateODataPrimitiveValue(object graph, IEdmPrimitiveTypeReference primitiveType,
ODataSerializerContext writeContext)
{
var dbGeographyValue = graph as DbGeography;
if (dbGeographyValue != null)
{
// The logic is not included in Restier as publisher layer does not touch provider layer type
if (dbGeographyValue.SpatialTypeName == GeographyTypeNamePoint)
{
graph = dbGeographyValue.ToGeographyPoint();
}
else if (dbGeographyValue.SpatialTypeName == GeographyTypeNameLineString)
{
graph = dbGeographyValue.ToGeographyLineString();
}
else if (dbGeographyValue.SpatialTypeName == GeographyTypeNamePolygon)
{
// TODO, convert original value and return converted value
}
}
return base.CreateODataPrimitiveValue(graph, primitiveType, writeContext);
}
示例11: 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
});
}
}
示例12: 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
});
}
示例13: ODataPrimitiveSerializer
public ODataPrimitiveSerializer(IEdmPrimitiveTypeReference edmPrimitiveType)
: base(edmPrimitiveType, ODataPayloadKind.Property)
{
}
示例14: ReadPrimitiveValue
/// <summary>
/// Read a primitive value from the reader.
/// </summary>
/// <param name="actualValueTypeReference">The type of the value to read.</param>
/// <returns>The value read from the payload and converted as appropriate to the target type.</returns>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - the element to read the value for.
/// XmlNodeType.Attribute - an attribute on the element to read the value for.
/// Post-Condition: XmlNodeType.Element - the element was empty.
/// XmlNodeType.EndElement - the element had some value.
///
/// Note that this method will not read null values, those should be handled by the caller already.
/// </remarks>
private object ReadPrimitiveValue(IEdmPrimitiveTypeReference actualValueTypeReference)
{
Debug.Assert(actualValueTypeReference != null, "actualValueTypeReference != null");
Debug.Assert(actualValueTypeReference.TypeKind() == EdmTypeKind.Primitive, "Only primitive values can be read by this method.");
this.AssertXmlCondition(XmlNodeType.Element, XmlNodeType.Attribute);
object result = AtomValueUtils.ReadPrimitiveValue(this.XmlReader, actualValueTypeReference);
this.AssertXmlCondition(true, XmlNodeType.EndElement);
Debug.Assert(result != null, "The method should never return null since it doesn't handle null values.");
return result;
}
示例15: CreatePrimitive
internal static ODataPrimitiveValue CreatePrimitive(object value, IEdmPrimitiveTypeReference primitveType,
ODataMetadataLevel metadataLevel)
{
if (value == null)
{
return null;
}
object supportedValue = ConvertUnsupportedPrimitives(value);
ODataPrimitiveValue primitive = new ODataPrimitiveValue(supportedValue);
AddTypeNameAnnotationAsNeeded(primitive, primitveType, metadataLevel);
return primitive;
}