示例#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
        private Func <ApiMutableSchema, ApiMutableProperty> CreateApiMutablePropertyFactory(Type clrDeclaringType, string clrName, Type clrType)
        {
            Contract.Requires(clrDeclaringType != null);
            Contract.Requires(clrName.SafeHasContent());
            Contract.Requires(clrType != null);

            ApiMutableProperty ApiMutablePropertyFactory(ApiMutableSchema apiMutableSchema)
            {
                Contract.Requires(apiMutableSchema != null);

                // Apply conventions
                this.ApiPrecedenceStack.Push(ApiPrecedenceLevel.Convention);

                var apiConventionSet      = apiMutableSchema?.ApiConventionSet;
                var apiConventionSettings = apiMutableSchema?.ApiConventionSettings;

                this.ApplyApiPropertyNameConventions(clrName, apiConventionSet, apiConventionSettings);

                this.ApiPrecedenceStack.Pop();

                // Create API mutable property
                var apiTypeKind = clrType.GetApiTypeKind(out var clrItemType);

                var apiCollectionTypeConfiguration = default(ApiCollectionTypeConfiguration);

                switch (apiTypeKind)
                {
                case ApiTypeKind.Collection:
                {
                    apiCollectionTypeConfiguration = new ApiCollectionTypeConfiguration(clrDeclaringType, clrType, clrItemType, this.ApiPrecedenceStack);
                    break;
                }
                }

                var apiDefaultName     = clrName;
                var apiMutableProperty = new ApiMutableProperty
                {
                    ApiMutableSchema = apiMutableSchema,
                    ApiName          = apiDefaultName,
                    ApiTypeKind      = apiTypeKind,
                    ApiCollectionTypeConfiguration = apiCollectionTypeConfiguration,
                    ClrDeclaringType = clrDeclaringType,
                    ClrName          = clrName,
                    ClrType          = clrType
                };

                return(apiMutableProperty);
            }

            return(ApiMutablePropertyFactory);
        }