Skip to content

Commit

Permalink
Add missing unary+ operator
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed May 30, 2023
1 parent 40b2a2d commit 050b0ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions JLChnToZ.CommonUtils.Dynamic.Test/LimitlessTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void TestOperators() {
_ = limitless >> 1; Assert.AreSame(TestSubject.lastCalledMethod, "operator>>", $"Call operator on 2 wrapped objects >> (Actual = {TestSubject.lastCalledMethod})");
_ = limitless++; Assert.AreSame(TestSubject.lastCalledMethod, "operator++", $"Call operator on 1 wrapped object ++ (Actual = {TestSubject.lastCalledMethod})");
_ = limitless--; Assert.AreSame(TestSubject.lastCalledMethod, "operator--", $"Call operator on 1 wrapped object -- (Actual = {TestSubject.lastCalledMethod})");
_ = +limitless; Assert.AreSame(TestSubject.lastCalledMethod, "operator+", $"Call operator on 1 wrapped object + (Actual = {TestSubject.lastCalledMethod})");
_ = -limitless; Assert.AreSame(TestSubject.lastCalledMethod, "operator-", $"Call operator on 1 wrapped object - (Actual = {TestSubject.lastCalledMethod})");
_ = limitless += limitless2; Assert.AreSame(TestSubject.lastCalledMethod, "operator+", $"Call operator on 2 wrapped objects += (Actual = {TestSubject.lastCalledMethod})");
_ = limitless -= limitless2; Assert.AreSame(TestSubject.lastCalledMethod, "operator-", $"Call operator on 2 wrapped objects -= (Actual = {TestSubject.lastCalledMethod})");
_ = limitless *= limitless2; Assert.AreSame(TestSubject.lastCalledMethod, "operator*", $"Call operator on 2 wrapped objects *= (Actual = {TestSubject.lastCalledMethod})");
Expand Down
12 changes: 6 additions & 6 deletions JLChnToZ.CommonUtils.Dynamic/TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ internal bool TryGetValue(object instance, string key, out object value) {
}

internal bool TryGetValue(object instance, object[] indexes, out object value) {
PropertyInfo matched;
if (indexes == null || indexers.Length == 0) {
value = null;
return false;
}
matched = Type.DefaultBinder.SelectProperty(
var binder = Type.DefaultBinder;
var matched = binder.SelectProperty(
DEFAULT_FLAGS | BindingFlags.GetProperty, indexers, null, Array.ConvertAll(indexes, GetUndelyType), null
);
if (matched != null) {
value = InternalWrap(matched.GetValue(instance, InternalUnwrap(
indexes, Type.DefaultBinder,
indexes, binder,
Array.ConvertAll(matched.GetIndexParameters(), GetParameterType)
)));
return true;
Expand All @@ -117,14 +117,14 @@ internal bool TrySetValue(object instance, string key, object value) {
}

internal bool TrySetValue(object instance, object[] indexes, object value) {
PropertyInfo matched;
if (indexes == null || indexers.Length == 0) return false;
matched = Type.DefaultBinder.SelectProperty(
var binder = Type.DefaultBinder;
var matched = binder.SelectProperty(
DEFAULT_FLAGS | BindingFlags.SetProperty, indexers, null, Array.ConvertAll(indexes, GetUndelyType), null
);
if (matched != null) {
matched.SetValue(InternalUnwrap(instance), value, InternalUnwrap(
indexes, Type.DefaultBinder,
indexes, binder,
Array.ConvertAll(matched.GetIndexParameters(), GetParameterType)
));
return true;
Expand Down
4 changes: 2 additions & 2 deletions JLChnToZ.CommonUtils.Dynamic/Utilites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public static void InternalWrap(object[] sourceObj, object[] destObj) {
}

public static bool TryGetMatchingMethod<T>(T[] methodInfos, ref object[] args, out T bestMatches) where T : MethodBase {
MethodBase matched;
if (args == null) args = emptyArgs;
var binder = Type.DefaultBinder;
matched = binder.SelectMethod(DEFAULT_FLAGS, methodInfos, Array.ConvertAll(args, GetUndelyType), null);
var matched = binder.SelectMethod(DEFAULT_FLAGS, methodInfos, Array.ConvertAll(args, GetUndelyType), null);
if (matched != null) {
bestMatches = (T)matched;
args = InternalUnwrap(args, binder, Array.ConvertAll(matched.GetParameters(), GetParameterType));
Expand Down Expand Up @@ -78,6 +77,7 @@ public static string ToOperatorMethodName(this ExpressionType expressionType) {
case ExpressionType.ExclusiveOr: case ExpressionType.ExclusiveOrAssign: return "op_ExclusiveOr";
case ExpressionType.LeftShift: case ExpressionType.LeftShiftAssign: return "op_LeftShift";
case ExpressionType.RightShift: case ExpressionType.RightShiftAssign: return "op_RightShift";
case ExpressionType.UnaryPlus: return "op_UnaryPlus";
case ExpressionType.Negate: return "op_UnaryNegation";
case ExpressionType.Not: return "op_LogicalNot";
case ExpressionType.OnesComplement: return "op_OnesComplement";
Expand Down

0 comments on commit 050b0ce

Please sign in to comment.