private static void WriteDictionaryExtensions(DataClassWriter writer, Property property) { var propertyInstance = property.Name.ToInstance(); var(keyType, valueType) = property.GetDictionaryKeyValueTypes(); var propertySingular = property.Name.ToSingular(); var propertySingularInstance = property.Name.ToSingular().ToInstance(); var keyInstance = $"{propertySingularInstance}Key"; var valueInstance = $"{propertySingularInstance}Value"; var propertyAccess = $"toolSettings.{property.Name}Internal"; writer .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new dictionary", property) .WriteMethod($"Set{property.Name}", $"IDictionary<{keyType}, {valueType}> {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToDictionary(x => x.Key, x => x.Value, {property.GetKeyComparer()});") .WriteSummaryExtension($"Clears {property.GetCrefTag()}", property) .WriteMethod($"Clear{property.Name}", $"{propertyAccess}.Clear();") .WriteSummaryExtension($"Adds a new key-value-pair {property.GetCrefTag()}", property) .WriteMethod($"Add{propertySingular}", new[] { $"{keyType} {keyInstance}", $"{valueType} {valueInstance}" }, $"{propertyAccess}.Add({keyInstance}, {valueInstance});") .WriteSummaryExtension($"Removes a key-value-pair from {property.GetCrefTag()}", property) .WriteMethod($"Remove{propertySingular}", $"{keyType} {keyInstance}", $"{propertyAccess}.Remove({keyInstance});") .WriteSummaryExtension($"Sets a key-value-pair in {property.GetCrefTag()}", property) .WriteMethod($"Set{propertySingular}", new[] { $"{keyType} {keyInstance}", $"{valueType} {valueInstance}" }, $"{propertyAccess}[{keyInstance}] = {valueInstance};"); writer.ForEach(property.Delegates, x => WriteDictionaryDelegateExtensions(writer, property, x)); }
// TODO [3]: less naming? -> value private static void WriteMethods(DataClassWriter writer, Property property) { if (property.CustomImpl) return; writer.WriteLine($"#region {property.Name}"); if (!property.IsList() && !property.IsDictionary() && !property.IsLookupTable()) { writer .WriteSummaryExtension($"Sets {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod( $"Set{property.Name}", property, $"toolSettings.{property.Name} = {property.Name.ToInstance().EscapeParameter()};") .WriteSummaryExtension($"Resets {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod( $"Reset{property.Name}", $"toolSettings.{property.Name} = null;"); } if (property.IsBoolean()) WriteBooleanExtensions(writer, property); else if (property.IsList()) WriteListExtensions(writer, property); else if (property.IsDictionary()) WriteDictionaryExtensions(writer, property); else if (property.IsLookupTable()) WriteLookupExtensions(writer, property); writer.WriteLine("#endregion"); }
private static void WriteLookupExtensions(DataClassWriter writer, Property property) { var propertyInstance = property.Name.ToInstance(); var(keyType, valueType) = property.GetLookupTableKeyValueTypes(); var propertySingular = property.Name.ToSingular(); var propertySingularInstance = property.Name.ToSingular().ToInstance(); var keyInstance = $"{propertyInstance}Key"; var valueInstance = $"{propertyInstance}Value"; var valueInstances = $"{propertyInstance}Values"; var propertyAccess = $"toolSettings.{property.Name}Internal"; // TODO: params // TODO: remove by key writer .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new lookup table", property) .WriteMethod($"Set{property.Name}", $"ILookup<{keyType}, {valueType}> {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToLookupTable(StringComparer.OrdinalIgnoreCase);") .WriteSummaryExtension($"Clears {property.GetCrefTag()}", property) .WriteMethod($"Clear{property.Name}", $"{propertyAccess}.Clear();") .WriteSummaryExtension($"Adds new values for the given key to {property.GetCrefTag()}", property) .WriteMethod($"Add{property.Name}", new[] { $"{keyType} {keyInstance}", $"params {valueType}[] {valueInstances}" }, $"{propertyAccess}.AddRange({keyInstance}, {valueInstances});") .WriteSummaryExtension($"Adds new values for the given key to {property.GetCrefTag()}", property) .WriteMethod($"Add{property.Name}", new[] { $"{keyType} {keyInstance}", $"IEnumerable<{valueType}> {valueInstances}" }, $"{propertyAccess}.AddRange({keyInstance}, {valueInstances});") .WriteSummaryExtension($"Removes a single {propertySingularInstance} from {property.GetCrefTag()}", property) .WriteMethod($"Remove{propertySingular}", new[] { $"{keyType} {keyInstance}", $"{valueType} {valueInstance}" }, $"{propertyAccess}.Remove({keyInstance}, {valueInstance});"); }
private static DataClassWriter WriteConfigureArguments(this DataClassWriter writer) { var formatProperties = writer.DataClass.Properties.Where(x => x.Format != null).ToList(); if ((writer.DataClass as SettingsClass)?.Task.DefiniteArgument == null && formatProperties.Count == 0) { return(writer); } var argumentAdditions = formatProperties.Select(GetArgumentAddition).ToArray(); var hasArguments = argumentAdditions.Length > 0; if (hasArguments) { argumentAdditions[argumentAdditions.Length - 1] += ";"; } return(writer .WriteLine("protected override Arguments ConfigureArguments(Arguments arguments)") .WriteBlock(w => w .WriteLine("arguments") .WriteLine($"{GetCommandAdditionOrNull(writer.DataClass)}{(hasArguments ? string.Empty : ";")}") .ForEachWriteLine(argumentAdditions) .WriteLine("return base.ConfigureArguments(arguments);"))); }
public static void Run(DataClass dataClass, ToolWriter toolWriter) { if (dataClass.OmitDataClass) { return; } if (dataClass.IsToolSettingsClass) { foreach (var property in dataClass.Properties) { CheckMissingValue(property); CheckMissingSecret(property); } } var writer = new DataClassWriter(dataClass, toolWriter); var baseType = dataClass.BaseClass ?? (dataClass.Name.EndsWith("Settings") ? "ToolSettings" : "ISettingsEntity"); writer .WriteLine($"#region {dataClass.Name}") .WriteSummary(dataClass) .WriteLine("[PublicAPI]") .WriteObsoleteAttributeWhenObsolete(dataClass) .WriteLine("[ExcludeFromCodeCoverage]") .WriteLine("[Serializable]") .WriteLine($"public partial class {dataClass.Name} : {baseType}") .WriteBlock(w => w .WriteToolPath() .WriteLogger() .ForEach(dataClass.Properties, WritePropertyDeclaration) .WriteConfigureArguments()) .WriteLine("#endregion"); }
private static DataClassWriter WriteConfigureArguments(this DataClassWriter writer) { var formatProperties = writer.DataClass.Properties.Where(x => x.Format != null).ToList(); if ((writer.DataClass as SettingsClass)?.Task.DefiniteArgument == null && formatProperties.Count == 0) { return(writer); } var argumentAdditions = formatProperties.Select(GetArgumentAddition).ToList(); var settingsClass = writer.DataClass as SettingsClass; if (settingsClass?.Task.DefiniteArgument != null) { argumentAdditions.Insert(index: 0, $" .Add({settingsClass.Task.DefiniteArgument.DoubleQuote()})"); } var hasArguments = argumentAdditions.Count > 0; if (hasArguments) { argumentAdditions[argumentAdditions.Count - 1] += ";"; } return(writer .WriteLine("protected override Arguments ConfigureArguments(Arguments arguments)") .WriteBlock(w => w .WriteLine("arguments") .ForEachWriteLine(argumentAdditions) .WriteLine("return base.ConfigureArguments(arguments);"))); }
private static DataClassWriter WriteMethod( this DataClassWriter writer, string name, string additionalParameter, params string[] modifications) { return(writer.WriteMethod(name, new[] { additionalParameter }, modifications)); }
private static DataClassWriter WriteConfigureArguments(this DataClassWriter writer) { var formatProperties = writer.DataClass.Properties.Where(x => x.Format != null).ToList(); if ((writer.DataClass as SettingsClass)?.Task.DefiniteArgument == null && formatProperties.Count == 0) { return(writer); } var argumentAdditions = formatProperties.Select(GetArgumentAddition).ToArray(); ref var last = ref argumentAdditions[argumentAdditions.Length - 1];
private static void WriteListExtensions(DataClassWriter writer, Property property) { var propertyInternal = $"{property.Name}Internal"; var propertyInstance = property.Name.ToInstance().EscapeParameter(); var valueType = property.GetListValueType(); var propertyAccess = $"toolSettings.{propertyInternal}"; writer .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new list", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Set{property.Name}", $"params {valueType}[] {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToList();") .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new list", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Set{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToList();") .WriteSummaryExtension($"Adds values to {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Add{property.Name}", $"params {valueType}[] {propertyInstance}", $"{propertyAccess}.AddRange({propertyInstance});") .When(property.HasCustomListType(), _ => _ .WriteSummaryExtension($"Adds a value to {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Add{property.Name.ToSingular()}", $"Configure<{valueType}> configurator", $"{propertyAccess}.Add(configurator.InvokeSafe(new {valueType}()));")) .WriteSummaryExtension($"Adds values to {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Add{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"{propertyAccess}.AddRange({propertyInstance});") .WriteSummaryExtension($"Clears {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Clear{property.Name}", $"{propertyAccess}.Clear();") //.WriteSummaryExtension($"Adds a single {propertySingularInstance} to {property.GetCrefTag()}", property) //.WriteListAddMethod(propertySingular, propertySingularInstanceEscaped, valueType, propertyInternal) .WriteSummaryExtension($"Removes values from {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Remove{property.Name}", $"params {valueType}[] {propertyInstance}", $"var hashSet = new HashSet<{valueType}>({propertyInstance});", $"{propertyAccess}.RemoveAll(x => hashSet.Contains(x));") .WriteSummaryExtension($"Removes values from {property.GetCrefTag()}", property) .WriteObsoleteAttributeWhenObsolete(property) .WriteMethod($"Remove{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"var hashSet = new HashSet<{valueType}>({propertyInstance});", $"{propertyAccess}.RemoveAll(x => hashSet.Contains(x));"); }
private static void WritePropertyDeclaration(DataClassWriter writer, Property property) { if (property.CustomImpl) { return; } writer .WriteSummary(property) .WriteLine(GetPublicPropertyDeclaration(property)) .WriteLine(GetInternalPropertyDeclarationOrNull(property)); }
private static void WritePropertyDeclaration(DataClassWriter writer, Property property) { if (property.CustomImpl) { return; } writer .WriteSummary(property) .WritePublicProperty(property) .WriteInternalPropertyWhenNeeded(property); }
private static DataClassWriter WriteLogger(this DataClassWriter writer) { if (!writer.DataClass.IsToolSettingsClass) { return(writer); } var tool = writer.DataClass.Tool; var logger = $"{tool.GetClassName()}.{tool.Name}Logger"; return(writer.WriteLine($"public override Action<OutputType, string> CustomLogger => {logger};")); }
private static DataClassWriter WriteLogLevelParser(this DataClassWriter writer) { var tool = writer.DataClass.Tool; if (!tool.LogLevelParsing) { return(writer); } var logLevelParser = $"{tool.GetClassName()}.ParseLogLevel"; return(writer.WriteLine($"protected override Func<string, LogLevel> LogLevelParser => {logLevelParser};")); }
public static void Run(DataClass dataClass, ToolWriter toolWriter) { var writer = new DataClassWriter(dataClass, toolWriter); writer .WriteLine($"#region {dataClass.Name}Extensions") .WriteSummary(dataClass) .WriteLine("[PublicAPI]") .WriteLine("[ExcludeFromCodeCoverage]") .WriteLine($"public static partial class {dataClass.Name}Extensions") .WriteBlock(w => w.ForEach(dataClass.Properties, WriteMethods)) .WriteLine("#endregion"); }
private static void WriteBooleanExtensions(DataClassWriter writer, Property property) { var propertyAccess = $"toolSettings.{property.Name}"; writer .WriteSummaryExtension($"Enables {property.GetCrefTag()}", property) .WriteMethod($"Enable{property.Name}", $"{propertyAccess} = true;") .WriteSummaryExtension($"Disables {property.GetCrefTag()}", property) .WriteMethod($"Disable{property.Name}", $"{propertyAccess} = false;") .WriteSummaryExtension($"Toggles {property.GetCrefTag()}", property) .WriteMethod($"Toggle{property.Name}", $"{propertyAccess} = !{propertyAccess};"); // TODO [4]: negate for 'skip', 'no', 'disable' }
private static DataClassWriter WriteMethod( this DataClassWriter writer, string name, IEnumerable <string> additionalParameters, params string[] modifications) { var parameters = new[] { $"this {writer.DataClass.Name} toolSettings" }.Concat(additionalParameters); return(writer .WriteLine("[Pure]") .WriteLine($"public static {writer.DataClass.Name} {name}({parameters.Join()})") .WriteBlock(w => w .WriteLine("toolSettings = toolSettings.NewInstance();") .ForEachWriteLine(modifications) .WriteLine("return toolSettings;"))); }
private static DataClassWriter WriteToolPath(this DataClassWriter writer) { if (!(writer.DataClass is SettingsClass settingsClass)) { return(writer); } var tool = settingsClass.Tool.NotNull(); var resolver = !tool.CustomExecutable ? $"{tool.GetClassName()}.{tool.Name}Path" : "GetToolPath()"; return(writer .WriteSummary($"Path to the {tool.Name} executable.") .WriteLine($"public override string ToolPath => base.ToolPath ?? {resolver};")); }
private static DataClassWriter WriteMethod( this DataClassWriter writer, string name, IEnumerable<string> additionalParameters, params string[] modifications) { // NOTE: methods cannot be generic because constraints are not taken into account for overload resolution var parameters = new[] { $"this {writer.DataClass.Name} toolSettings" }.Concat(additionalParameters); return writer .WriteLine("[Pure]") .WriteLine($"public static {writer.DataClass.Name} {name}({parameters.JoinComma()})") .WriteBlock(w => w .WriteLine("toolSettings = toolSettings.NewInstance();") .ForEachWriteLine(modifications) .WriteLine("return toolSettings;")); }
private static DataClassWriter WriteToolPath(this DataClassWriter writer) { if (!(writer.DataClass is SettingsClass settingsClass)) { return(writer); } var tool = settingsClass.Tool.NotNull(); var resolvers = new List <string>(); if (tool.CustomExecutable) { resolvers.Add("{GetToolPath()}".DoubleQuoteInterpolated()); } if (tool.PackageId != null) { resolvers.Add("ToolPathResolver.GetPackageExecutable(" + $"{tool.PackageId.DoubleQuoteInterpolated()}, " + $"{(tool.PackageExecutable ?? "{GetPackageExecutable()}").DoubleQuoteInterpolated()})"); } if (tool.EnvironmentExecutable != null) { resolvers.Add("ToolPathResolver.GetEnvironmentExecutable(" + $"{tool.EnvironmentExecutable.DoubleQuoteInterpolated()})"); } if (tool.PathExecutable != null) { resolvers.Add("ToolPathResolver.GetPathExecutable(" + $"{tool.PathExecutable.DoubleQuoteInterpolated()})"); } if (resolvers.Count == 0) { return(writer); } Trace.Assert(resolvers.Count == 1, "resolvers.Count == 1"); return(writer .WriteSummary($"Path to the {tool.Name} executable.") .WriteLine($"public override string ToolPath => base.ToolPath ?? {resolvers.Single()};")); }
private static DataClassWriter WriteAssertValid(this DataClassWriter writer) { var validatedProperties = writer.DataClass.Properties.Where(x => x.Assertion != null).ToList(); if (validatedProperties.Count == 0) { return(writer); } return(writer .WriteLine("protected override void AssertValid()") .WriteBlock(w => w .WriteLine("base.AssertValid();") .ForEach( validatedProperties.Select(GetAssertion), assertion => w.WriteLine($"ControlFlow.Assert({assertion}, {assertion.DoubleQuote()});")) )); }
// ReSharper disable once CyclomaticComplexity private static DataClassWriter WriteToolPath(this DataClassWriter writer) { var settingsClass = writer.DataClass as SettingsClass; if (settingsClass == null) { return(writer); } var tool = settingsClass.Tool.NotNull(); var resolvers = new List <string> { "base.ToolPath" }; if (tool.CustomExecutable) { resolvers.Add("{GetToolPath()}".DoubleQuoteInterpolated()); } if (tool.PackageId != null) { resolvers.Add("ToolPathResolver.GetPackageExecutable(" + $"{tool.PackageId.DoubleQuoteInterpolated()}, " + $"{(tool.PackageExecutable ?? "{GetPackageExecutable()}").DoubleQuoteInterpolated()})"); } if (tool.EnvironmentExecutable != null) { resolvers.Add("ToolPathResolver.GetEnvironmentExecutable(" + $"{tool.EnvironmentExecutable.DoubleQuoteInterpolated()})"); } if (tool.PathExecutable != null) { resolvers.Add("ToolPathResolver.GetPathExecutable(" + $"{tool.PathExecutable.DoubleQuoteInterpolated()})"); } if (resolvers.Count == 1) { return(writer); } return(writer .WriteSummary($"Path to the {tool.Name} executable.") .WriteLine($"public override string ToolPath => {resolvers.Join(" ?? ")};")); }
public static void Run(DataClass dataClass, ToolWriter toolWriter) { if (dataClass.ArgumentConstruction) { foreach (var property in dataClass.Properties) { if (property.NoArgument) { continue; } if (new[] { "int", "bool" }.Contains(property.Type)) { continue; } if (property.Format != null && property.Format.Contains("{value}")) { continue; } Console.WriteLine($"Format for '{dataClass.Name}.{property.Name}' doesn't contain '{{value}}'."); } } var writer = new DataClassWriter(dataClass, toolWriter); var baseType = dataClass.BaseClass ?? (dataClass.Name.EndsWith("Settings") ? "ToolSettings" : "ISettingsEntity"); writer .WriteLine($"#region {dataClass.Name}") .WriteSummary(dataClass) .WriteLine("[PublicAPI]") .WriteObsoleteAttributeWhenObsolete(dataClass) .WriteLine("[ExcludeFromCodeCoverage]") .WriteLine("[Serializable]") .WriteLine($"public partial class {dataClass.Name} : {baseType}") .WriteBlock(w => w .WriteToolPath() .WriteLogLevelParser() .ForEach(dataClass.Properties, WritePropertyDeclaration) .WriteAssertValid() .WriteConfigureArguments()) .WriteLine("#endregion"); }
private static void WritePropertyDeclaration(DataClassWriter writer, Property property) { if (property.CustomImpl) { return; } var type = GetPublicPropertyType(property); var implementation = GetPublicPropertyImplementation(property); var hasInternalProperty = property.IsList() || property.IsDictionary() || property.IsLookupTable(); writer .WriteSummary(property) .WriteObsoleteAttributeWhenObsolete(property) .WriteLineIfTrue(!hasInternalProperty, GetJsonSerializationAttribute(property)) .WriteLineIfTrue(hasInternalProperty, GetJsonIgnoreAttribute(property)) .WriteLine($"public virtual {type} {property.Name} {implementation}") .WriteLineIfTrue(hasInternalProperty, GetJsonSerializationAttribute(property)) .WriteLineIfTrue(hasInternalProperty, $"internal {property.Type} {property.Name}Internal {{ get; set; }}{GetPropertyInitialization(property)}"); }
private static void WriteListExtensions(DataClassWriter writer, Property property) { var propertyInternal = $"{property.Name}Internal"; var propertyInstance = property.Name.ToInstance(); var valueType = property.GetListValueType(); var propertyAccess = $"toolSettings.{propertyInternal}"; writer .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new list", property) .WriteMethod($"Set{property.Name}", $"params {valueType}[] {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToList();") .WriteSummaryExtension($"Sets {property.GetCrefTag()} to a new list", property) .WriteMethod($"Set{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"{propertyAccess} = {propertyInstance}.ToList();") .WriteSummaryExtension($"Adds values to {property.GetCrefTag()}", property) .WriteMethod($"Add{property.Name}", $"params {valueType}[] {propertyInstance}", $"{propertyAccess}.AddRange({propertyInstance});") .WriteSummaryExtension($"Adds values to {property.GetCrefTag()}", property) .WriteMethod($"Add{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"{propertyAccess}.AddRange({propertyInstance});") .WriteSummaryExtension($"Clears {property.GetCrefTag()}", property) .WriteMethod($"Clear{property.Name}", $"{propertyAccess}.Clear();") //.WriteSummaryExtension($"Adds a single {propertySingularInstance} to {property.GetCrefTag()}", property) //.WriteListAddMethod(propertySingular, propertySingularInstanceEscaped, valueType, propertyInternal) .WriteSummaryExtension($"Removes values from {property.GetCrefTag()}", property) .WriteMethod($"Remove{property.Name}", $"params {valueType}[] {propertyInstance}", $"var hashSet = new HashSet<{valueType}>({propertyInstance});", $"{propertyAccess}.RemoveAll(x => hashSet.Contains(x));") .WriteSummaryExtension($"Removes values from {property.GetCrefTag()}", property) .WriteMethod($"Remove{property.Name}", $"IEnumerable<{valueType}> {propertyInstance}", $"var hashSet = new HashSet<{valueType}>({propertyInstance});", $"{propertyAccess}.RemoveAll(x => hashSet.Contains(x));"); }
private static DataClassWriter WriteMethod(this DataClassWriter writer, string name, Property property, string modification) { return(writer.WriteMethod(name, $"{property.GetNullabilityAttribute()}{property.GetNullableType()} {property.Name.ToInstance()}", modification)); }
private static DataClassWriter WriteMethod(this DataClassWriter writer, string name, Property property, string modification) { return writer.WriteMethod(name, $"{property.GetNullableType()} {property.Name.ToInstance().EscapeParameter()}", modification); }
private static void WriteDictionaryDelegateExtensions(DataClassWriter writer, Property property, Property delegateProperty) { writer.WriteLine($"#region {delegateProperty.Name}"); var propertyAccess = $"toolSettings.{property.Name}Internal"; var reference = $"<c>{delegateProperty.Name}</c>"; string GetModification(string newValue) => $"{propertyAccess}[{delegateProperty.Name.DoubleQuote()}] = {newValue};"; if (!delegateProperty.IsList()) { writer .WriteSummaryExtension($"Sets {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod( $"Set{delegateProperty.Name}", delegateProperty, GetModification(delegateProperty.Name.ToInstance())) .WriteSummaryExtension($"Resets {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod( $"Reset{delegateProperty.Name}", $"{propertyAccess}.Remove({delegateProperty.Name.DoubleQuote()});"); } if (delegateProperty.IsBoolean()) { writer .WriteSummaryExtension($"Enables {reference} in {property.GetCrefTag()}", property) .WriteMethod($"Enable{delegateProperty.Name}", GetModification("true")) .WriteSummaryExtension($"Disables {reference} in {property.GetCrefTag()}", property) .WriteMethod($"Disable{delegateProperty.Name}", GetModification("false")) .WriteSummaryExtension($"Toggles {reference} in {property.GetCrefTag()}", property) .WriteMethod($"Toggle{delegateProperty.Name}", $"ExtensionHelper.ToggleBoolean({propertyAccess}, {delegateProperty.Name.DoubleQuote()});"); } if (delegateProperty.IsList()) { var propertyInstance = delegateProperty.Name.ToInstance(); var valueType = delegateProperty.GetListValueType(); var propertyPlural = delegateProperty.Name.ToPlural(); writer .WriteSummaryExtension($"Sets {reference} in {property.GetCrefTag()} to a new collection", delegateProperty, property) .WriteMethod($"Set{propertyPlural}", $"params {valueType}[] {propertyInstance}", $"ExtensionHelper.SetCollection({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});") .WriteSummaryExtension($"Sets {reference} in {property.GetCrefTag()} to a new collection", delegateProperty, property) .WriteMethod($"Set{propertyPlural}", $"IEnumerable<{valueType}> {propertyInstance}", $"ExtensionHelper.SetCollection({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});") .WriteSummaryExtension($"Adds values to {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod($"Add{propertyPlural}", $"params {valueType}[] {propertyInstance}", $"ExtensionHelper.AddItems({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});") .WriteSummaryExtension($"Adds values to {reference} in existing {property.GetCrefTag()}", delegateProperty, property) .WriteMethod($"Add{propertyPlural}", $"IEnumerable<{valueType}> {propertyInstance}", $"ExtensionHelper.AddItems({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});") .WriteSummaryExtension($"Clears {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod($"Clear{propertyPlural}", $"{propertyAccess}.Remove({delegateProperty.Name.DoubleQuote()});") .WriteSummaryExtension($"Removes values from {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod($"Remove{propertyPlural}", $"params {valueType}[] {propertyInstance}", $"ExtensionHelper.RemoveItems({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});") .WriteSummaryExtension($"Removes values from {reference} in {property.GetCrefTag()}", delegateProperty, property) .WriteMethod($"Remove{propertyPlural}", $"IEnumerable<{valueType}> {propertyInstance}", $"ExtensionHelper.RemoveItems({propertyAccess}, {delegateProperty.Name.DoubleQuote()}, {propertyInstance}, {delegateProperty.Separator.SingleQuote()});"); } writer.WriteLine("#endregion"); }
private static DataClassWriter WriteMethod(this DataClassWriter writer, string name, Property property, string modification) { var attributes = property.Secret ?? false ? "[Secret] " : string.Empty; return(writer.WriteMethod(name, $"{attributes}{property.GetNullableType()} {property.Name.ToInstance().EscapeParameter()}", modification)); }
private static DataClassWriter WriteMethod(this DataClassWriter writer, string name, string modification) { return(writer.WriteMethod(name, new[] { modification })); }
private static DataClassWriter WriteMethod(this DataClassWriter writer, string name, string[] modifications) { return(writer.WriteMethod(name, new string[0], modifications)); }