本文整理汇总了C#中IEdmType.FullTypeName方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmType.FullTypeName方法的具体用法?C# IEdmType.FullTypeName怎么用?C# IEdmType.FullTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmType
的用法示例。
在下文中一共展示了IEdmType.FullTypeName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckRelatedTo
/// <summary>
/// Check whether the parent and child are properly related types
/// </summary>
/// <param name="parentType">the parent type</param>
/// <param name="childType">the child type</param>
/// <exception cref="ODataException">Throws if the two types are not related.</exception>
public static void CheckRelatedTo(IEdmType parentType, IEdmType childType)
{
if (!IsRelatedTo(parentType, childType))
{
// If the parentType is an open property, parentType will be null and can't have an ODataFullName.
string parentTypeName = (parentType != null) ? parentType.ODataFullName() : "<null>";
throw new ODataException(OData.Core.Strings.MetadataBinder_HierarchyNotFollowed(childType.FullTypeName(), parentTypeName));
}
}
示例2: CreateResource
public static object CreateResource(IEdmType type)
{
var targetType = EdmClrTypeUtils.GetInstanceType(type.FullTypeName());
return QuickCreateInstance(targetType);
}
示例3: GetSchemaFromModel
public static TypeSchema GetSchemaFromModel(IEdmType type)
{
var structure = type as IEdmStructuredType;
if (structure != null)
{
return GetSchemaFromModel(structure);
}
var collection = type as IEdmCollectionType;
if (collection != null)
{
return Schema.CreateArray(GetSchemaFromModel(collection.ElementType));
}
var primitive = type as IEdmPrimitiveType;
if (primitive != null)
{
switch (primitive.PrimitiveKind)
{
case EdmPrimitiveTypeKind.Binary:
return Schema.CreateBytes();
case EdmPrimitiveTypeKind.Boolean:
return Schema.CreateBoolean();
case EdmPrimitiveTypeKind.Int32:
return Schema.CreateInt();
case EdmPrimitiveTypeKind.Int64:
return Schema.CreateLong();
case EdmPrimitiveTypeKind.Single:
return Schema.CreateFloat();
case EdmPrimitiveTypeKind.Double:
return Schema.CreateDouble();
case EdmPrimitiveTypeKind.String:
return Schema.CreateString();
}
}
throw new Exception(string.Format("unsupported type: {0}", type.FullTypeName()));
}
示例4: SetSwaggerType
public static void SetSwaggerType(JObject jObject, IEdmType edmType)
{
if (edmType.TypeKind == EdmTypeKind.Complex || edmType.TypeKind == EdmTypeKind.Entity)
{
jObject.Add("$ref", "#/definitions/" + edmType.FullTypeName());
}
else if (edmType.TypeKind == EdmTypeKind.Primitive)
{
string format;
string type = GetPrimitiveTypeAndFormat((IEdmPrimitiveType) edmType, out format);
jObject.Add("type", type);
if (format != null)
{
jObject.Add("format", format);
}
}
else if (edmType.TypeKind == EdmTypeKind.Enum)
{
jObject.Add("type", "string");
}
else if (edmType.TypeKind == EdmTypeKind.Collection)
{
IEdmType itemEdmType = ((IEdmCollectionType)edmType).ElementType.Definition;
JObject nestedItem = new JObject();
SetSwaggerType(nestedItem, itemEdmType);
jObject.Add("type", "array");
jObject.Add("items", nestedItem);
}
}
示例5: TranslateEdmTypeToClrType
//-----------------------------------------------------------------------------------------------------------------------------------------------------
private Type TranslateEdmTypeToClrType(IEdmModel model, IEdmType edmType)
{
var annotation = model.GetAnnotationValue<ClrTypeAnnotation>(edmType);
if ( annotation != null )
{
return annotation.ClrType;
}
var entityType = (edmType as IEdmEntityType);
if ( entityType != null )
{
return base.Context.Factory.FindDynamicType(new EdmEntityTypeKey(model, entityType));
}
var collectionType = (edmType as IEdmCollectionType);
if ( collectionType != null )
{
var elementClrType = TranslateEdmTypeToClrType(model, collectionType.ElementType.Definition);
return typeof (DataServiceCollection<>).MakeGenericType(elementClrType);
}
var primitiveType = (edmType as IEdmPrimitiveType);
if ( primitiveType != null )
{
return s_BuiltInTypesMapping[primitiveType];
}
throw new Exception("Could not determine CLR type for EDM type: " + edmType.FullTypeName() + " {" + edmType.GetType().Name + "}");
}
示例6: GetInstanceType
/// <summary>
/// Getting the instance type from the assembly in name
/// </summary>
/// <param name="assembly"></param>
/// <param name="type"></param>
/// <returns></returns>
private static Type GetInstanceType(IEdmType type, string typeName)
{
Type result = null;
switch (type.TypeKind)
{
case EdmTypeKind.Enum:
result = GetTypeFromModels(typeName);
if (result != null && !result.IsEnum)
{
throw new InvalidOperationException(
string.Format("The EdmType {0} is not match to the instance type {1}.", type.FullTypeName(), result.FullName));
}
break;
case EdmTypeKind.Entity:
result = GetTypeFromModels(typeName);
// TODO: Validate the type is a entity type.
break;
case EdmTypeKind.Complex:
result = GetTypeFromModels(typeName);
// TODO: Validate the type is a complex type.
break;
case EdmTypeKind.Collection:
var elementType = GetTypeFromModels((type as IEdmCollectionType).ElementType.Definition.FullTypeName());
result = typeof (List<>).MakeGenericType(new[] {elementType});
break;
// It seems we never hit here.
default:
throw new InvalidOperationException(string.Format("GetInstanceType for TypeKind {0} is not supported.", type.TypeKind));
}
return result;
}
示例7: ResolveAndValidateTargetTypeStrictValidationEnabled
/// <summary>
/// Resolves the payload type versus the expected type and validates that such combination is allowed when strict validation is enabled.
/// </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="payloadType">The payload type, or null if the payload type was not specified, or it didn't resolve against the model.</param>
/// <returns>The target type reference to use for parsing the value.</returns>
private static IEdmTypeReference ResolveAndValidateTargetTypeStrictValidationEnabled(
EdmTypeKind expectedTypeKind,
IEdmTypeReference expectedTypeReference,
IEdmType payloadType)
{
// Strict validation logic
switch (expectedTypeKind)
{
case EdmTypeKind.Complex:
if (payloadType != null)
{
// The payload type must be compatible to the expected type.
VerifyComplexType(expectedTypeReference, payloadType, /* failIfNotRelated */ true);
// Use the payload type
return payloadType.ToTypeReference(/*nullable*/ true);
}
break;
case EdmTypeKind.Entity:
if (payloadType != null)
{
// The payload type must be assignable to the expected type.
IEdmTypeReference payloadTypeReference = payloadType.ToTypeReference(/*nullable*/ true);
ValidationUtils.ValidateEntityTypeIsAssignable((IEdmEntityTypeReference)expectedTypeReference, (IEdmEntityTypeReference)payloadTypeReference);
// Use the payload type
return payloadTypeReference;
}
break;
case EdmTypeKind.Enum:
if (payloadType != null && string.CompareOrdinal(payloadType.FullTypeName(), expectedTypeReference.FullName()) != 0)
{
throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadType.FullTypeName(), expectedTypeReference.FullName()));
}
break;
case EdmTypeKind.Collection:
// The type must be exactly equal - note that we intentionally ignore nullability of the items here, since the payload type
// can't specify that.
if (payloadType != null && !payloadType.IsElementTypeEquivalentTo(expectedTypeReference.Definition))
{
VerifyCollectionComplexItemType(expectedTypeReference, payloadType);
throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadType.FullTypeName(), expectedTypeReference.FullName()));
}
break;
case EdmTypeKind.TypeDefinition:
if (payloadType != null && !expectedTypeReference.Definition.IsAssignableFrom(payloadType))
{
throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadType.FullTypeName(), expectedTypeReference.FullName()));
}
break;
default:
throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ReaderValidationUtils_ResolveAndValidateTypeName_Strict_TypeKind));
}
// Either there's no payload type, in which case use the expected one, or the payload one and the expected one are equal.
return expectedTypeReference;
}
示例8: CalculateBindableOperationsForType
internal static IEdmOperation[] CalculateBindableOperationsForType(IEdmType bindingType, IEdmModel model, EdmTypeResolver edmTypeResolver)
{
Debug.Assert(model != null, "model != null");
Debug.Assert(edmTypeResolver != null, "edmTypeResolver != null");
List<IEdmOperation> operations = null;
try
{
operations = model.FindBoundOperations(bindingType).ToList();
}
catch (Exception exc)
{
if (!ExceptionUtils.IsCatchableExceptionType(exc))
{
throw;
}
throw new ODataException(Strings.MetadataUtils_CalculateBindableOperationsForType(bindingType.FullTypeName()), exc);
}
List<IEdmOperation> operationsFound = new List<IEdmOperation>();
foreach (IEdmOperation operation in operations.EnsureOperationsBoundWithBindingParameter())
{
IEdmOperationParameter bindingParameter = operation.Parameters.FirstOrDefault();
IEdmType resolvedBindingType = edmTypeResolver.GetParameterType(bindingParameter).Definition;
if (resolvedBindingType.IsAssignableFrom(bindingType))
{
operationsFound.Add(operation);
}
}
return operationsFound.ToArray();
}
示例9: ParseLevels
/// <summary>
/// Parse from levelsOption token to LevelsClause.
/// Negative value would be treated as max.
/// </summary>
/// <param name="levelsOption">The levelsOption for current expand.</param>
/// <param name="sourceType">The type of current level navigation source.</param>
/// <param name="property">Navigation property for current expand.</param>
/// <returns>The LevelsClause parsed, null if levelsOption is null</returns>
private LevelsClause ParseLevels(long? levelsOption, IEdmType sourceType, IEdmNavigationProperty property)
{
if (!levelsOption.HasValue)
{
return null;
}
IEdmType relatedType = property.ToEntityType();
if (sourceType != null && relatedType != null && !UriEdmHelpers.IsRelatedTo(sourceType, relatedType))
{
throw new ODataException(ODataErrorStrings.ExpandItemBinder_LevelsNotAllowedOnIncompatibleRelatedType(property.Name, relatedType.FullTypeName(), sourceType.FullTypeName()));
}
return new LevelsClause(levelsOption.Value < 0, levelsOption.Value);
}
示例10: ResolveType
/// <summary>
/// Resolves the given type if a client type resolver is available.
/// </summary>
/// <param name="typeToResolve">Type to resolve.</param>
/// <returns>The resolved type.</returns>
private IEdmType ResolveType(IEdmType typeToResolve)
{
Debug.Assert(typeToResolve != null, "typeToResolve != null");
Debug.Assert(this.model != null, "model != null");
Debug.Assert(this.readerBehavior != null, "readerBehavior != null");
Func<IEdmType, string, IEdmType> customTypeResolver = this.readerBehavior.TypeResolver;
if (customTypeResolver == null)
{
return typeToResolve;
}
Debug.Assert(this.readerBehavior.ApiBehaviorKind == ODataBehaviorKind.WcfDataServicesClient, "Custom type resolver can only be specified in WCF DS Client behavior.");
EdmTypeKind typeKind;
// MetadataUtils.ResolveTypeName() does not allow entity collection types however both operationImport.ReturnType and operationParameter.Type can be of entity collection types.
// We don't want to relax MetadataUtils.ResolveTypeName() since the rest of ODL only allows primitive and complex collection types and is currently relying on the method to
// enforce this. So if typeToResolve is an entity collection type, we will resolve the item type and reconstruct the collection type from the resolved item type.
IEdmCollectionType collectionTypeToResolve = typeToResolve as IEdmCollectionType;
if (collectionTypeToResolve != null && collectionTypeToResolve.ElementType.IsEntity())
{
IEdmTypeReference itemTypeReferenceToResolve = collectionTypeToResolve.ElementType;
IEdmType resolvedItemType = MetadataUtils.ResolveTypeName(this.model, null /*expectedType*/, itemTypeReferenceToResolve.FullName(), customTypeResolver, out typeKind);
return new EdmCollectionType(resolvedItemType.ToTypeReference(itemTypeReferenceToResolve.IsNullable));
}
return MetadataUtils.ResolveTypeName(this.model, null /*expectedType*/, typeToResolve.FullTypeName(), customTypeResolver, out typeKind);
}