本文整理汇总了C#中IEdmTypeReference.TypeKind方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.TypeKind方法的具体用法?C# IEdmTypeReference.TypeKind怎么用?C# IEdmTypeReference.TypeKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.TypeKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeTargetTypeKind
private static EdmTypeKind ComputeTargetTypeKind(IEdmTypeReference expectedTypeReference, bool forEntityValue, string payloadTypeName, EdmTypeKind payloadTypeKind, ODataMessageReaderSettings messageReaderSettings, Func<EdmTypeKind> typeKindFromPayloadFunc)
{
EdmTypeKind kind;
bool flag = (messageReaderSettings.ReaderBehavior.TypeResolver != null) && (payloadTypeKind != EdmTypeKind.None);
if (((expectedTypeReference != null) && !flag) && (!expectedTypeReference.IsODataPrimitiveTypeKind() || !messageReaderSettings.DisablePrimitiveTypeConversion))
{
kind = expectedTypeReference.TypeKind();
}
else if (payloadTypeKind != EdmTypeKind.None)
{
if (!forEntityValue)
{
ValidationUtils.ValidateValueTypeKind(payloadTypeKind, payloadTypeName);
}
kind = payloadTypeKind;
}
else
{
kind = typeKindFromPayloadFunc();
}
if (ShouldValidatePayloadTypeKind(messageReaderSettings, expectedTypeReference, payloadTypeKind))
{
ValidationUtils.ValidateTypeKind(kind, expectedTypeReference.TypeKind(), payloadTypeName);
}
return kind;
}
示例2: GetInstanceType
/// <summary>
/// Returns the instance type for the specified Edm type or null if none exists.
/// </summary>
/// <param name="type">The type to get the instance type for.</param>
/// <returns>The instance type for the <paramref name="typeReference"/> or null if no instance type exists.</returns>
public static Type GetInstanceType(IEdmTypeReference type)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
Type result = null;
if (type.TypeKind() == EdmTypeKind.TypeDefinition)
{
var td = type.Definition as IEdmTypeDefinition;
result = GetUnsignedIntInstanceType(td, type.IsNullable);
}
else if (type.TypeKind() == EdmTypeKind.Primitive)
{
// TODO: Find out if the type is nullable
result = GetPrimitiveInstanceType(type.Definition as IEdmPrimitiveType, type.IsNullable);
}
else
{
// TODO: We should load from DataSource assembly.
result = GetInstanceType(type.Definition, type.Definition.FullTypeName());
}
if (result != null)
{
return result;
}
else
{
throw new InvalidOperationException(string.Format("Cannot find instance type for EdmType {0}.", type.Definition.FullTypeName()));
}
}
示例3: CreateEdmTypeSerializer
public override ODataSerializer CreateEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Primitive:
return new ODataPrimitiveSerializer(edmType.AsPrimitive());
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedSerializer(collectionType, this);
}
else
{
return new ODataCollectionSerializer(collectionType, this);
}
case EdmTypeKind.Complex:
return new ODataComplexTypeSerializer(edmType.AsComplex(), this);
case EdmTypeKind.Entity:
return new ODataEntityTypeSerializer(edmType.AsEntity(), this);
default:
throw Error.InvalidOperation(SRResources.TypeCannotBeSerialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter).Name);
}
}
示例4: CreateDeserializer
protected override ODataEntryDeserializer CreateDeserializer(IEdmTypeReference edmType)
{
if (edmType != null)
{
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return new ODataEntityDeserializer(edmType.AsEntity(), this);
case EdmTypeKind.Primitive:
return new ODataPrimitiveDeserializer(edmType.AsPrimitive());
case EdmTypeKind.Complex:
return new ODataComplexTypeDeserializer(edmType.AsComplex(), this);
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedDeserializer(collectionType, this);
}
else
{
return new ODataCollectionDeserializer(collectionType, this);
}
}
}
return null;
}
示例5: GetEdmTypeDeserializer
/// <inheritdoc />
public override ODataEdmTypeDeserializer GetEdmTypeDeserializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return _entityDeserializer;
case EdmTypeKind.Primitive:
return _primitiveDeserializer;
case EdmTypeKind.Complex:
return _complexDeserializer;
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return _feedDeserializer;
}
else
{
return _collectionDeserializer;
}
default:
return null;
}
}
示例6: CreateEdmTypeSerializer
/// <summary>
/// Creates a new instance of the <see cref="ODataEdmTypeSerializer"/> for the given edm type.
/// </summary>
/// <param name="edmType">The <see cref="IEdmTypeReference"/>.</param>
/// <returns>The constructed <see cref="ODataEdmTypeSerializer"/>.</returns>
public virtual ODataEdmTypeSerializer CreateEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Primitive:
return new ODataPrimitiveSerializer(edmType.AsPrimitive());
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.ElementType().IsEntity())
{
return new ODataFeedSerializer(collectionType, this);
}
else
{
return new ODataCollectionSerializer(collectionType, this);
}
case EdmTypeKind.Complex:
return new ODataComplexTypeSerializer(edmType.AsComplex(), this);
case EdmTypeKind.Entity:
return new ODataEntityTypeSerializer(edmType.AsEntity(), this);
default:
return null;
}
}
示例7: GetEdmTypeSerializer
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return _sampleEntityTypeSerializer;
}
return base.GetEdmTypeSerializer(edmType);
}
示例8: ReadInline
/// <inheritdoc />
public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
{
if (item == null)
{
return null;
}
if (readContext.IsUntyped)
{
Contract.Assert(edmType.TypeKind() == EdmTypeKind.Enum);
return new EdmEnumObject((IEdmEnumTypeReference)edmType, ((ODataEnumValue)item).Value);
}
Type clrType = EdmLibHelpers.GetClrType(edmType, readContext.Model);
return EnumDeserializationHelpers.ConvertEnumValue(item, clrType);
}
示例9: ResolveTypeNameForWriting
internal static IEdmTypeReference ResolveTypeNameForWriting(IEdmModel model, IEdmTypeReference typeReferenceFromMetadata, ref string typeName, EdmTypeKind typeKindFromValue, bool isOpenPropertyType)
{
IEdmType type = ValidateValueTypeName(model, typeName, typeKindFromValue, isOpenPropertyType);
IEdmTypeReference typeReferenceFromValue = type.ToTypeReference();
if (typeReferenceFromMetadata != null)
{
ValidationUtils.ValidateTypeKind(typeKindFromValue, typeReferenceFromMetadata.TypeKind(), (type == null) ? null : type.ODataFullName());
}
typeReferenceFromValue = ValidateMetadataType(typeReferenceFromMetadata, typeReferenceFromValue);
if ((typeKindFromValue == EdmTypeKind.Collection) && (typeReferenceFromValue != null))
{
typeReferenceFromValue = ValidationUtils.ValidateCollectionType(typeReferenceFromValue);
}
if ((typeName == null) && (typeReferenceFromValue != null))
{
typeName = typeReferenceFromValue.ODataFullName();
}
return typeReferenceFromValue;
}
示例10: CreateDeserializer
protected override ODataEntryDeserializer CreateDeserializer(IEdmTypeReference edmType)
{
if (edmType != null)
{
switch (edmType.TypeKind())
{
case EdmTypeKind.Entity:
return new ODataEntityDeserializer(edmType.AsEntity(), this);
case EdmTypeKind.Primitive:
return new ODataRawValueDeserializer(edmType.AsPrimitive());
case EdmTypeKind.Complex:
return new ODataComplexTypeDeserializer(edmType.AsComplex(), this);
}
}
return null;
}
示例11: IsEquivalentTo
public static bool IsEquivalentTo(this IEdmTypeReference thisType, IEdmTypeReference otherType)
{
if (thisType != otherType)
{
if (thisType == null || otherType == null)
{
return false;
}
else
{
EdmTypeKind edmTypeKind = thisType.TypeKind();
if (edmTypeKind == otherType.TypeKind())
{
if (edmTypeKind != EdmTypeKind.Primitive)
{
if (thisType.IsNullable != otherType.IsNullable)
{
return false;
}
else
{
return thisType.Definition.IsEquivalentTo(otherType.Definition);
}
}
else
{
return thisType.IsEquivalentTo((IEdmPrimitiveTypeReference)otherType);
}
}
else
{
return false;
}
}
}
else
{
return true;
}
}
示例12: GetEdmTypeSerializer
/// <inheritdoc />
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
switch (edmType.TypeKind())
{
case EdmTypeKind.Enum:
return _enumSerializer;
case EdmTypeKind.Primitive:
return _primitiveSerializer;
case EdmTypeKind.Collection:
IEdmCollectionTypeReference collectionType = edmType.AsCollection();
if (collectionType.Definition.IsDeltaFeed())
{
return _deltaFeedSerializer;
}
else if (collectionType.ElementType().IsEntity())
{
return _feedSerializer;
}
else
{
return _collectionSerializer;
}
case EdmTypeKind.Complex:
return _complexTypeSerializer;
case EdmTypeKind.Entity:
return _entityTypeSerializer;
default:
return null;
}
}
示例13: GetClrTypeForUntypedDelta
internal static Type GetClrTypeForUntypedDelta(IEdmTypeReference edmType)
{
Contract.Assert(edmType != null);
switch (edmType.TypeKind())
{
case EdmTypeKind.Primitive:
return EdmLibHelpers.GetClrType(edmType.AsPrimitive(), EdmCoreModel.Instance);
case EdmTypeKind.Complex:
return typeof(EdmComplexObject);
case EdmTypeKind.Entity:
return typeof(EdmEntityObject);
case EdmTypeKind.Enum:
return typeof(EdmEnumObject);
case EdmTypeKind.Collection:
IEdmTypeReference elementType = edmType.AsCollection().ElementType();
if (elementType.IsPrimitive())
{
Type elementClrType = GetClrTypeForUntypedDelta(elementType);
return typeof(List<>).MakeGenericType(elementClrType);
}
else if (elementType.IsComplex())
{
return typeof(EdmComplexObjectCollection);
}
else if (elementType.IsEntity())
{
return typeof(EdmEntityObjectCollection);
}
else if (elementType.IsEnum())
{
return typeof(EdmEnumObjectCollection);
}
break;
}
throw Error.InvalidOperation(SRResources.UnsupportedEdmType, edmType.ToTraceString(), edmType.TypeKind());
}
示例14: ValidateNullValue
/// <summary>
/// Validate a null value.
/// </summary>
/// <param name="model">The <see cref="IEdmModel"/> used to read the payload.</param>
/// <param name="expectedTypeReference">The expected type of the null value.</param>
/// <param name="messageReaderSettings">The message reader settings.</param>
/// <param name="validateNullValue">true to validate the the null value; false to only check whether the type is supported.</param>
/// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
/// <param name="isDynamicProperty">Indicates whether the property is dynamic or unknown.</param>
internal static void ValidateNullValue(
IEdmModel model,
IEdmTypeReference expectedTypeReference,
ODataMessageReaderSettings messageReaderSettings,
bool validateNullValue,
string propertyName,
bool? isDynamicProperty = null)
{
// For a null value if we have an expected type
// - we validate that the expected type is nullable if type conversion is enabled
// - don't validate any primitive types if primitive type conversion is disabled
// For a null value without an expected type
// - we simply return null (treat it is as primitive null value)
if (expectedTypeReference != null)
{
ValidateTypeSupported(expectedTypeReference);
if (!messageReaderSettings.DisablePrimitiveTypeConversion || expectedTypeReference.TypeKind() != EdmTypeKind.Primitive)
{
ValidateNullValueAllowed(expectedTypeReference, validateNullValue, model, propertyName, isDynamicProperty);
}
}
}
示例15: ResolveAndValidateNonPrimitiveTargetType
/// <summary>
/// Resolves the payload type versus the expected type and validates that such combination is allowed.
/// </summary>
/// <param name="expectedTypeKind">The expected type kind for the value.</param>
/// <param name="expectedTypeReference">The expected type reference, or null if no expected type is available.</param>
/// <param name="payloadTypeKind">The payload type kind, this may be the one from the type itself, or one detected without resolving the type.</param>
/// <param name="payloadType">The payload type, or null if the payload type was not specified, or it didn't resolve against the model.</param>
/// <param name="payloadTypeName">The payload type name, or null if no payload type was specified.</param>
/// <param name="model">The model to use.</param>
/// <param name="messageReaderSettings">The message reader settings to use.</param>
/// <returns>
/// The target type reference to use for parsing the value.
/// If there is no user specified model, this will return null.
/// If there is a user specified model, this method never returns null.
/// </returns>
/// <remarks>
/// This method cannot be used for primitive type resolution. Primitive type resolution is format dependent and format specific methods should be used instead.
/// </remarks>
internal static IEdmTypeReference ResolveAndValidateNonPrimitiveTargetType(
EdmTypeKind expectedTypeKind,
IEdmTypeReference expectedTypeReference,
EdmTypeKind payloadTypeKind,
IEdmType payloadType,
string payloadTypeName,
IEdmModel model,
ODataMessageReaderSettings messageReaderSettings)
{
Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
Debug.Assert(
expectedTypeKind == EdmTypeKind.Enum || expectedTypeKind == EdmTypeKind.Complex || expectedTypeKind == EdmTypeKind.Entity ||
expectedTypeKind == EdmTypeKind.Collection || expectedTypeKind == EdmTypeKind.TypeDefinition,
"The expected type kind must be one of Enum, Complex, Entity, Collection or TypeDefinition.");
Debug.Assert(
payloadTypeKind == EdmTypeKind.Complex || payloadTypeKind == EdmTypeKind.Entity ||
payloadTypeKind == EdmTypeKind.Collection || payloadTypeKind == EdmTypeKind.None ||
payloadTypeKind == EdmTypeKind.Primitive || payloadTypeKind == EdmTypeKind.Enum ||
payloadTypeKind == EdmTypeKind.TypeDefinition,
"The payload type kind must be one of None, Primitive, Enum, Complex, Entity, Collection or TypeDefinition.");
Debug.Assert(
expectedTypeReference == null || expectedTypeReference.TypeKind() == expectedTypeKind,
"The expected type kind must match the expected type reference if that is available.");
Debug.Assert(
payloadType == null || payloadType.TypeKind == payloadTypeKind,
"The payload type kind must match the payload type if that is available.");
Debug.Assert(payloadType == null || payloadTypeName != null, "If we have a payload type, we must have its name as well.");
bool useExpectedTypeOnlyForTypeResolution = messageReaderSettings.ReaderBehavior.TypeResolver != null && payloadType != null;
if (!useExpectedTypeOnlyForTypeResolution)
{
ValidateTypeSupported(expectedTypeReference);
// We should validate that the payload type resolved before anything else to produce reasonable error messages
// Otherwise we might report errors which are somewhat confusing (like "Type '' is Complex but Collection was expected.").
if (model.IsUserModel() && (expectedTypeReference == null || !messageReaderSettings.DisableStrictMetadataValidation))
{
// When using a type resolver (i.e., useExpectedTypeOnlyForTypeResolution == true) then we don't have to
// call this method because the contract with the type resolver is to always resolve the type name and thus
// we will always get a defined type.
VerifyPayloadTypeDefined(payloadTypeName, payloadType);
}
}
else
{
// Payload types are always nullable.
ValidateTypeSupported(payloadType == null ? null : payloadType.ToTypeReference(/*nullable*/ true));
}
// In lax mode don't cross check kinds of types (we would just use the expected type) unless we expect
// an open property of a specific kind (e.g. top level complex property for PUT requests)
if (payloadTypeKind != EdmTypeKind.None && (!messageReaderSettings.DisableStrictMetadataValidation || expectedTypeReference == null))
{
// Make sure that the type kinds match.
ValidationUtils.ValidateTypeKind(payloadTypeKind, expectedTypeKind, payloadTypeName);
}
if (!model.IsUserModel())
{
// If there's no model, it means we should not have the expected type either, and that there's no type to use,
// no metadata validation to perform.
Debug.Assert(expectedTypeReference == null, "If we don't have a model, we must not have expected type either.");
return null;
}
if (expectedTypeReference == null || useExpectedTypeOnlyForTypeResolution)
{
Debug.Assert(payloadTypeName == null || payloadType != null, "The payload type must have resolved before we get here.");
return ResolveAndValidateTargetTypeWithNoExpectedType(
expectedTypeKind,
payloadType);
}
if (messageReaderSettings.DisableStrictMetadataValidation)
{
return ResolveAndValidateTargetTypeStrictValidationDisabled(
expectedTypeKind,
expectedTypeReference,
payloadType);
}
Debug.Assert(payloadTypeName == null || payloadType != null, "The payload type must have resolved before we get here.");
//.........这里部分代码省略.........