// PUBLIC CONSTRUCTORS //////////////////////////////////////////////
        #region Constructors
        public ApiEnumerationValueConfiguration(string clrName, int clrOrdinal, ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(clrName.SafeHasContent());
            Contract.Requires(apiPrecedenceStack != null);

            this.ApiPrecedenceStack = apiPrecedenceStack;
            this.ApiMutableEnumerationValueFactory = new ApiMutableFactory <ApiMutableSchema, ApiMutableEnumerationValue>(this.CreateApiMutableEnumerationValueFactory(clrName, clrOrdinal), IndentConstants.ApiMutableEnumerationValue);
        }
Exemple #2
0
        public void AddOrUpdateApiScalarTypeConfiguration(ApiTypeConfiguration apiTypeConfiguration,
                                                          ApiPrecedenceLevel apiPrecedenceLevel,
                                                          ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(apiTypeConfiguration != null);
            Contract.Requires(apiPrecedenceStack != null);

            AddOrUpdateApiTypeConfiguration <ApiScalarTypeConfiguration, ApiMutableFactory <ApiMutableSchema, ApiMutableScalarType>, ApiMutableScalarType>(this.ApiScalarTypeConfigurationDictionary, apiTypeConfiguration,
                                                                                                                                                           ApiScalarTypeConfigurationOpenGenericType, apiPrecedenceLevel, apiPrecedenceStack);
        }
Exemple #3
0
        public ApiScalarTypeConfiguration GetOrAddApiScalarTypeConfiguration(Type clrScalarType,
                                                                             ApiPrecedenceLevel apiPrecedenceLevel,
                                                                             ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(clrScalarType != null);
            Contract.Requires(apiPrecedenceStack != null);

            var apiScalarTypeConfiguration = GetOrAddApiConfiguration <ApiScalarTypeConfiguration>(this.ApiScalarTypeConfigurationDictionary, clrScalarType, ApiScalarTypeConfigurationOpenGenericType, apiPrecedenceLevel, apiPrecedenceStack);

            return(apiScalarTypeConfiguration);
        }
Exemple #4
0
        private static TApiConfiguration GetOrAddApiConfiguration <T, TApiConfiguration>(IDictionary <Type, ApiTypeConfiguration> dictionary,
                                                                                         Type apiConfigurationOpenGenericType,
                                                                                         ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                         ApiPrecedenceStack apiPrecedenceStack)
            where TApiConfiguration : ApiTypeConfiguration
        {
            Contract.Requires(dictionary != null);
            Contract.Requires(apiConfigurationOpenGenericType != null);
            Contract.Requires(apiPrecedenceStack != null);

            var clrType = typeof(T);

            return(GetOrAddApiConfiguration <TApiConfiguration>(dictionary, clrType, apiConfigurationOpenGenericType, apiPrecedenceLevel, apiPrecedenceStack));
        }
