本文整理汇总了C#中IEdmTypeReference.AsPrimitiveOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.AsPrimitiveOrNull方法的具体用法?C# IEdmTypeReference.AsPrimitiveOrNull怎么用?C# IEdmTypeReference.AsPrimitiveOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.AsPrimitiveOrNull方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConvertTo
internal static bool CanConvertTo(IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
{
if (sourceReference.IsEquivalentTo(targetReference))
{
return true;
}
if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
{
return ((IEdmStructuredType) targetReference.Definition).IsAssignableFrom(((IEdmStructuredType) sourceReference.Definition));
}
if (IsOpenPropertyType(targetReference))
{
return true;
}
IEdmPrimitiveTypeReference type = sourceReference.AsPrimitiveOrNull();
IEdmPrimitiveTypeReference reference2 = targetReference.AsPrimitiveOrNull();
return (((type != null) && (reference2 != null)) && MetadataUtilsCommon.CanConvertPrimitiveTypeTo(type.PrimitiveDefinition(), reference2.PrimitiveDefinition()));
}
示例2: VerifyAndCoerceUriPrimitiveLiteral
internal static object VerifyAndCoerceUriPrimitiveLiteral(object primitiveValue, IEdmModel model, IEdmTypeReference expectedTypeReference, ODataVersion version)
{
ExceptionUtils.CheckArgumentNotNull<object>(primitiveValue, "primitiveValue");
ExceptionUtils.CheckArgumentNotNull<IEdmModel>(model, "model");
ExceptionUtils.CheckArgumentNotNull<IEdmTypeReference>(expectedTypeReference, "expectedTypeReference");
ODataUriNullValue value2 = primitiveValue as ODataUriNullValue;
if (value2 != null)
{
if (!expectedTypeReference.IsNullable)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralNullOnNonNullableType(expectedTypeReference.ODataFullName()));
}
IEdmType type = ValidationUtils.ValidateValueTypeName(model, value2.TypeName, expectedTypeReference.Definition.TypeKind);
if (type.IsSpatial())
{
ODataVersionChecker.CheckSpatialValue(version);
}
if (!TypePromotionUtils.CanConvertTo(type.ToTypeReference(), expectedTypeReference))
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralNullTypeVerificationFailure(expectedTypeReference.ODataFullName(), value2.TypeName));
}
value2.TypeName = expectedTypeReference.ODataFullName();
return value2;
}
IEdmPrimitiveTypeReference reference = expectedTypeReference.AsPrimitiveOrNull();
if (reference == null)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedTypeReference.ODataFullName(), primitiveValue));
}
object obj2 = CoerceNumericType(primitiveValue, reference.PrimitiveDefinition());
if (obj2 != null)
{
return obj2;
}
Type c = primitiveValue.GetType();
if (!TypeUtils.GetNonNullableType(EdmLibraryExtensions.GetPrimitiveClrType(reference)).IsAssignableFrom(c))
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(reference.ODataFullName(), primitiveValue));
}
return primitiveValue;
}
示例3: TryUriStringToPrimitive
internal static bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, out object targetValue, out string reason)
{
Debug.Assert(text != null, "text != null");
Debug.Assert(targetType != null, "targetType != null");
reason = null;
if (targetType.IsNullable)
{
// COMPAT 38: Product does not support "null" literals in service operation arguments
// check for the 'null' constant for nullable types
if (text == ExpressionConstants.KeywordNull)
{
targetValue = null;
return true;
}
}
IEdmPrimitiveTypeReference primitiveTargetType = targetType.AsPrimitiveOrNull();
if (primitiveTargetType == null)
{
targetValue = null;
return false;
}
EdmPrimitiveTypeKind targetTypeKind = primitiveTargetType.PrimitiveKind();
byte[] byteArrayValue;
bool binaryResult = TryUriStringToByteArray(text, out byteArrayValue);
if (targetTypeKind == EdmPrimitiveTypeKind.Binary)
{
targetValue = (object)byteArrayValue;
return binaryResult;
}
else if (binaryResult)
{
string keyValue = Encoding.UTF8.GetString(byteArrayValue, 0, byteArrayValue.Length);
return TryUriStringToPrimitive(keyValue, targetType, out targetValue);
}
else if (targetTypeKind == EdmPrimitiveTypeKind.Guid)
{
Guid guidValue;
bool result = UriUtils.TryUriStringToGuid(text, out guidValue);
targetValue = guidValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.Date)
{
Date dateValue;
bool result = UriUtils.TryUriStringToDate(text, out dateValue);
targetValue = dateValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.DateTimeOffset)
{
DateTimeOffset dateTimeOffsetValue;
bool result = UriUtils.TryUriStringToDateTimeOffset(text, out dateTimeOffsetValue);
targetValue = dateTimeOffsetValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.Duration)
{
TimeSpan timespanValue;
bool result = TryUriStringToDuration(text, out timespanValue);
targetValue = timespanValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.Geography)
{
Geography geographyValue;
bool result = TryUriStringToGeography(text, out geographyValue, out reason);
targetValue = geographyValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.Geometry)
{
Geometry geometryValue;
bool result = TryUriStringToGeometry(text, out geometryValue, out reason);
targetValue = geometryValue;
return result;
}
else if (targetTypeKind == EdmPrimitiveTypeKind.TimeOfDay)
{
TimeOfDay timeOfDayValue;
bool result = UriUtils.TryUriStringToTimeOfDay(text, out timeOfDayValue);
targetValue = timeOfDayValue;
return result;
}
bool quoted = targetTypeKind == EdmPrimitiveTypeKind.String;
if (quoted != IsUriValueQuoted(text))
{
targetValue = null;
return false;
}
if (quoted)
{
text = RemoveQuotes(text);
}
//.........这里部分代码省略.........
示例4: GetNumericTypeKind
/// <summary>Gets a flag for the numeric kind of type.</summary>
/// <param name="typeReference">Type to get numeric kind for.</param>
/// <returns>The <see cref="NumericTypeKind"/> of the <paramref name="typeReference"/> argument.</returns>
private static NumericTypeKind GetNumericTypeKind(IEdmTypeReference typeReference)
{
IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();
if (primitiveTypeReference == null)
{
return NumericTypeKind.NotNumeric;
}
switch (primitiveTypeReference.PrimitiveDefinition().PrimitiveKind)
{
case EdmPrimitiveTypeKind.Single:
case EdmPrimitiveTypeKind.Decimal:
case EdmPrimitiveTypeKind.Double:
return NumericTypeKind.NotIntegral;
case EdmPrimitiveTypeKind.Int16:
case EdmPrimitiveTypeKind.Int32:
case EdmPrimitiveTypeKind.Int64:
case EdmPrimitiveTypeKind.SByte:
return NumericTypeKind.SignedIntegral;
case EdmPrimitiveTypeKind.Byte:
return NumericTypeKind.UnsignedIntegral;
default:
return NumericTypeKind.NotNumeric;
}
}
示例5: IsDoubleOrSingle
/// <summary>Checks if the specified type is either double or single or the nullable variants.</summary>
/// <param name="typeReference">Type to check.</param>
/// <returns>true if <paramref name="typeReference"/> is double, single or nullable double or single; false otherwise.</returns>
private static bool IsDoubleOrSingle(IEdmTypeReference typeReference)
{
IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();
if (primitiveTypeReference != null)
{
EdmPrimitiveTypeKind primitiveTypeKind = primitiveTypeReference.PrimitiveKind();
return primitiveTypeKind == EdmPrimitiveTypeKind.Double || primitiveTypeKind == EdmPrimitiveTypeKind.Single;
}
return false;
}
示例6: IsDecimalType
/// <summary>Checks if the specified type is a decimal or nullable decimal type.</summary>
/// <param name="typeReference">Type to check.</param>
/// <returns>true if <paramref name="typeReference"/> is either decimal or nullable decimal type; false otherwise.</returns>
private static bool IsDecimalType(IEdmTypeReference typeReference)
{
IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();
if (primitiveTypeReference != null)
{
return primitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.Decimal;
}
return false;
}
示例7: IsDateTimeOffset
/// <summary>Checks if the specified type is a DateTimeOffset or nullable DateTimeOffset type.</summary>
/// <param name="typeReference">Type to check.</param>
/// <returns>true if <paramref name="typeReference"/> is either DateTimeOffset or nullable DateTimeOffset type; false otherwise.</returns>
private static bool IsDateTimeOffset(IEdmTypeReference typeReference)
{
IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();
if (primitiveTypeReference != null)
{
return primitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.DateTimeOffset;
}
return false;
}
示例8: CanConvertTo
internal static bool CanConvertTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
{
Debug.Assert(sourceReference != null, "sourceReference != null");
Debug.Assert(targetReference != null, "targetReference != null");
//// Copy of the ResourceQueryParser.ExpressionParser.IsCompatibleWith method.
if (sourceReference.IsEquivalentTo(targetReference))
{
return true;
}
if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
{
// for structured types, use IsAssignableFrom
return EdmLibraryExtensions.IsAssignableFrom(
(IEdmStructuredType)targetReference.Definition,
(IEdmStructuredType)sourceReference.Definition);
}
//// This rule stops the parser from considering nullable types as incompatible
//// with non-nullable types. We have however implemented this rule because we just
//// access underlying rules. C# requires an explicit .Value access, and EDM has no
//// nullablity on types and (at the model level) implements null propagation.
////
//// if (sourceReference.IsNullable && !targetReference.IsNullable)
//// {
//// return false;
//// }
if (sourceReference.IsEnum() && targetReference.IsEnum())
{
if (sourceReference.Definition.IsEquivalentTo(targetReference.Definition))
{
return targetReference.IsNullable() || (!sourceReference.IsNullable());
}
return false;
}
IEdmPrimitiveTypeReference sourcePrimitiveTypeReference = sourceReference.AsPrimitiveOrNull();
IEdmPrimitiveTypeReference targetPrimitiveTypeReference = targetReference.AsPrimitiveOrNull();
if (sourcePrimitiveTypeReference == null || targetPrimitiveTypeReference == null)
{
return false;
}
return MetadataUtilsCommon.CanConvertPrimitiveTypeTo(sourceNodeOrNull, sourcePrimitiveTypeReference.PrimitiveDefinition(), targetPrimitiveTypeReference.PrimitiveDefinition());
}
示例9: IsOpenPropertyType
private static bool IsOpenPropertyType(IEdmTypeReference typeReference)
{
IEdmPrimitiveTypeReference type = typeReference.AsPrimitiveOrNull();
return ((type != null) && (type.PrimitiveKind() == EdmPrimitiveTypeKind.None));
}
示例10: TryUriStringToPrimitive
internal static bool TryUriStringToPrimitive(string text, IEdmTypeReference targetType, out object targetValue)
{
byte[] buffer;
bool flag9;
if (targetType.IsNullable && (text == "null"))
{
targetValue = null;
return true;
}
IEdmPrimitiveTypeReference type = targetType.AsPrimitiveOrNull();
if (type == null)
{
targetValue = null;
return false;
}
EdmPrimitiveTypeKind kind = type.PrimitiveKind();
bool flag = TryUriStringToByteArray(text, out buffer);
if (kind == EdmPrimitiveTypeKind.Binary)
{
targetValue = buffer;
return flag;
}
if (flag)
{
return TryUriStringToPrimitive(Encoding.UTF8.GetString(buffer, 0, buffer.Length), targetType, out targetValue);
}
switch (kind)
{
case EdmPrimitiveTypeKind.Guid:
{
Guid guid;
bool flag2 = TryUriStringToGuid(text, out guid);
targetValue = guid;
return flag2;
}
case EdmPrimitiveTypeKind.DateTime:
{
DateTime time;
bool flag3 = TryUriStringToDateTime(text, out time);
targetValue = time;
return flag3;
}
case EdmPrimitiveTypeKind.DateTimeOffset:
{
DateTimeOffset offset;
bool flag4 = TryUriStringToDateTimeOffset(text, out offset);
targetValue = offset;
return flag4;
}
case EdmPrimitiveTypeKind.Time:
{
TimeSpan span;
bool flag5 = TryUriStringToTime(text, out span);
targetValue = span;
return flag5;
}
case EdmPrimitiveTypeKind.Geography:
{
Geography geography;
bool flag6 = TryUriStringToGeography(text, out geography);
targetValue = geography;
return flag6;
}
case EdmPrimitiveTypeKind.Geometry:
{
Geometry geometry;
bool flag7 = TryUriStringToGeometry(text, out geometry);
targetValue = geometry;
return flag7;
}
}
bool flag8 = kind == EdmPrimitiveTypeKind.String;
if (flag8 != IsUriValueQuoted(text))
{
targetValue = null;
return false;
}
if (flag8)
{
text = RemoveQuotes(text);
}
try
{
switch (kind)
{
case EdmPrimitiveTypeKind.Boolean:
targetValue = XmlConvert.ToBoolean(text);
goto Label_02B3;
case EdmPrimitiveTypeKind.Byte:
targetValue = XmlConvert.ToByte(text);
goto Label_02B3;
case EdmPrimitiveTypeKind.Decimal:
if (TryRemoveLiteralSuffix("M", ref text))
{
try
{
targetValue = XmlConvert.ToDecimal(text);
goto Label_02B3;
//.........这里部分代码省略.........
示例11: IsOpenPropertyType
/// <summary>Checks if the specified type reference is an open type.</summary>
/// <param name="typeReference">Type to check.</param>
/// <returns>true if <paramref name="typeReference"/> is an open type; false otherwise.</returns>
private static bool IsOpenPropertyType(IEdmTypeReference typeReference)
{
// TODO: the product treats open properties as object-typed (System.Object). Using TypeKind.None for now
// but likely to have to change when we start supporting open properties.
IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitiveOrNull();
if (primitiveTypeReference != null)
{
return primitiveTypeReference.PrimitiveKind() == EdmPrimitiveTypeKind.None;
}
return false;
}
示例12: VerifyAndCoerceUriPrimitiveLiteral
/// <summary>
/// Verifies that the given <paramref name="primitiveValue"/> is or can be coerced to <paramref name="expectedTypeReference"/>, and coerces it if necessary.
/// </summary>
/// <param name="primitiveValue">An EDM primitive value to verify.</param>
/// <param name="literalValue">The literal value that was parsed as this primitiveValue.</param>
/// <param name="model">Model to verify against.</param>
/// <param name="expectedTypeReference">Expected type reference.</param>
/// <returns>Coerced version of the <paramref name="primitiveValue"/>.</returns>
internal static object VerifyAndCoerceUriPrimitiveLiteral(
object primitiveValue,
string literalValue,
IEdmModel model,
IEdmTypeReference expectedTypeReference)
{
ExceptionUtils.CheckArgumentNotNull(primitiveValue, "primitiveValue");
ExceptionUtils.CheckArgumentNotNull(literalValue, "literalValue");
ExceptionUtils.CheckArgumentNotNull(model, "model");
ExceptionUtils.CheckArgumentNotNull(expectedTypeReference, "expectedTypeReference");
// First deal with null literal
ODataNullValue nullValue = primitiveValue as ODataNullValue;
if (nullValue != null)
{
if (!expectedTypeReference.IsNullable)
{
throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralNullOnNonNullableType(expectedTypeReference.FullName()));
}
return nullValue;
}
// Only other positive case is a numeric primitive that needs to be coerced
IEdmPrimitiveTypeReference expectedPrimitiveTypeReference = expectedTypeReference.AsPrimitiveOrNull();
if (expectedPrimitiveTypeReference == null)
{
throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedTypeReference.FullName(), literalValue));
}
object coercedResult = CoerceNumericType(primitiveValue, expectedPrimitiveTypeReference.PrimitiveDefinition());
if (coercedResult != null)
{
return coercedResult;
}
// if expectedTypeReference is set, need to coerce cast
coercedResult = CoerceTemporalType(primitiveValue, expectedPrimitiveTypeReference.PrimitiveDefinition());
if (coercedResult != null)
{
return coercedResult;
}
Type actualType = primitiveValue.GetType();
Type targetType = TypeUtils.GetNonNullableType(EdmLibraryExtensions.GetPrimitiveClrType(expectedPrimitiveTypeReference));
// If target type is assignable from actual type, we're OK
if (targetType.IsAssignableFrom(actualType))
{
return primitiveValue;
}
throw new ODataException(ODataErrorStrings.ODataUriUtils_ConvertFromUriLiteralTypeVerificationFailure(expectedPrimitiveTypeReference.FullName(), literalValue));
}