Skip to content

Commit

Permalink
Allow internal properties in expressions
Browse files Browse the repository at this point in the history
Allows to use public and internal properties to be used in expressions used for bindings.
  • Loading branch information
CodeDevAM committed May 21, 2024
1 parent a0da097 commit 061d64b
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ public static TypedBinding<TIn, TOut> TwoWay<TOut>(Expression<Func<TIn, TOut>> e
$"Cannot create a two-way binding for '{expression}' because the expression does not target a property.",
nameof(expression));

if (property.GetGetMethod() is null)
MethodInfo? getMethodInfo = property.GetGetMethod(true);
if (getMethodInfo is null || getMethodInfo.IsPrivate)
throw new ArgumentException(
$"Cannot create a two-way binding for '{expression}' because the property has no getter.",
$"Cannot create a two-way binding for '{expression}' because the property has no getter or the getter is private.",
nameof(expression));

if (property.GetSetMethod() is null)
MethodInfo? setMethodInfo = property.GetSetMethod(true);
if (setMethodInfo is null || setMethodInfo.IsPrivate)
throw new ArgumentException(
$"Cannot create a two-way binding for '{expression}' because the property has no setter.",
$"Cannot create a two-way binding for '{expression}' because the property has no setter or the setter is private.",
nameof(expression));

// TODO: This is using reflection and mostly untested. Unit test it properly and
Expand Down

0 comments on commit 061d64b

Please sign in to comment.