Exemple #5
0
        private static TApiConfiguration GetOrAddApiConfiguration <TApiConfiguration>(IDictionary <Type, ApiTypeConfiguration> dictionary,
                                                                                      Type clrType,
                                                                                      Type apiConfigurationOpenGenericType,
                                                                                      ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                      ApiPrecedenceStack apiPrecedenceStack)
            where TApiConfiguration : ApiTypeConfiguration
        {
            Contract.Requires(dictionary != null);
            Contract.Requires(clrType != null);
            Contract.Requires(apiConfigurationOpenGenericType != null);
            Contract.Requires(apiPrecedenceStack != null);

            if (dictionary.TryGetValue(clrType, out var apiConfiguration))
            {
                var apiConfigurationExisting = (TApiConfiguration)apiConfiguration;
                return(apiConfigurationExisting);
            }

            var apiConfigurationNew = ApiTypeConfigurationFactory.CreateApiTypeConfiguration <TApiConfiguration>(clrType, apiConfigurationOpenGenericType, apiPrecedenceStack);

            dictionary.Add(clrType, apiConfigurationNew);

            var apiTypeKind = apiConfigurationNew.ApiTypeKind;

            switch (apiTypeKind)
            {
            case ApiTypeKind.Enumeration:
            {
                ApiFrameworkLog.Trace($"Added {nameof(ApiEnumerationType)} [{nameof(ApiEnumerationType.ClrType)}={clrType.Name}] at {apiPrecedenceLevel} Level".Indent(IndentConstants.ApiMutableSchemaModifier));
                break;
            }

            case ApiTypeKind.Object:
            {
                ApiFrameworkLog.Trace($"Added {nameof(ApiObjectType)} [{nameof(ApiObjectType.ClrType)}={clrType.Name}] at {apiPrecedenceLevel} Level".Indent(IndentConstants.ApiMutableSchemaModifier));
                break;
            }

            case ApiTypeKind.Scalar:
            {
                ApiFrameworkLog.Trace($"Added {nameof(ApiScalarType)} [{nameof(ApiScalarType.ClrType)}={clrType.Name}] at {apiPrecedenceLevel} Level".Indent(IndentConstants.ApiMutableSchemaModifier));
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(apiConfigurationNew);
        }
Exemple #6
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private static void AddOrUpdateApiTypeConfiguration <TConfiguration, TMutableFactory, TMutable>(IDictionary <Type, ApiTypeConfiguration> dictionary,
                                                                                                        ApiTypeConfiguration apiTypeConfiguration,
                                                                                                        Type apiTypeConfigurationOpenGenericType,
                                                                                                        ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                                        ApiPrecedenceStack apiPrecedenceStack)
            where TConfiguration : ApiTypeConfiguration
            where TMutableFactory : ApiMutableFactory <ApiMutableSchema, TMutable>
        {
            Contract.Requires(dictionary != null);
            Contract.Requires(apiTypeConfiguration != null);
            Contract.Requires(apiTypeConfigurationOpenGenericType != null);
            Contract.Requires(apiPrecedenceStack != null);

            var apiConfigurationIncoming = (TConfiguration)apiTypeConfiguration;
            var apiObjectFactoryIncoming = (TMutableFactory)apiConfigurationIncoming.ApiMutableFactory;

            var clrType = apiTypeConfiguration.ClrType;

            if (dictionary.TryGetValue(clrType, out var apiConfiguration))
            {
                // Update the existing API configuration by merging the incoming derived API configuration.
                var apiConfigurationExisting = (TConfiguration)apiConfiguration;
                var apiObjectFactoryExisting = (TMutableFactory)apiConfigurationExisting.ApiMutableFactory;
                apiObjectFactoryExisting.Merge(apiObjectFactoryIncoming);
                return;
            }

            // Create a new API configuration from the incoming derived API configuration.
            var apiConfigurationNew = ApiTypeConfigurationFactory.CreateApiTypeConfiguration <TConfiguration, TMutableFactory, TMutable>(clrType, apiTypeConfigurationOpenGenericType, apiPrecedenceStack, apiObjectFactoryIncoming);

            dictionary.Add(clrType, apiConfigurationNew);

            ApiFrameworkLog.Trace($"Added {typeof(TConfiguration).Name} [ClrType={apiConfigurationNew.ClrType.Name}] at {apiPrecedenceLevel} Level".Indent(IndentConstants.ApiMutableSchemaModifier));
        }
Exemple #7
0
        public ApiObjectTypeConfiguration <TObject> GetOrAddApiObjectTypeConfiguration <TObject>(ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                                 ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(apiPrecedenceStack != null);

            var apiObjectTypeConfiguration = GetOrAddApiConfiguration <TObject, ApiObjectTypeConfiguration <TObject> >(this.ApiObjectTypeConfigurationDictionary, ApiObjectTypeConfigurationOpenGenericType, apiPrecedenceLevel, apiPrecedenceStack);

            return(apiObjectTypeConfiguration);
        }
Exemple #8
0
        public ApiEnumerationTypeConfiguration <TEnum> GetOrAddApiEnumerationTypeConfiguration <TEnum>(ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                                       ApiPrecedenceStack apiPrecedenceStack)
            where TEnum : Enum
        {
            Contract.Requires(apiPrecedenceStack != null);

            var apiEnumTypeConfiguration = GetOrAddApiConfiguration <TEnum, ApiEnumerationTypeConfiguration <TEnum> >(this.ApiEnumerationTypeConfigurationDictionary, ApiEnumerationTypeConfigurationOpenGenericType, apiPrecedenceLevel, apiPrecedenceStack);

            return(apiEnumTypeConfiguration);
        }
Exemple #9
0
        // PUBLIC CONSTRUCTORS //////////////////////////////////////////////
        #region Constructors
        public ApiPropertyConfiguration(Type clrDeclaringType, string clrName, Type clrType, ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(clrDeclaringType != null);
            Contract.Requires(clrName.SafeHasContent());
            Contract.Requires(clrType != null);
            Contract.Requires(apiPrecedenceStack != null);

            this.ClrName                   = clrName;
            this.ClrType                   = clrType;
            this.ApiPrecedenceStack        = apiPrecedenceStack;
            this.ApiMutablePropertyFactory = new ApiMutableFactory <ApiMutableSchema, ApiMutableProperty>(this.CreateApiMutablePropertyFactory(clrDeclaringType, clrName, clrType), IndentConstants.ApiProperty);
        }
Exemple #10
0
        // INTERNAL CONSTRUCTORS ////////////////////////////////////////////
        #region Constructors
        public ApiCollectionTypeConfiguration(Type clrDeclaringType, Type clrType, Type clrItemType, ApiPrecedenceStack apiPrecedenceStack)
            : base(clrType)
        {
            Contract.Requires(clrDeclaringType != null);
            Contract.Requires(clrType != null);
            Contract.Requires(clrItemType != null);
            Contract.Requires(apiPrecedenceStack != null);

            this.ApiPrecedenceStack = apiPrecedenceStack;
            this.ApiMutableCollectionTypeFactory = new ApiMutableFactory <ApiMutableSchema, ApiMutableCollectionType>(this.CreateApiMutableCollectionTypeFactory(clrDeclaringType, clrType, clrItemType), IndentConstants.ApiMutableCollectionType);
        }
        public static TApiTypeConfiguration CreateApiTypeConfiguration <TApiTypeConfiguration, TApiTypeConfigurationFactory, TApiTypeContext>(Type clrType,
                                                                                                                                              Type apiTypeConfigurationOpenGenericType,
                                                                                                                                              ApiPrecedenceStack apiPrecedenceStack,
                                                                                                                                              TApiTypeConfigurationFactory apiTypeConfigurationFactory)
            where TApiTypeConfiguration : ApiTypeConfiguration
            where TApiTypeConfigurationFactory : ApiMutableFactory <ApiMutableSchema, TApiTypeContext>
        {
            Contract.Requires(clrType != null);
            Contract.Requires(apiTypeConfigurationOpenGenericType != null);
            Contract.Requires(apiPrecedenceStack != null);
            Contract.Requires(apiTypeConfigurationFactory != null);

            var apiTypeConfigurationClosedGenericType = apiTypeConfigurationOpenGenericType.MakeGenericType(clrType);
            var apiTypeConfigurationNewExpression     = ExpressionBuilder.New <ApiPrecedenceStack, ApiMutableFactory <ApiMutableSchema, TApiTypeContext>, TApiTypeConfiguration>(ReflectionFlags.NonPublic, apiTypeConfigurationClosedGenericType);
            var apiTypeConfigurationNewLambda         = apiTypeConfigurationNewExpression.Compile();
            var apiTypeConfiguration = apiTypeConfigurationNewLambda(apiPrecedenceStack, apiTypeConfigurationFactory);

            return(apiTypeConfiguration);
        }