private void buildSourceType(GeneratedAssembly assembly, CompiledSourceType handlerType, GeneratedType compiledHandlerType) { var rules = _storeOptions.CreateGenerationRules(); var sourceBaseType = typeof(CompiledQuerySource <,>).MakeGenericType(_plan.OutputType, _plan.QueryType); var sourceType = assembly.AddType(_typeName, sourceBaseType); var hardcoded = new InjectedField(typeof(HardCodedParameters), "hardcoded"); sourceType.AllInjectedFields.Add(hardcoded); var buildHandler = sourceType.MethodFor("BuildHandler"); switch (handlerType) { case CompiledSourceType.Cloneable: var innerField = new InjectedField(typeof(IMaybeStatefulHandler)); sourceType.AllInjectedFields.Add(innerField); var statistics = _plan.StatisticsMember == null ? "null" : $"query.{_plan.StatisticsMember.Name}"; buildHandler.Frames.Code( $"return new {assembly.Namespace}.{compiledHandlerType.TypeName}({innerField.Usage}, query, {statistics}, _hardcoded);"); break; case CompiledSourceType.Stateless: var inner = new InjectedField(typeof(IQueryHandler <>).MakeGenericType(_plan.OutputType)); sourceType.AllInjectedFields.Add(inner); buildHandler.Frames.Code( $"return new {assembly.Namespace}.{compiledHandlerType.TypeName}({inner.Usage}, query, _hardcoded);"); break; case CompiledSourceType.Complex: var innerField2 = new InjectedField(typeof(IMaybeStatefulHandler)); sourceType.AllInjectedFields.Add(innerField2); buildHandler.Frames.Code( $"return new {assembly.Namespace}.{compiledHandlerType.TypeName}({innerField2.Usage}, query, _hardcoded);"); break; } }
internal void Compile(StoreOptions options) { var rules = options.CreateGenerationRules(); Compile(options, rules); }