internal void GenerateCode(TextWriter writer)
 {
     writer.WriteLine("namespace " + generalData.Namespace + " {");
     writer.WriteLine("public sealed partial class {0}: EntitySetupBase {{".FormatWith(generalData.ClassName));
     OptionalParameterPackageStatics.WriteClassIfNecessary(writer, requiredParameters, optionalParameters);
     ParametersModificationStatics.WriteClassIfNecessary(writer, requiredParameters.Concat(optionalParameters));
     UrlStatics.GenerateUrlClasses(writer, generalData.ClassName, null, requiredParameters, optionalParameters, false);
     if (optionalParameters.Any())
     {
         InfoStatics.WriteSpecifyParameterDefaultsMethod(writer, false);
     }
     InfoStatics.WriteParameterMembers(writer, requiredParameters, optionalParameters);
     if (requiredParameters.Any() || optionalParameters.Any())
     {
         writer.WriteLine("internal ParametersModification parametersModification;");
     }
     if (optionalParameters.Any())
     {
         writer.WriteLine("private Action<OptionalParameterSpecifier, Parameters> optionalParameterSetter;");
     }
     InfoStatics.WriteConstructorAndHelperMethods(writer, generalData, requiredParameters, optionalParameters, false, true);
     if (requiredParameters.Any() || optionalParameters.Any())
     {
         writer.WriteLine("{0} override void InitParametersModification() {{".FormatWith(projectContainsFramework ? "protected internal" : "protected"));
         writer.WriteLine("parametersModification = new ParametersModification();");
         foreach (var i in requiredParameters.Concat(optionalParameters))
         {
             writer.WriteLine("parametersModification.{0} = {0};".FormatWith(i.PropertyName));
         }
         writer.WriteLine("}");
     }
     else
     {
         writer.WriteLine("{0} override void InitParametersModification() {{}}".FormatWith(projectContainsFramework ? "protected internal" : "protected"));
     }
     UrlStatics.GenerateGetEncoderMethod(writer, "", requiredParameters, optionalParameters, p => "true", false);
     writer.WriteLine(
         "internal {0} ReCreate() => new {0}({1});".FormatWith(
             generalData.ClassName,
             StringTools.ConcatenateWithDelimiter(
                 ", ",
                 InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(requiredParameters, parameter => parameter.PropertyName),
                 optionalParameters.Any() ? "optionalParameterSetter: optionalParameterSetter" : "")
             .Surround(" ", " ")));
     WebFrameworkStatics.WriteReCreateFromNewParameterValuesMethod(
         writer,
         requiredParameters,
         "internal {0} ".FormatWith(generalData.ClassName),
         generalData.ClassName,
         "");
     writeEqualsMethod(writer);
     InfoStatics.WriteGetHashCodeMethod(writer, generalData.PathRelativeToProject, requiredParameters, optionalParameters);
     writer.WriteLine("}");
     writer.WriteLine("}");
 }
        internal void GenerateCode(TextWriter writer)
        {
            writer.WriteLine("namespace " + generalData.Namespace + " {");
            writer.WriteLine("public partial class " + generalData.ClassName + " {");

            writeInfoClass(writer);
            OptionalParameterPackageStatics.WriteClassIfNecessary(writer, optionalParameters);
            ParametersModificationStatics.WriteClassIfNecessary(writer, requiredParameters.Concat(optionalParameters));
            if (entitySetup != null)
            {
                writer.WriteLine("private EntitySetup es;");
            }
            writer.WriteLine("private Info info;");
            if (requiredParameters.Any() || optionalParameters.Any())
            {
                writer.WriteLine("private ParametersModification parametersModification;");
            }
            writer.WriteLine("public override EntitySetupBase EsAsBaseType { get { return " + (entitySetup != null ? "es" : "null") + "; } }");
            writer.WriteLine("public override PageInfo InfoAsBaseType { get { return info; } }");
            writer.WriteLine(
                "public override ParametersModificationBase ParametersModificationAsBaseType { get { return " +
                (requiredParameters.Any() || optionalParameters.Any() ? "parametersModification" : "null") + "; } }");
            writeInitEntitySetupMethod(writer);
            WebMetaLogicStatics.WriteClearInfoMethod(writer, "protected override void ");
            WebMetaLogicStatics.WriteCreateInfoFromQueryStringMethod(
                writer,
                requiredParameters,
                optionalParameters,
                "protected override void ",
                entitySetup != null ? "es.info" : "");
            writeGetInfoMethod(writer);
            generalData.ReadPageStateVariablesFromCodeAndWriteTypedPageStateMethods(writer);
            WebMetaLogicStatics.WriteCreateInfoFromNewParameterValuesMethod(
                writer,
                requiredParameters,
                optionalParameters,
                "protected override PageInfo ",
                entitySetup != null ? "es.CreateInfoFromNewParameterValues()" : "");

            writer.WriteLine("}");
            writer.WriteLine("}");
        }
