本文整理汇总了C#中IEdmTypeReference.IsEnum方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsEnum方法的具体用法?C# IEdmTypeReference.IsEnum怎么用?C# IEdmTypeReference.IsEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsEnum方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEdmTypeDeserializer
/// <inheritdoc />
public override ODataEdmTypeDeserializer GetEdmTypeDeserializer(IEdmTypeReference edmType)
{
if (edmType.IsEnum())
{
return this.enumDeserializer;
}
return base.GetEdmTypeDeserializer(edmType);
}
示例2: CreateODataValue
/// <inheritdoc/>
public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)
{
if (!expectedType.IsEnum())
{
throw Error.InvalidOperation(SRResources.CannotWriteType, typeof(ODataEnumSerializer).Name, expectedType.FullName());
}
ODataEnumValue value = CreateODataEnumValue(graph, expectedType.AsEnum(), writeContext);
if (value == null)
{
return new ODataNullValue();
}
return value;
}
示例3: ReadWithExpectedType
/// <summary>
/// Reads a value from the message reader.
/// </summary>
/// <param name="expectedClientType">The expected client type being materialized into.</param>
/// <param name="expectedReaderType">The expected type for the underlying reader.</param>
protected override void ReadWithExpectedType(IEdmTypeReference expectedClientType, IEdmTypeReference expectedReaderType)
{
ODataProperty property = this.messageReader.ReadProperty(expectedReaderType);
Type underlyingExpectedType = Nullable.GetUnderlyingType(this.ExpectedType) ?? this.ExpectedType;
object propertyValue = property.Value;
if (expectedClientType.IsCollection())
{
Debug.Assert(WebUtil.IsCLRTypeCollection(underlyingExpectedType, this.MaterializerContext.Model) || (SingleResult.HasValue && !SingleResult.Value), "expected type must be collection or single result must be false");
// We are here for two cases:
// (1) Something like Execute<ICollection<T>>, in which case the underlyingExpectedType is ICollection<T>
// (2) Execute<T> with the bool singleValue = false, in which case underlyingExpectedType is T
Type collectionItemType = this.ExpectedType;
Type collectionICollectionType = ClientTypeUtil.GetImplementationType(underlyingExpectedType, typeof(ICollection<>));
object collectionInstance;
if (collectionICollectionType != null)
{
// Case 1
collectionItemType = collectionICollectionType.GetGenericArguments()[0];
collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionPropertyInstance(property, underlyingExpectedType);
}
else
{
// Case 2
collectionICollectionType = typeof(ICollection<>).MakeGenericType(new Type[] { collectionItemType });
collectionInstance = this.CollectionValueMaterializationPolicy.CreateCollectionPropertyInstance(property, collectionICollectionType);
}
bool isElementNullable = expectedClientType.AsCollection().ElementType().IsNullable;
this.CollectionValueMaterializationPolicy.ApplyCollectionDataValues(
property,
collectionInstance,
collectionItemType,
ClientTypeUtil.GetAddToCollectionDelegate(collectionICollectionType),
isElementNullable);
this.currentValue = collectionInstance;
}
else if (expectedClientType.IsComplex())
{
ODataComplexValue complexValue = propertyValue as ODataComplexValue;
Debug.Assert(this.MaterializerContext.Model.GetOrCreateEdmType(underlyingExpectedType).ToEdmTypeReference(false).IsComplex(), "expectedType must be complex type");
this.ComplexValueMaterializationPolicy.MaterializeComplexTypeProperty(underlyingExpectedType, complexValue);
this.currentValue = complexValue.GetMaterializedValue();
}
else if (expectedClientType.IsEnum())
{
this.currentValue = this.EnumValueMaterializationPolicy.MaterializeEnumTypeProperty(underlyingExpectedType, property);
}
else
{
Debug.Assert(this.MaterializerContext.Model.GetOrCreateEdmType(underlyingExpectedType).ToEdmTypeReference(false).IsPrimitive(), "expectedType must be primitive type");
this.currentValue = this.PrimitivePropertyConverter.ConvertPrimitiveValue(property.Value, this.ExpectedType);
}
}
示例4: 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());
}
示例5: PromoteOperandTypes
/// <summary>Checks that the operands (possibly promoted) are valid for the specified operation.</summary>
/// <param name="operatorKind">The operator kind to promote the operand types for.</param>
/// <param name="leftNode">The left operand node.</param>
/// <param name="rightNode">The right operand node.</param>
/// <param name="left">The left operand type after promotion.</param>
/// <param name="right">The right operand type after promotion.</param>
/// <returns>True if a valid function signature was found that matches the given types after any necessary promotions are made.
/// False if there is no binary operators </returns>
internal static bool PromoteOperandTypes(BinaryOperatorKind operatorKind, SingleValueNode leftNode, SingleValueNode rightNode, out IEdmTypeReference left, out IEdmTypeReference right)
{
left = leftNode.TypeReference;
right = rightNode.TypeReference;
// The types for the operands can be null
// if they (a) represent the null literal or (b) represent an open type/property.
// If both argument types are null we lack type information on both sides and cannot promote arguments.
if (left == null && right == null)
{
// if we find null literals or open properties on both sides we cannot promote; the result type will also be null
return true;
}
if (operatorKind == BinaryOperatorKind.NotEqual || operatorKind == BinaryOperatorKind.Equal)
{
if (TryHandleEqualityOperatorForEntityOrComplexTypes(ref left, ref right))
{
return true;
}
// enum and spatial type support equality operator for null operand:
if ((left == null) && (right != null) && (right.IsEnum() || right is IEdmSpatialTypeReference))
{
left = right;
return true;
}
if ((right == null) && (left != null) && (left.IsEnum() || left is IEdmSpatialTypeReference))
{
right = left;
return true;
}
}
// enum support, check type full names
if (left != null && right != null && left.IsEnum() && right.IsEnum())
{
return string.Equals(left.FullName(), right.FullName(), StringComparison.Ordinal);
}
// type definition support, treat type definitions as their underlying types.
if (left != null && left.IsTypeDefinition())
{
left = left.AsPrimitive();
}
if (right != null && right.IsTypeDefinition())
{
right = right.AsPrimitive();
}
// Except for above, binary operators are only supported on primitive types
if (left != null && !left.IsODataPrimitiveTypeKind() || right != null && !right.IsODataPrimitiveTypeKind())
{
return false;
}
// The following will match primitive argument types to build in function signatures, choosing the best one possible.
FunctionSignature[] signatures = GetFunctionSignatures(operatorKind);
SingleValueNode[] argumentNodes = new SingleValueNode[] { leftNode, rightNode };
IEdmTypeReference[] argumentTypes = new IEdmTypeReference[] { left, right };
bool success = FindBestSignature(signatures, argumentNodes, argumentTypes) == 1;
if (success)
{
left = argumentTypes[0];
right = argumentTypes[1];
if (left == null)
{
left = right;
}
else if (right == null)
{
right = left;
}
}
return success;
}
示例6: GetEdmTypeSerializer
/// <summary>
/// Gets the serializer for the given EDM type reference.
/// </summary>
/// <param name="edmType">The EDM type reference involved in the serializer.</param>
/// <returns>The serializer instance.</returns>
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType.IsEntity())
{
return this.entityTypeSerializer;
}
if (edmType.IsComplex())
{
return this.complexTypeSerializer;
}
if (edmType.IsPrimitive())
{
return this.primitiveSerializer;
}
if (edmType.IsEnum())
{
return this.enumSerializer;
}
if (edmType.IsCollection())
{
if (edmType.AsCollection().ElementType().IsEntity())
{
return this.feedSerializer;
}
return this.collectionSerializer;
}
return base.GetEdmTypeSerializer(edmType);
}
示例7: ConvertToEdmValue
/// <summary>
/// Converts a clr value to an edm value.
/// </summary>
/// <param name="propertyValue">The property value.</param>
/// <param name="edmPropertyType">Type of the property.</param>
/// <returns>
/// The converted value
/// </returns>
private IEdmValue ConvertToEdmValue(object propertyValue, IEdmTypeReference edmPropertyType)
{
Debug.Assert(edmPropertyType != null, "edmPropertyType != null");
if (propertyValue == null)
{
return EdmNullExpression.Instance;
}
if (edmPropertyType.IsStructured())
{
var actualEdmTypeReference = this.model.GetClientTypeAnnotation(propertyValue.GetType());
if (actualEdmTypeReference != null && actualEdmTypeReference.EdmTypeReference.Definition.IsOrInheritsFrom(edmPropertyType.Definition))
{
return new ClientEdmStructuredValue(propertyValue, this.model, actualEdmTypeReference);
}
else
{
return new ClientEdmStructuredValue(propertyValue, this.model, this.model.GetClientTypeAnnotation(edmPropertyType.Definition));
}
}
if (edmPropertyType.IsCollection())
{
var collectionType = edmPropertyType as IEdmCollectionTypeReference;
Debug.Assert(collectionType != null, "collectionType != null");
var elements = ((IEnumerable)propertyValue).Cast<object>().Select(v => this.ConvertToEdmValue(v, collectionType.ElementType()));
return new ClientEdmCollectionValue(collectionType, elements);
}
if (edmPropertyType.IsEnum())
{
// Need to handle underlying type(Int16, Int32, Int64)
return new EdmEnumValue(edmPropertyType as IEdmEnumTypeReference, new EdmIntegerConstant(Convert.ToInt64(propertyValue, CultureInfo.InvariantCulture)));
}
var primitiveType = edmPropertyType as IEdmPrimitiveTypeReference;
Debug.Assert(primitiveType != null, "Type was not structured, collection, or primitive");
return EdmValueUtils.ConvertPrimitiveValue(propertyValue, primitiveType).Value;
}
示例8: GetClrTypeName
//fill all properties/name of the class template
private string GetClrTypeName(IEdmTypeReference edmTypeReference)
{
string clrTypeName = edmTypeReference.ToString();
IEdmType edmType = edmTypeReference.Definition;
if (edmTypeReference.IsPrimitive()) return EdmToClr(edmType as IEdmPrimitiveType);
//@@@ v1.0.0-rc2
if (edmTypeReference.IsEnum())
{
var ent = edmType as IEdmEnumType;
if (ent != null) return ent.Name;
}
if (edmTypeReference.IsComplex())
{
var edmComplexType = edmType as IEdmComplexType;
if (edmComplexType != null) return edmComplexType.Name;
}
if (edmTypeReference.IsEntity())
{
var ent = edmType as IEdmEntityType;
if (ent != null) return ent.Name;
}
if (edmTypeReference.IsCollection())
{
IEdmCollectionType edmCollectionType = edmType as IEdmCollectionType;
if (edmCollectionType != null)
{
IEdmTypeReference elementTypeReference = edmCollectionType.ElementType;
IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType;
if (primitiveElementType == null)
{
IEdmSchemaElement schemaElement = elementTypeReference.Definition as IEdmSchemaElement;
if (schemaElement != null)
{
clrTypeName = schemaElement.Name;
//@@@ 1.0.0-rc2
// clrTypeName = string.Format("ICollection<{0}>", clrTypeName);
clrTypeName = string.Format("List<{0}>", clrTypeName); //to support RestSharp
}
return clrTypeName;
}
clrTypeName = EdmToClr(primitiveElementType);
clrTypeName = string.Format("List<{0}>", clrTypeName);
}
return clrTypeName;
}//IsCollection
return clrTypeName;
}