Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ private IDictionary<string, object> MigrateToTipTap(IDictionary<string, object>
extensions.Add("Umb.Tiptap.Block");
}

if (configuration.ContainsKey("toolbar"))
configuration.Remove("toolbar");
configuration.Remove("toolbar");

configuration["toolbar"] = new List<List<List<string>>> { new() { newToolbar } };

Expand All @@ -128,7 +127,7 @@ private IDictionary<string, object> MigrateToTipTap(IDictionary<string, object>
return configuration;
}

private bool TryGetToolbarArray(object? toolbar, out List<string> toolBarList)
private static bool TryGetToolbarArray(object? toolbar, out List<string> toolBarList)
{
toolBarList = new List<string>();
if (toolbar is null) return false;
Expand All @@ -146,7 +145,7 @@ private bool TryGetToolbarArray(object? toolbar, out List<string> toolBarList)
return true;
}

private string? MapToolbarItem(string item)
private static string? MapToolbarItem(string item)
{
return item switch
{
Expand Down
23 changes: 10 additions & 13 deletions uSync.Core/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ public static string GetUsername(this Dictionary<int, string> usernames, int? id
{
if (usernames == null || id == null) return "unknown";

usernames[id.Value] = usernames.ContainsKey(id.Value)
? usernames[id.Value]
: findMethod(id.Value)?.Email ?? "unknown";
if (usernames.TryGetValue(id.Value, out string? username))
return username;

return usernames[id.Value];
return usernames[id.Value] = findMethod(id.Value)?.Email ?? "unknown";
}

public static int GetEmails(this Dictionary<string, int> emails, string email, Func<string, IUser> findMethod)
{
if (emails == null || string.IsNullOrEmpty(email)) return -1;

emails[email] = emails.TryGetValue(email, out int value)
? value
: findMethod(email)?.Id ?? -1;
if (emails.TryGetValue(email, out int value))
return value;

return emails[email];
return emails[email] = findMethod(email)?.Id ?? -1;
}

// This method converts an object to a dictionary of string, object
Expand All @@ -40,7 +38,7 @@ public static int GetEmails(this Dictionary<string, int> emails, string email, F
var properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

// Create a dictionary and populate it with the property names and values
var dictionary = new Dictionary<string, object?>();
Dictionary<string, object?> dictionary = new(properties.Length);
foreach (var property in properties)
{
dictionary.Add(property.Name, property.GetValue(obj));
Expand All @@ -60,7 +58,7 @@ public static bool TryConvertToDictionary(this object obj, out IDictionary<strin
{
var properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

var dictionary = new Dictionary<string, object?>();
Dictionary<string, object?> dictionary = new(properties.Length);
foreach (var property in properties)
{
dictionary.Add(property.Name, property.GetValue(obj));
Expand All @@ -87,8 +85,7 @@ public static IDictionary<TKey, TValue> MergeIgnoreDuplicates<TKey, TValue>(this
{
foreach (var kvp in dictionary)
{
if (mergedDictionary.ContainsKey(kvp.Key) is true) continue;
mergedDictionary.Add(kvp.Key, kvp.Value);
mergedDictionary.TryAdd(kvp.Key, kvp.Value);
}
}

Expand All @@ -111,6 +108,6 @@ public static string ToCamelCase(this string s)
return s.ToLowerInvariant();
}

return char.ToLowerInvariant(s[0]) + s.Substring(1);
return $"{char.ToLowerInvariant(s[0])}{s.AsSpan(1)}";
}
}
4 changes: 2 additions & 2 deletions uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public override Task<IEnumerable<uSyncDependency>> GetDependenciesAsync(object v

private static Guid GetGuidValue(JsonObject obj, string key)
{
if (obj != null && obj.ContainsKey(key))
if (obj != null && obj.TryGetPropertyValue(key, out JsonNode? node))
{
if (obj[key]?.ToString().TryGetValueAs<Guid>(out var guid) is true)
if (node?.ToString().TryGetValueAs<Guid>(out var guid) is true)
return guid;
}

Expand Down
7 changes: 3 additions & 4 deletions uSync.Core/Roots/Configs/SyncConfigMergerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public JsonObject GetJsonPropertyDifferences(JsonObject sourceObject, JsonObject
// targetObject[property.Key] = JsonValue.Create(_inheritedValue);

// inherited is implicit.
if (targetObject.ContainsKey(property.Key))
targetObject.Remove(property.Key);
targetObject.Remove(property.Key);
}
}

Expand Down Expand Up @@ -206,9 +205,9 @@ public JsonObject GetJsonPropertyDifferences(JsonObject sourceObject, JsonObject
for (int i = 0; i < targetArray.Count; i++)
{
if (targetArray[i] is not JsonObject targetObject) continue;
if (targetObject.ContainsKey(removeProperty) is false) continue;
if (targetObject.TryGetPropertyValue(removeProperty, out JsonNode? removal) is false) continue;

if (targetObject[removeProperty]!.ToString().StartsWith(_removedLabel) is true)
if (removal!.ToString().StartsWith(_removedLabel) is true)
{
// we can't remove it while iterating, so add to a list.
removals.Add(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ public override string ItemAlias(TObject item)
public bool TabClashesWithExisting(TObject item, string alias, PropertyGroupType tabType)
{
EnsureAllTabsCacheLoaded(item);
return _allTabs?.ContainsKey(alias) is true && _allTabs?[alias] != tabType;
return _allTabs?.TryGetValue(alias, out PropertyGroupType aliasTab) is true && aliasTab != tabType;
}

public void EnsureAllTabsCacheLoaded(TObject item)
Expand Down
3 changes: 1 addition & 2 deletions uSync.Core/Serialization/Serializers/WebhookSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ private static List<uSyncChange> DeserializeHeaders(IWebhook item, XElement node
var headerValue = header.ValueOrDefault(string.Empty);

if (headerKey == string.Empty) continue;
if (newHeaders.ContainsKey(headerKey)) continue; // stop duplicates.
newHeaders.Add(headerKey, headerValue);
newHeaders.TryAdd(headerKey, headerValue); // stop duplicates.
}

var existingOrderedEvents = item.Headers.OrderBy(x => x.Key).ToDictionary();
Expand Down
Loading