Пример #1
0
        public string CreateInterfaceCode(CodeNames codeNameBase, int maxServiceCount)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(
                $@"    public interface {GetInterfaceNameAndTemplateParamaters(codeNameBase)}
    {{
");
            PolicyScopeResultSelectorGenerator servicePolicyScopeBuilderGenerator = new PolicyScopeResultSelectorGenerator();

            for (int serviceCount = 0; serviceCount <= maxServiceCount; serviceCount++)
            {
                if (serviceCount != 0)
                {
                    sb.AppendLine();
                }

                CodeNames codeNames = new CodeNames(serviceCount, false, codeNameBase.IsAsync);

                sb.AppendLine(
                    $@"        {servicePolicyScopeBuilderGenerator.GetInterfaceNameAndTemplateParamaters(codeNames)} {codeNames.FunctionWithServicesName}{codeNames.TemplateParameters}();");
            }

            sb.AppendLine(
                $@"    }}");

            return(sb.ToString());
        }
Пример #2
0
        public string CreateClassCode(CodeNames codeNameBase, int maxServiceCount)
        {
            StringBuilder sb = new StringBuilder();

            string interfacePolicyName = codeNameBase.IsAsync ? "IAsyncPolicy" : "ISyncPolicy";
            string variablePolicyName  = codeNameBase.IsAsync ? "asyncPolicy" : "syncPolicy";

            sb.Append(
                $@"    internal class {GetClassNameAndTemplateParamaters(codeNameBase)} : {codeNameBase.BaseClassName}, {GetInterfaceNameAndTemplateParamaters(codeNameBase)}
    {{
        internal {GetClassName(codeNameBase)}(IServiceProvider serviceProvider, {interfacePolicyName} {variablePolicyName})
            : base(serviceProvider, {variablePolicyName})
        {{
        }}

");

            PolicyScopeResultSelectorGenerator servicePolicyScopeBuilderGenerator = new PolicyScopeResultSelectorGenerator();

            for (int serviceCount = 0; serviceCount <= maxServiceCount; serviceCount++)
            {
                if (serviceCount != 0)
                {
                    sb.AppendLine();
                }
                CodeNames codeNames = new CodeNames(serviceCount, false, codeNameBase.IsAsync);

                sb.AppendLine(
                    $@"        public {servicePolicyScopeBuilderGenerator.GetInterfaceNameAndTemplateParamaters(codeNames)} {codeNames.FunctionWithServicesName}{codeNames.TemplateParameters}()
        {{
            return new {servicePolicyScopeBuilderGenerator.GetClassNameAndTemplateParamaters(codeNames)}(this);
        }}");
            }

            sb.AppendLine(
                $@"    }}");

            return(sb.ToString());
        }