Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: change the settings dictionary to string,object #493 #498

Draft
wants to merge 1 commit into
base: v11/dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions uSync.BackOffice.Targets/appsettings-schema.usync.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@
"Settings": {
"type": "object",
"description": "Additional settings for the handler",
"additionalProperties": {
"type": "string"
}
"additionalProperties": {}
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions uSync.BackOffice/Configuration/uSyncHandlerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class HandlerSettings
/// <summary>
/// Additional settings for the handler
/// </summary>
public Dictionary<string, string> Settings { get; set; } = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
}

/// <summary>
Expand Down Expand Up @@ -89,7 +89,7 @@ public static TResult GetSetting<TResult>(this HandlerSettings settings, string
public static void AddSetting<TObject>(this HandlerSettings settings, string key, TObject value)
{
if (settings.Settings == null)
settings.Settings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
settings.Settings = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

settings.Settings[key] = value.ToString();
}
Expand All @@ -109,7 +109,7 @@ public static HandlerSettings Clone(this HandlerSettings settings)
UseFlatStructure = settings.UseFlatStructure,
Group = settings.Group,
GuidNames = settings.GuidNames,
Settings = new Dictionary<string, string>(settings.Settings, StringComparer.InvariantCultureIgnoreCase)
Settings = new Dictionary<string, object>(settings.Settings, StringComparer.InvariantCultureIgnoreCase)
};
}

Expand Down
4 changes: 1 addition & 3 deletions uSync.BackOffice/SyncHandlers/Handlers/DictionaryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ protected override IEnumerable<uSyncAction> ReportElement(XElement node, string
}

private bool IsOneWay(HandlerSettings config)
{
return (config.Settings.ContainsKey("OneWay") && config.Settings["OneWay"].InvariantEquals("true"));
}
=> config.GetSetting<bool>("OneWay", false);
}
}
14 changes: 7 additions & 7 deletions uSync.Core/Serialization/SyncSerializerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public SyncSerializerOptions(SerializerFlags flags)
this.Flags = flags;
}

public SyncSerializerOptions(Dictionary<string, string> settings)
public SyncSerializerOptions(Dictionary<string, object> settings)
{
this.Settings = settings != null ? new Dictionary<string, string>(settings) : new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
this.Settings = settings != null ? new Dictionary<string, object>(settings) : new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);

}

public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, string> settings)
public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, object> settings)
: this(settings)
{
this.Flags = flags;
Expand All @@ -46,7 +46,7 @@ public SyncSerializerOptions(SerializerFlags flags, Dictionary<string, string> s
/// <summary>
/// Parameterized options, custom for each handler
/// </summary>
public Dictionary<string, string> Settings { get; internal set; }
public Dictionary<string, object> Settings { get; internal set; }

/// <summary>
/// flag properties, we can move this away from flags if we want to.
Expand Down Expand Up @@ -102,7 +102,7 @@ public IList<string> GetSegments()

public string SwapValue(string key, string newValue)
{
string oldValue = null;
object oldValue = null;

if (!this.Settings.ContainsKey(key))
oldValue = this.Settings[key];
Expand All @@ -112,15 +112,15 @@ public string SwapValue(string key, string newValue)
else
this.Settings[key] = newValue;

return oldValue;
return oldValue.ToString();
}

/// <summary>
/// merge any new settings into the settings collection.
/// </summary>
public void MergeSettings(Dictionary<string, string> newSettings)
{
if (Settings == null) Settings = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
if (Settings == null) Settings = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
if (newSettings != null)
{
foreach (var kvp in newSettings)
Expand Down