Skip to content

Commit

Permalink
Merge pull request #49 from DynamicsValue/sonar-bug-fixes
Browse files Browse the repository at this point in the history
Replace UnionWith for an empty collection so it's compliant with Sonar
  • Loading branch information
jordimontana82 authored Oct 15, 2023
2 parents 06dd902 + 9d87042 commit 88294b4
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class OptionSetValueCollectionExtensions
/// <returns></returns>
public static HashSet<int> ConvertToHashSetOfInt(object input, bool isOptionSetValueCollectionAccepted)
{
var set = new HashSet<int>();
HashSet<int> set = null;

var faultReason = $"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter" +
$" http://schemas.microsoft.com/xrm/2011/Contracts/Services:query. The InnerException message was 'Error in line 1 position 8295. Element " +
Expand All @@ -31,39 +31,39 @@ public static HashSet<int> ConvertToHashSetOfInt(object input, bool isOptionSetV

if (input is int)
{
set.Add((int)input);
set = new HashSet<int>(new int[] {(int)input});
}
else if (input is string)
{
set.Add(int.Parse(input as string));
set = new HashSet<int>(new int[] { int.Parse(input as string) });
}
else if (input is int[])
{
set.UnionWith(input as int[]);
set = new HashSet<int>(input as int[]);
}
else if (input is string[])
{
set.UnionWith((input as string[]).Select(s => int.Parse(s)));
set = new HashSet<int>((input as string[]).Select(s => int.Parse(s)));
}
else if (input is DataCollection<object>)
{
var collection = input as DataCollection<object>;

if (collection.All(o => o is int))
{
set.UnionWith(collection.Cast<int>());
set = new HashSet<int>(collection.Cast<int>());
}
else if (collection.All(o => o is string))
{
set.UnionWith(collection.Select(o => int.Parse(o as string)));
set = new HashSet<int>(collection.Select(o => int.Parse(o as string)));
}
else if (collection.Count == 1 && collection[0] is int[])
{
set.UnionWith(collection[0] as int[]);
set = new HashSet<int>(collection[0] as int[]);
}
else if (collection.Count == 1 && collection[0] is string[])
{
set.UnionWith((collection[0] as string[]).Select(s => int.Parse(s)));
set = new HashSet<int>((collection[0] as string[]).Select(s => int.Parse(s)));
}
else
{
Expand All @@ -72,7 +72,7 @@ public static HashSet<int> ConvertToHashSetOfInt(object input, bool isOptionSetV
}
else if (isOptionSetValueCollectionAccepted && input is OptionSetValueCollection)
{
set.UnionWith((input as OptionSetValueCollection).Select(osv => osv.Value));
set = new HashSet<int>((input as OptionSetValueCollection).Select(osv => osv.Value));
}
else
{
Expand Down

0 comments on commit 88294b4

Please sign in to comment.