private static IApiCollectionType CreateApiCollectionType(ApiMutableCollectionType apiMutableCollectionType, ApiSchemaProxy apiSchemaProxy) { Contract.Requires(apiMutableCollectionType != null); Contract.Requires(apiSchemaProxy != null); var apiMutableSchema = apiMutableCollectionType.ApiMutableSchema; var apiItemTypeKind = apiMutableCollectionType.ApiItemTypeKind; var apiItemTypeModifiers = apiMutableCollectionType.ApiItemTypeModifiers; var clrItemType = apiMutableCollectionType.ClrItemType; switch (apiItemTypeKind) { case ApiTypeKind.Scalar: { apiMutableSchema.AddClrImplicitScalarType(clrItemType); break; } case ApiTypeKind.Enumeration: { apiMutableSchema.AddClrImplicitEnumerationType(clrItemType); break; } } var apiItemTypeResolver = new ApiSchemaProxyTypeResolver(apiSchemaProxy, apiItemTypeKind, clrItemType); var apiCollectionType = ApiTypeFactory.CreateApiCollectionType(apiItemTypeResolver, apiItemTypeModifiers); return(apiCollectionType); }
// PRIVATE METHODS ////////////////////////////////////////////////// #region Methods private Func <ApiMutableSchema, ApiMutableCollectionType> CreateApiMutableCollectionTypeFactory(Type clrDeclaringType, Type clrType, Type clrItemType) { Contract.Requires(clrDeclaringType != null); Contract.Requires(clrType != null); Contract.Requires(clrItemType != null); ApiMutableCollectionType ApiMutableCollectionTypeFactory(ApiMutableSchema apiMutableSchema) { Contract.Requires(apiMutableSchema != null); var apiItemTypeKind = clrItemType.GetApiTypeKind(out var clrInnerCollectionItemType); switch (apiItemTypeKind) { case ApiTypeKind.Collection: // Unable to handle collections within collections. var message = $"Unable to configure collections [clrItemType={clrItemType.Name}] that contain other collections [clrItemType={clrInnerCollectionItemType.Name}] in the API schema."; throw new ApiSchemaException(message); } var apiMutableCollectionType = new ApiMutableCollectionType { ApiMutableSchema = apiMutableSchema, ApiItemTypeKind = apiItemTypeKind, ClrDeclaringType = clrDeclaringType, ClrCollectionType = clrType, ClrItemType = clrItemType, }; return(apiMutableCollectionType); } return(ApiMutableCollectionTypeFactory); }