예제 #1
0
        private static IApiProperty CreateApiProperty(ApiMutableObjectType apiMutableObjectType,
                                                      ApiMutableProperty apiMutableProperty,
                                                      ApiSchemaProxy apiSchemaProxy)
        {
            Contract.Requires(apiMutableObjectType != null);
            Contract.Requires(apiMutableProperty != null);
            Contract.Requires(apiSchemaProxy != null);

            var apiMutableSchema = apiMutableProperty.ApiMutableSchema;
            var apiName          = apiMutableProperty.ApiName;
            var apiDescription   = apiMutableProperty.ApiDescription;
            var apiTypeKind      = apiMutableProperty.ApiTypeKind;
            var apiTypeModifiers = apiMutableProperty.ApiTypeModifiers;
            var clrName          = apiMutableProperty.ClrName;
            var clrType          = apiMutableProperty.ClrType;

            switch (apiTypeKind)
            {
            case ApiTypeKind.Enumeration:
            {
                apiMutableSchema.AddClrImplicitEnumerationType(clrType);
                break;
            }

            case ApiTypeKind.Collection:
            {
                // Create the known concrete API collection type.
                var apiCollectionTypeConfiguration = apiMutableProperty.ApiCollectionTypeConfiguration;
                var apiCollectionType = apiCollectionTypeConfiguration.Create(apiMutableSchema, apiSchemaProxy);
                return(ApiTypeFactory.CreateApiProperty(apiName, apiDescription, apiCollectionType, apiTypeModifiers, clrName));
            }

            case ApiTypeKind.Scalar:
            {
                apiMutableSchema.AddClrImplicitScalarType(clrType);
                break;
            }
            }

            // API identity properties will always be required.
            var clrIdentityPropertyName = apiMutableObjectType?.ClrIdentityProperty?.ClrPropertyName;

            if (clrName == clrIdentityPropertyName)
            {
                apiTypeModifiers |= ApiTypeModifiers.Required;
            }

            var apiTypeResolver = new ApiSchemaProxyTypeResolver(apiSchemaProxy, apiTypeKind, clrType);

            return(ApiTypeFactory.CreateApiProperty(apiName, apiDescription, apiTypeResolver, apiTypeModifiers, clrName));
        }
예제 #2
0
        public IApiProperty CreateApiProperty(ApiMutableSchema apiMutableSchema, ApiMutableObjectType apiMutableObjectType, ApiSchemaProxy apiSchemaProxy)
        {
            Contract.Requires(apiMutableSchema != null);
            Contract.Requires(apiMutableObjectType != null);
            Contract.Requires(apiSchemaProxy != null);

            var apiMutableProperty = this.ApiMutablePropertyFactory.Create(apiMutableSchema);

            var apiProperty = CreateApiProperty(apiMutableObjectType, apiMutableProperty, apiSchemaProxy);

            ApiFrameworkLog.Debug($"Created {apiProperty}".Indent(IndentConstants.ApiProperty));

            return(apiProperty);
        }