Skip to content

Commit

Permalink
true/false operator
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed May 30, 2023
1 parent 6a56fa1 commit 5ca5b97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions JLChnToZ.CommonUtils.Dynamic/TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ internal bool TryCast(object instance, Type type, bool isIn, out object result)
result = null;
return !(isIn ? this.type : type).IsValueType; // Only reference types can be null
}
var instanceType = isIn ? this.type : instance.GetType();
if (type.IsAssignableFrom(instanceType)) { // No need to cast if the type is already assignable
if (type.IsAssignableFrom(isIn ? this.type : instance.GetType())) { // No need to cast if the type is already assignable
result = instance;
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion JLChnToZ.CommonUtils.Dynamic/Utilites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static string ToOperatorMethodName(this ExpressionType expressionType) {
case ExpressionType.OnesComplement: return "op_OnesComplement";
case ExpressionType.Increment: return "op_Increment";
case ExpressionType.Decrement: return "op_Decrement";
default: throw new NotSupportedException();
case ExpressionType.IsTrue: return "op_True";
case ExpressionType.IsFalse: return "op_False";
default: return ""; // Fail silently
}
}
}
Expand Down

0 comments on commit 5ca5b97

Please sign in to comment.