implement (untested) deep-copy Clone on SettingsProvider and friends
This commit is contained in:
parent
5356098217
commit
eeda385dcf
@ -23,7 +23,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace MBS.Framework
|
namespace MBS.Framework
|
||||||
{
|
{
|
||||||
public abstract class Setting
|
public abstract class Setting : ICloneable
|
||||||
{
|
{
|
||||||
public Setting(string name, string title, object defaultValue = null, bool enabled = true, bool visible = true)
|
public Setting(string name, string title, object defaultValue = null, bool enabled = true, bool visible = true)
|
||||||
{
|
{
|
||||||
@ -168,10 +168,13 @@ namespace MBS.Framework
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValue<T>(T value)
|
public void SetValue<T>(T value)
|
||||||
{
|
{
|
||||||
mvarValue = value;
|
mvarValue = value;
|
||||||
_valueSet = true;
|
_valueSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract object Clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,5 +36,18 @@ namespace MBS.Framework.Settings
|
|||||||
}
|
}
|
||||||
base.SetValue(val);
|
base.SetValue(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
BooleanSetting clone = new BooleanSetting(Name, Title, (bool)DefaultValue, Enabled, Visible);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,5 +82,20 @@ namespace MBS.Framework.Settings
|
|||||||
|
|
||||||
public bool RequireSelectionFromList { get; set; } = true;
|
public bool RequireSelectionFromList { get; set; } = true;
|
||||||
public bool MultipleSelect { get; set; } = false;
|
public bool MultipleSelect { get; set; } = false;
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
ChoiceSetting clone = new ChoiceSetting(Name, Title, DefaultValue);
|
||||||
|
clone.SelectedValue = SelectedValue;
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.RequireSelectionFromList = RequireSelectionFromList;
|
||||||
|
clone.MultipleSelect = MultipleSelect;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.Description = Description;
|
||||||
|
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,13 +28,32 @@ namespace MBS.Framework.Settings
|
|||||||
|
|
||||||
public string SingularItemTitle { get; set; } = null;
|
public string SingularItemTitle { get; set; } = null;
|
||||||
|
|
||||||
public CollectionSetting(string name, string title, SettingsGroup group, string singularItemTitle = null) : base(name, title, null)
|
public CollectionSetting(string name, string title, SettingsGroup group = null, string singularItemTitle = null) : base(name, title, null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < group.Settings.Count; i++)
|
if (group != null)
|
||||||
{
|
{
|
||||||
Settings.Add(group.Settings[i]);
|
for (int i = 0; i < group.Settings.Count; i++)
|
||||||
|
{
|
||||||
|
Settings.Add(group.Settings[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SingularItemTitle = singularItemTitle;
|
SingularItemTitle = singularItemTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
CollectionSetting clone = new CollectionSetting(Name, Title);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
foreach (Setting setting in Settings)
|
||||||
|
{
|
||||||
|
clone.Settings.Add(setting.Clone() as Setting);
|
||||||
|
}
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,5 +30,17 @@ namespace MBS.Framework.Settings
|
|||||||
{
|
{
|
||||||
CommandID = commandID;
|
CommandID = commandID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
CommandSetting clone = new CommandSetting(Name, Title, CommandID) { StylePreset = StylePreset };
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,5 +33,18 @@ namespace MBS.Framework.Settings
|
|||||||
{
|
{
|
||||||
base.SetValue(value);
|
base.SetValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
CustomSetting clone = new CustomSetting(Name, Title, ControlTypeName);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,5 +51,18 @@ namespace MBS.Framework.Settings
|
|||||||
RequireExistingFile = requireExistingFile;
|
RequireExistingFile = requireExistingFile;
|
||||||
FileNameFilter = fileNameFilter;
|
FileNameFilter = fileNameFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
FileSetting clone = new FileSetting(Name, Title, (string)DefaultValue, RequireExistingFile, FileNameFilter);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,5 +69,26 @@ namespace MBS.Framework.Settings
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
GroupSetting clone = new GroupSetting(Name, Title);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
foreach (Setting setting in HeaderSettings)
|
||||||
|
{
|
||||||
|
clone.HeaderSettings.Add(setting.Clone() as Setting);
|
||||||
|
}
|
||||||
|
foreach (Setting setting in Options)
|
||||||
|
{
|
||||||
|
clone.Options.Add(setting.Clone() as Setting);
|
||||||
|
}
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,8 +29,22 @@ namespace MBS.Framework.Settings
|
|||||||
|
|
||||||
public RangeSetting(string name, string title, decimal defaultValue = 0.0M, decimal? minimumValue = null, decimal? maximumValue = null) : base(name, title, defaultValue)
|
public RangeSetting(string name, string title, decimal defaultValue = 0.0M, decimal? minimumValue = null, decimal? maximumValue = null) : base(name, title, defaultValue)
|
||||||
{
|
{
|
||||||
|
DefaultValue = defaultValue;
|
||||||
MinimumValue = minimumValue;
|
MinimumValue = minimumValue;
|
||||||
MaximumValue = maximumValue;
|
MaximumValue = maximumValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
RangeSetting clone = new RangeSetting(Name, Title, (decimal)DefaultValue, MinimumValue, MaximumValue);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,5 +29,18 @@ namespace MBS.Framework.Settings
|
|||||||
{
|
{
|
||||||
MaximumLength = maxLength;
|
MaximumLength = maxLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
TextSetting clone = new TextSetting(Name, Title, (string)DefaultValue, MaximumLength);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,5 +29,18 @@ namespace MBS.Framework.Settings
|
|||||||
{
|
{
|
||||||
ComponentCount = componentCount;
|
ComponentCount = componentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override object Clone()
|
||||||
|
{
|
||||||
|
VersionSetting clone = new VersionSetting(Name, Title, (Version)DefaultValue, ComponentCount);
|
||||||
|
clone.Required = Required;
|
||||||
|
clone.Prefix = Prefix;
|
||||||
|
clone.Description = Description;
|
||||||
|
clone.Enabled = Enabled;
|
||||||
|
clone.Visible = Visible;
|
||||||
|
clone.Suffix = Suffix;
|
||||||
|
clone.SetValue(GetValue());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ using MBS.Framework.Settings;
|
|||||||
|
|
||||||
namespace MBS.Framework
|
namespace MBS.Framework
|
||||||
{
|
{
|
||||||
public class SettingsGroup : IComparable<SettingsGroup>
|
public class SettingsGroup : IComparable<SettingsGroup>, ICloneable
|
||||||
{
|
{
|
||||||
public class SettingsGroupCollection
|
public class SettingsGroupCollection
|
||||||
: System.Collections.ObjectModel.Collection<SettingsGroup>
|
: System.Collections.ObjectModel.Collection<SettingsGroup>
|
||||||
@ -166,5 +166,18 @@ namespace MBS.Framework
|
|||||||
{
|
{
|
||||||
return String.Join (":", Path);
|
return String.Join (":", Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
SettingsGroup clone = new SettingsGroup();
|
||||||
|
clone.ID = ID;
|
||||||
|
clone.Path = Path?.Clone() as string[];
|
||||||
|
clone.Priority = Priority;
|
||||||
|
foreach (Setting setting in Settings)
|
||||||
|
{
|
||||||
|
clone.Settings.Add(setting.Clone() as Setting);
|
||||||
|
}
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,5 +111,13 @@ namespace MBS.Framework
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CopyTo(SettingsProvider other)
|
||||||
|
{
|
||||||
|
foreach (SettingsGroup group in SettingsGroups)
|
||||||
|
{
|
||||||
|
other.SettingsGroups.Add(group.Clone() as SettingsGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user