public void Ctor_Throws_TypeMustBeEntityCollection() { EdmComplexType complexType = new EdmComplexType("namespace", "name"); EdmCollectionType collectionType = new EdmCollectionType(new EdmComplexTypeReference(complexType, isNullable: true)); Assert.Throws<NotSupportedException>( () => new ODataFeedSerializer(new EdmCollectionTypeReference(collectionType, isNullable: false), new DefaultODataSerializerProvider()), "namespace.name is not a collection of type IEdmEntityType. Only entity collections are supported."); }
private IEdmTypeReference MapArray(KeyValuePair<string, JSchema> property, JSchema parent, EdmModel model) { var entityPrimitiveType = ToEdmPrimitiveType(property.Value.Items.Single().Type.Value); var entityType = EdmCoreModel.Instance.GetPrimitiveType(entityPrimitiveType); var collectionType = new EdmCollectionType(new EdmPrimitiveTypeReference(entityType, false)); bool isNullable = !parent.Required.Contains(property.Key); return new EdmCollectionTypeReference(collectionType, isNullable); }
private IEdmCollectionType EnsureCollectionItemTypeIsPrimitiveOrComplex(ResourceType itemResourceType, List<KeyValuePair<string, object>> customAnnotations) { IEdmCollectionType type; if (!this.primitiveOrComplexCollectionTypeCache.TryGetValue(itemResourceType, out type)) { IEdmTypeReference reference; switch (itemResourceType.ResourceTypeKind) { case ResourceTypeKind.ComplexType: reference = this.EnsureTypeReference(itemResourceType, customAnnotations); reference = reference.IsNullable ? reference.Clone(false) : reference; break; case ResourceTypeKind.Primitive: { MetadataProviderUtils.GetAndRemoveNullableFacet(customAnnotations); IEdmPrimitiveTypeReference typeReference = MetadataProviderUtils.CreatePrimitiveTypeReference(itemResourceType, customAnnotations); reference = typeReference.IsNullable ? typeReference.Clone(false) : typeReference; break; } default: throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderEdmModel_UnsupportedCollectionItemType_PrimitiveOrComplex(itemResourceType.ResourceTypeKind.ToString())); } type = new EdmCollectionType(reference); this.primitiveOrComplexCollectionTypeCache.Add(itemResourceType, type); } return type; }
private static IEdmTypeReference GetEdmTypeReference(Dictionary<Type, IEdmStructuredType> availableTypes, IEdmTypeConfiguration configuration, bool nullable) { Contract.Assert(availableTypes != null); if (configuration == null) { return null; } EdmTypeKind kind = configuration.Kind; if (kind == EdmTypeKind.Collection) { CollectionTypeConfiguration collectionType = configuration as CollectionTypeConfiguration; EdmCollectionType edmCollectionType = new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, false)); return new EdmCollectionTypeReference(edmCollectionType, nullable); } else if (availableTypes.ContainsKey(configuration.ClrType)) { IEdmStructuredType structuralType = availableTypes[configuration.ClrType]; if (kind == EdmTypeKind.Complex) { return new EdmComplexTypeReference(structuralType as IEdmComplexType, nullable); } else if (kind == EdmTypeKind.Entity) { return new EdmEntityTypeReference(structuralType as IEdmEntityType, nullable); } else { throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString()); } } else if (configuration.Kind == EdmTypeKind.Primitive) { PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration; return new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable); } else { throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName); } }
internal static IEdmCollectionTypeReference ToCollectionTypeReference(this IEdmComplexTypeReference itemTypeReference) { DebugUtils.CheckNoExternalCallers(); IEdmCollectionType collectionType = new EdmCollectionType(itemTypeReference); return (IEdmCollectionTypeReference)ToTypeReference(collectionType); }
internal static IEdmCollectionTypeReference ToCollectionTypeReference(this IEdmPrimitiveTypeReference itemTypeReference) { IEdmCollectionType type = new EdmCollectionType(itemTypeReference); return (IEdmCollectionTypeReference) type.ToTypeReference(); }