Skip to content
Open
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
57 changes: 48 additions & 9 deletions v4/DynamicsCrm.DevKit.Shared/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,51 @@ public static string DecryptString(string cipherText)

public static bool IsTheSame(string value1, string value2)
{
if (value1 == null && value2 == null) return true;
if (value1 != null && value2 == null) return false;
if (value1 == null && value2 != null) return false;
value1 = value1.Replace("\r\n", string.Empty).Replace("\r", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim();
value2 = value2.Replace("\r\n", string.Empty).Replace("\r", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim();
return string.Equals(value1, value2, StringComparison.OrdinalIgnoreCase);
if (ReferenceEquals(value1, value2)) return true;
if (value1 == null || value2 == null) return false;
if (value1.Length == 0 && value2.Length == 0) return true;
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant. If both strings are empty and equal, they will typically share the same reference (both pointing to string.Empty) and will be caught by the ReferenceEquals check on line 77. If they don't share a reference but both have length 0, the main loop logic will correctly return true when both indices reach the end. Consider removing this check to simplify the code.

Suggested change
if (value1.Length == 0 && value2.Length == 0) return true;

Copilot uses AI. Check for mistakes.

int i1 = 0, i2 = 0;
int len1 = value1.Length, len2 = value2.Length;

while (i1 < len1 || i2 < len2)
{
// Skip whitespace in value1
while (i1 < len1 && (value1[i1] == '\r' || value1[i1] == '\n' || value1[i1] == '\t' || value1[i1] == ' '))
{
i1++;
}

// Skip whitespace in value2
while (i2 < len2 && (value2[i2] == '\r' || value2[i2] == '\n' || value2[i2] == '\t' || value2[i2] == ' '))
{
i2++;
}

// If one string is finished, the other must also be finished (or only contain whitespace)
if (i1 >= len1)
{
return i2 >= len2;
}
if (i2 >= len2)
{
return i1 >= len1;
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition can be simplified to just 'return false;' since we know that i1 < len1 at this point (otherwise the previous check at line 99 would have been taken). The current code returns 'i1 >= len1' which will always evaluate to false here. While the logic is functionally correct, using 'return false;' would make the intent clearer.

Suggested change
return i1 >= len1;
return false;

Copilot uses AI. Check for mistakes.
}

// Compare characters (case-insensitive)
char c1 = char.ToUpperInvariant(value1[i1]);
char c2 = char.ToUpperInvariant(value2[i2]);

if (c1 != c2)
{
return false;
}

i1++;
i2++;
}

return true;
}

public static async Task<string> ReadEmbeddedResourceAsync(string path)
Expand All @@ -104,13 +143,13 @@ public static string GetSchemaNameFromFile(string file, string endsWith)

private static string GetIdentifier(string name)
{
var value = string.Empty;
var sb = new StringBuilder(name.Length);
for (int i = 0; i < name.Length; ++i)
{
if (char.IsLetterOrDigit(name[i]) || name[i] == ' ' || name[i] == '-' || name[i] == '_')
value += name[i];
sb.Append(name[i]);
}
return value;
return sb.ToString();
}

public static string SafeIdentifier(string name)
Expand Down
Loading