//-----------------------------------------------------------------------------------------------------------------------------------------------------

        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}.");
            }
        }
Esempio n. 5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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);
        }
Esempio n. 6
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual void Implement(ITypeFactoryContext <TContextExtension> context, TypeWriter writer)
        {
        }
Esempio n. 7
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual void Declare(ITypeFactoryContext <TContextExtension> context)
        {
        }
Esempio n. 8
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual void Validate(ITypeFactoryContext <TContextExtension> context)
        {
        }
Esempio n. 9
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual bool ShouldApply(ITypeFactoryContext <TContextExtension> context)
        {
            return(true);
        }
Esempio n. 10
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        void ITypeFactoryConvention.Implement(ITypeFactoryContext context)
        {
            //var writer = new TypeWriter()
            this.Implement((ITypeFactoryContext <TContextExtension>)context, null);
        }
Esempio n. 11
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        void ITypeFactoryConvention.Validate(ITypeFactoryContext context)
        {
            this.Validate((ITypeFactoryContext <TContextExtension>)context);
        }
Esempio n. 12
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        bool ITypeFactoryConvention.ShouldApply(ITypeFactoryContext context)
        {
            return(this.ShouldApply((ITypeFactoryContext <TContextExtension>)context));
        }
Esempio n. 13
0
 protected override void Implement(
     ITypeFactoryContext <Empty.ContextExtension> context,
     TypeWriter writer)
 {
 }
Esempio n. 14
0
 public TypeWriter(ITypeFactoryContext context)
 {
     _context = context;
 }
Esempio n. 15
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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);
            }
        }