bool _InnerTryUnaryOperation(ExpressionType operand, Type returnType, out object result) { switch(operand) { case ExpressionType.IsFalse: if(!returnType.IsAssignableFrom(typeof(bool))) { result = null; return false; } result = Type == JsonObjectType.False; return true; case ExpressionType.IsTrue: if(!returnType.IsAssignableFrom(typeof(bool))) { result = null; return false; } result = Type == JsonObjectType.True; return true; case ExpressionType.UnaryPlus: if (Type == JsonObjectType.FastNumber || Type == JsonObjectType.Number) { return this.InnerTryConvert(returnType, out result); } break; case ExpressionType.NegateChecked: case ExpressionType.Negate: if (Type == JsonObjectType.FastNumber) { var negated = new JsonObject { Type = JsonObjectType.FastNumber, FastNumberNegative = !this.FastNumberNegative, FastNumberPart1 = this.FastNumberPart1, FastNumberPart2 = this.FastNumberPart2, FastNumberPart2Length = this.FastNumberPart2Length, FastNumberPart3 = this.FastNumberPart3 }; return negated.InnerTryConvert(returnType, out result); } if (Type == JsonObjectType.Number) { var negated = new JsonObject { Type = JsonObjectType.Number, NumberValue = -this.NumberValue }; return negated.InnerTryConvert(returnType, out result); } break; case ExpressionType.Not: if (Type == JsonObjectType.True) { return JsonObject.False.InnerTryConvert(returnType, out result); } if (Type == JsonObjectType.False) { return JsonObject.True.InnerTryConvert(returnType, out result); } break; } result = null; return false; }
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { object ignored; return(Context.InnerTryConvert(destinationType, out ignored)); }