Skip to content

Commit

Permalink
Fixes regressions in TryGetValueByPath introduced with 6.0 release (8…
Browse files Browse the repository at this point in the history
…ff4f2f)

-  Was throwing cast exception for most trivial case instead of returning false
- Did not return user provided default value in case the path couldn't be resolved
  • Loading branch information
azeno committed May 31, 2024
1 parent db31235 commit 753faa9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions VL.Core/src/IVLObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,13 @@ public static bool TryGetValueByPath<T>(this object instance, string path, T def
{
if (path == "")
{
value = (T)instance;
return value is T;
if (instance is T v)
{
value = v;
return true;
}
value = defaultValue;
return false;
}

if (instance is IVLObject vlObj)
Expand All @@ -778,7 +783,7 @@ public static bool TryGetValueByPath<T>(this object instance, string path, T def
return o.TryGetValueByPath(rest, defaultValue, out value);
}
}
value = default;
value = defaultValue;
return false;
}

Expand All @@ -794,7 +799,7 @@ public static bool TryGetValueByPath<T>(this object instance, string path, T def
return o.TryGetValueByPath(rest, defaultValue, out value);
}
}
value = default;
value = defaultValue;
return false;
}

Expand All @@ -811,7 +816,7 @@ public static bool TryGetValueByPath<T>(this object instance, string path, T def
return o.TryGetValueByPath(rest, defaultValue, out value);
}
}
value = default;
value = defaultValue;
return false;
}

Expand All @@ -829,7 +834,7 @@ public static bool TryGetValueByPath<T>(this object instance, string path, T def
return o.TryGetValueByPath(rest, defaultValue, out value);
}
}
value = default;
value = defaultValue;
return false;
}
}
Expand Down

0 comments on commit 753faa9

Please sign in to comment.