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 {0} {{".FormatWith(generalData.Namespace)); writer.WriteLine("public sealed partial class {0}: StaticFile {{".FormatWith(generalData.ClassName)); UrlStatics.GenerateUrlClasses( writer, generalData.ClassName, null, Enumerable.Empty <WebItemParameter>().Materialize(), Enumerable.Empty <WebItemParameter>().Materialize(), !inVersionedFolder); writer.WriteLine("private readonly {0} folderSetup;".FormatWith(folderSetupClassName)); if (inVersionedFolder) { writer.WriteLine("public {0}(): base( true ) {{".FormatWith(generalData.ClassName)); } else { writer.WriteLine("public {0}( bool disableVersioning = false ): base( !disableVersioning ) {{".FormatWith(generalData.ClassName)); } writer.WriteLine("folderSetup = new {0}();".FormatWith(folderSetupClassName)); writer.WriteLine("}"); writer.WriteLine("public override EntitySetupBase EsAsBaseType => folderSetup;"); UrlStatics.GenerateGetEncoderMethod( writer, "", Enumerable.Empty <WebItemParameter>().Materialize(), Enumerable.Empty <WebItemParameter>().Materialize(), p => "false", !inVersionedFolder); writer.WriteLine( "protected override DateTimeOffset getBuildDateAndTime() => {0};".FormatWith(AppStatics.GetLiteralDateTimeExpression(DateTimeOffset.UtcNow))); writer.WriteLine("protected override bool isFrameworkFile => {0};".FormatWith(inFramework ? "true" : "false")); writer.WriteLine( "protected override string relativeFilePath => @\"{0}\";".FormatWith( generalData.PathRelativeToProject.Substring( ((inFramework ? EnterpriseWebFramework.StaticFile.FrameworkStaticFilesSourceFolderPath : EnterpriseWebFramework.StaticFile.AppStaticFilesFolderName) + Path.DirectorySeparatorChar).Length))); writer.WriteLine("}"); writer.WriteLine("}"); }
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("}"); }