-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from runceel/main
v7.5.0
- Loading branch information
Showing
24 changed files
with
1,121 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Source/ReactiveProperty.Core/Internals/ExpressionTreeUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace Reactive.Bindings.Internals | ||
{ | ||
internal static class ExpressionTreeUtils | ||
{ | ||
public static string GetPropertyPath<TType, TProperty>(Expression<Func<TType, TProperty>> propertySelector) | ||
{ | ||
if (!(propertySelector.Body is MemberExpression memberExpression)) | ||
{ | ||
if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); } | ||
memberExpression = unaryExpression.Operand as MemberExpression; | ||
if (memberExpression == null) { throw new ArgumentException(nameof(propertySelector)); } | ||
} | ||
|
||
var tokens = new LinkedList<string>(); | ||
while (memberExpression != null) | ||
{ | ||
tokens.AddFirst(memberExpression.Member.Name); | ||
memberExpression = memberExpression.Expression as MemberExpression; | ||
} | ||
|
||
return string.Join(".", tokens); | ||
} | ||
|
||
|
||
public static string GetPropertyName<TType, TProperty>(Expression<Func<TType, TProperty>> propertySelector) | ||
{ | ||
if (!(propertySelector.Body is MemberExpression memberExpression)) | ||
{ | ||
if (!(propertySelector.Body is UnaryExpression unaryExpression)) { throw new ArgumentException(nameof(propertySelector)); } | ||
memberExpression = unaryExpression.Operand as MemberExpression; | ||
if (memberExpression == null) { throw new ArgumentException(nameof(propertySelector)); } | ||
} | ||
|
||
return memberExpression.Member.Name; | ||
} | ||
|
||
public static bool IsNestedPropertyPath<TSubject, TProperty>(Expression<Func<TSubject, TProperty>> propertySelector) | ||
{ | ||
if (propertySelector.Body is MemberExpression member) | ||
{ | ||
return !(member.Expression is ParameterExpression); | ||
}; | ||
|
||
if (propertySelector.Body is UnaryExpression unary) | ||
{ | ||
if (unary.Operand is MemberExpression unaryMember) | ||
{ | ||
return !(unaryMember.Expression is ParameterExpression); | ||
} | ||
} | ||
|
||
throw new ArgumentException(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly:InternalsVisibleTo("ReactiveProperty, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a17d9f6e0d29671569d60841092ca470fd3105e6df77bbf6be713ace63c959e0d199dc7c16310a698bffb5133a6ffce1c87646f1f2b20e79b6c51a4dc4a44c8efcc5fbf0063353254d1cf9c094fbeb3133594b23c62c4ce67bcf1e445ef0b3770a6c885b79a3a2979c63e93e699f780c1d742fe70bacb6a0b2464498d37f83f7")] | ||
[assembly:InternalsVisibleTo("ReactiveProperty.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f56d09c52b0e027bc83bba3577eec7d30f15c7cd797d94f727d235ced2d26d95ab0e2a8d7e322b0c4eaf4f04838cbcaa25d8d7ec5c4a671160c9e112f5ed158c145a392ad205c3ef7c5f6bbea642930e65e41e00fd3d9404fe37a956217d65fe4824df826d3bb58fad44a185068242d346546743685e94f52801d3f5cbd707d6")] | ||
[assembly: InternalsVisibleTo("ReactiveProperty, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a17d9f6e0d29671569d60841092ca470fd3105e6df77bbf6be713ace63c959e0d199dc7c16310a698bffb5133a6ffce1c87646f1f2b20e79b6c51a4dc4a44c8efcc5fbf0063353254d1cf9c094fbeb3133594b23c62c4ce67bcf1e445ef0b3770a6c885b79a3a2979c63e93e699f780c1d742fe70bacb6a0b2464498d37f83f7")] | ||
[assembly: InternalsVisibleTo("ReactiveProperty.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f56d09c52b0e027bc83bba3577eec7d30f15c7cd797d94f727d235ced2d26d95ab0e2a8d7e322b0c4eaf4f04838cbcaa25d8d7ec5c4a671160c9e112f5ed158c145a392ad205c3ef7c5f6bbea642930e65e41e00fd3d9404fe37a956217d65fe4824df826d3bb58fad44a185068242d346546743685e94f52801d3f5cbd707d6")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.