Beispiel #3
0
 internal void GenerateCode(TextWriter writer)
 {
     writer.WriteLine("namespace " + generalData.Namespace + " {");
     writer.WriteLine("public partial class " + generalData.ClassName + " {");
     writeInfoClass(writer);
     OptionalParameterPackageStatics.WriteClassIfNecessary(writer, optionalParameters);
     ParametersModificationStatics.WriteClassIfNecessary(writer, requiredParameters.Concat(optionalParameters));
     writer.WriteLine("internal Info info { get; private set; }");
     if (requiredParameters.Any() || optionalParameters.Any())
     {
         writer.WriteLine("internal ParametersModification parametersModification;");
     }
     writer.WriteLine("EntitySetupInfo EntitySetupBase.InfoAsBaseType { get { return info; } }");
     writer.WriteLine(
         "ParametersModificationBase EntitySetupBase.ParametersModificationAsBaseType { get { return " +
         (requiredParameters.Any() || optionalParameters.Any() ? "parametersModification" : "null") + "; } }");
     WebMetaLogicStatics.WriteCreateInfoFromQueryStringMethod(writer, requiredParameters, optionalParameters, "void EntitySetupBase.", "");
     WebMetaLogicStatics.WriteCreateInfoFromNewParameterValuesMethod(writer, requiredParameters, optionalParameters, "internal Info ", "");
     writer.WriteLine("}");
     writer.WriteLine("}");
 }
Beispiel #4
0
        internal void GenerateCode(TextWriter writer)
        {
            writer.WriteLine("namespace {0} {{".FormatWith(generalData.Namespace));
            writer.WriteLine(
                "public sealed partial class {0}: {1} {{".FormatWith(
                    generalData.ClassName,
                    generalData.IsPage() ? "PageBase" : generalData.IsAutoCompleteService() ? "AutoCompleteService" : "ResourceBase"));

            OptionalParameterPackageStatics.WriteClassIfNecessary(writer, requiredParameters, optionalParameters);
            if (generalData.IsPage())
            {
                ParametersModificationStatics.WriteClassIfNecessary(writer, requiredParameters.Concat(optionalParameters));
            }
            UrlStatics.GenerateUrlClasses(writer, generalData.ClassName, entitySetup, requiredParameters, optionalParameters, false);
            if (optionalParameters.Any())
            {
                generateSegmentParameterSpecifier(writer);
            }
            writeGetInfoMethod(writer);
            if (optionalParameters.Any())
            {
                InfoStatics.WriteSpecifyParameterDefaultsMethod(writer, entitySetup != null);
            }
            if (entitySetup != null)
            {
                writer.WriteLine("public EntitySetup Es;");
            }
            InfoStatics.WriteParameterMembers(writer, requiredParameters, optionalParameters);
            if (generalData.IsPage() && (requiredParameters.Any() || optionalParameters.Any()))
            {
                writer.WriteLine("private ParametersModification parametersModification;");
            }
            if (optionalParameters.Any())
            {
                writer.WriteLine("private readonly Lazy<SegmentParameterSpecifier> segmentParameterSpecifier;");
                writer.WriteLine(
                    "private Action<{0}> optionalParameterSetter;".FormatWith(
                        StringTools.ConcatenateWithDelimiter(", ", "OptionalParameterSpecifier", entitySetup != null ? "EntitySetup" : "", "Parameters")));
            }
            InfoStatics.WriteConstructorAndHelperMethods(writer, generalData, requiredParameters, optionalParameters, entitySetup != null, false);
            writer.WriteLine("public override EntitySetupBase EsAsBaseType => {0};".FormatWith(entitySetup != null ? "Es" : "null"));
            if (generalData.IsPage())
            {
                if (requiredParameters.Any() || optionalParameters.Any())
                {
                    writer.WriteLine("protected override void initParametersModification() {");
                    writer.WriteLine("parametersModification = new ParametersModification();");
                    foreach (var i in requiredParameters.Concat(optionalParameters))
                    {
                        writer.WriteLine("parametersModification.{0} = {0};".FormatWith(i.PropertyName));
                    }
                    writer.WriteLine("}");
                }
                else
                {
                    writer.WriteLine("protected override void initParametersModification() {}");
                }
            }
            UrlStatics.GenerateGetEncoderMethod(
                writer,
                entitySetup != null ? "Es" : "",
                requiredParameters,
                optionalParameters,
                p => "segmentParameterSpecifier.Value.{0}IsSegmentParameter".FormatWith(p.PropertyName),
                false);
            if (optionalParameters.Any())
            {
                writer.WriteLine("partial void specifySegmentParameters( SegmentParameterSpecifier specifier );");
            }
            if (!generalData.IsPage())
            {
                writer.WriteLine("public override bool MatchesCurrent() => base.MatchesCurrent();");
            }
            writer.WriteLine(
                "{0} override ResourceBase ReCreate() => new {1}( {2} );".FormatWith(
                    projectContainsFramework ? "protected internal" : "protected",
                    generalData.ClassName,
                    StringTools.ConcatenateWithDelimiter(
                        ", ",
                        entitySetup != null ? "Es.ReCreate()" : "",
                        InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(requiredParameters, parameter => parameter.PropertyName),
                        optionalParameters.Any() ? "optionalParameterSetter: optionalParameterSetter" : "",
                        "uriFragmentIdentifier: uriFragmentIdentifier")));
            if (generalData.IsPage())
            {
                WebFrameworkStatics.WriteReCreateFromNewParameterValuesMethod(
                    writer,
                    requiredParameters,
                    "protected override PageBase ",
                    generalData.ClassName,
                    entitySetup != null ? "Es.ReCreateFromNewParameterValues()" : "");
            }
            writeEqualsMethod(writer);
            InfoStatics.WriteGetHashCodeMethod(writer, generalData.PathRelativeToProject, requiredParameters, optionalParameters);

            writer.WriteLine("}");
            writer.WriteLine("}");
        }