//----------------------------------------------------------------------------------------------------------------------------------------------------- protected override void Implement(ITypeFactoryContext <Empty.ContextExtension> context, TypeWriter writer) { throw new NotImplementedException(); //var txHandlerTypes = GenerateTxHandlerTypes(context, writer); //writer.IMPLEMENTS<ITxResourceHandlerList>(); //writer.PUBLIC().METHOD_OF<ITxResourceHandlerList>(x => x.GetHandlerTypes).BODY(G => { // G.RETURN(G.ARRAY<Type>(txHandlerTypes)); //}); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private TypeMember GenerateTxHandlerType( ITypeFactoryContext <Empty.ContextExtension> context, TypeWriter writer, TypeMember txType, MethodMember txMethod) { throw new NotImplementedException(); //var handlerType = writer.PRIVATE().CLASS($"HandlerOf_{txMethod.Name}").EXTENDS<RestResourceHandlerBase>(); //handlerType.PROTECTED().METHOD(nameof(RestResourceHandlerBase.OnPatch)) }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private List <TypeMember> GenerateTxHandlerTypes(ITypeFactoryContext <Empty.ContextExtension> context, TypeWriter writer) { var txType = context.Key.PrimaryContract; var txMethods = txType.SelectPublicInstance <MethodMember>(where : m => m.HasAttribute <TransactionScriptMethodAttribute>()); var txHandlerTypes = new List <TypeMember>(); foreach (var method in txMethods) { txHandlerTypes.Add(GenerateTxHandlerType(context, writer, txType, method)); } return(txHandlerTypes); }
protected override void Validate(ITypeFactoryContext <Empty.ContextExtension> context) { var txType = context.Key.PrimaryContract; if (!txType.HasAttribute <TransactionScriptComponentAttribute>()) { throw NewValidationException(txType, $"Must be marked with a {typeof(TransactionScriptComponentAttribute).Name}."); } if (!txType.SelectPublicInstance <MethodMember>(where : m => m.HasAttribute <TransactionScriptMethodAttribute>()).Any()) { throw NewValidationException(txType, $"Must have at least one method marked with {typeof(TransactionScriptMethodAttribute).Name}."); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- void ITypeFactoryConvention.Declare(ITypeFactoryContext context) { context.Type.Namespace = this.GetType().Namespace; if (context.Key.PrimaryContract != null) { context.Type.Name = $"{ConventionName}_Of_{context.Key.PrimaryContract.FullName}"; } else { context.Type.Name = $"{ConventionName}_Of_UnknownComponent"; } this.Declare((ITypeFactoryContext <TContextExtension>)context); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected virtual void Implement(ITypeFactoryContext <TContextExtension> context, TypeWriter writer) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected virtual void Declare(ITypeFactoryContext <TContextExtension> context) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected virtual void Validate(ITypeFactoryContext <TContextExtension> context) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected virtual bool ShouldApply(ITypeFactoryContext <TContextExtension> context) { return(true); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- void ITypeFactoryConvention.Implement(ITypeFactoryContext context) { //var writer = new TypeWriter() this.Implement((ITypeFactoryContext <TContextExtension>)context, null); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- void ITypeFactoryConvention.Validate(ITypeFactoryContext context) { this.Validate((ITypeFactoryContext <TContextExtension>)context); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- bool ITypeFactoryConvention.ShouldApply(ITypeFactoryContext context) { return(this.ShouldApply((ITypeFactoryContext <TContextExtension>)context)); }
protected override void Implement( ITypeFactoryContext <Empty.ContextExtension> context, TypeWriter writer) { }
public TypeWriter(ITypeFactoryContext context) { _context = context; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void ExecuteConventionPipeline(List <ITypeFactoryConvention> pipeline, ITypeFactoryContext factoryContext) { var effectivePipeline = pipeline.Where(sink => sink.ShouldApply(factoryContext)).ToImmutableList(); foreach (var sink in effectivePipeline) { sink.Validate(factoryContext); } foreach (var sink in effectivePipeline) { sink.Declare(factoryContext); } foreach (var sink in effectivePipeline) { sink.Implement(factoryContext); } }