|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Linq.Expressions; |
| 5 | +using System.Reflection; |
| 6 | +using System.Text; |
| 7 | +using NHibernate.Hql.Ast; |
| 8 | +using NHibernate.Linq.Visitors; |
| 9 | +using System.Collections.ObjectModel; |
| 10 | + |
| 11 | +namespace NHibernate.Linq.Functions |
| 12 | +{ |
| 13 | + public class ConvertToInt32Generator : BaseHqlGeneratorForMethod |
| 14 | + { |
| 15 | + public ConvertToInt32Generator() |
| 16 | + { |
| 17 | + SupportedMethods = new[] |
| 18 | + { |
| 19 | + ReflectionHelper.GetMethodDefinition<string>(s => int.Parse(s)), |
| 20 | + ReflectionHelper.GetMethodDefinition<bool>(o => Convert.ToInt32(o)), |
| 21 | + ReflectionHelper.GetMethodDefinition<byte>(o => Convert.ToInt32(o)), |
| 22 | + ReflectionHelper.GetMethodDefinition<char>(o => Convert.ToInt32(o)), |
| 23 | + ReflectionHelper.GetMethodDefinition<decimal>(o => Convert.ToInt32(o)), |
| 24 | + ReflectionHelper.GetMethodDefinition<double>(o => Convert.ToInt32(o)), |
| 25 | + ReflectionHelper.GetMethodDefinition<float>(o => Convert.ToInt32(o)), |
| 26 | + ReflectionHelper.GetMethodDefinition<int>(o => Convert.ToInt32(o)), |
| 27 | + ReflectionHelper.GetMethodDefinition<long>(o => Convert.ToInt32(o)), |
| 28 | + ReflectionHelper.GetMethodDefinition<object>(o => Convert.ToInt32(o)), |
| 29 | + ReflectionHelper.GetMethodDefinition<sbyte>(o => Convert.ToInt32(o)), |
| 30 | + ReflectionHelper.GetMethodDefinition<short>(o => Convert.ToInt32(o)), |
| 31 | + ReflectionHelper.GetMethodDefinition<string>(o => Convert.ToInt32(o)), |
| 32 | + ReflectionHelper.GetMethodDefinition<uint>(o => Convert.ToInt32(o)), |
| 33 | + ReflectionHelper.GetMethodDefinition<ulong>(o => Convert.ToInt32(o)), |
| 34 | + ReflectionHelper.GetMethodDefinition<ushort>(o => Convert.ToInt32(o)) |
| 35 | + }; |
| 36 | + } |
| 37 | + |
| 38 | + public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) |
| 39 | + { |
| 40 | + return treeBuilder.Cast(visitor.Visit(arguments[0]).AsExpression(), typeof (int)); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public class ConvertToDecimalGenerator : BaseHqlGeneratorForMethod |
| 45 | + { |
| 46 | + public ConvertToDecimalGenerator() |
| 47 | + { |
| 48 | + SupportedMethods = new[] |
| 49 | + { |
| 50 | + ReflectionHelper.GetMethodDefinition<string>(s => decimal.Parse(s)), |
| 51 | + ReflectionHelper.GetMethodDefinition<bool>(o => Convert.ToDecimal(o)), |
| 52 | + ReflectionHelper.GetMethodDefinition<byte>(o => Convert.ToDecimal(o)), |
| 53 | + ReflectionHelper.GetMethodDefinition<decimal>(o => Convert.ToDecimal(o)), |
| 54 | + ReflectionHelper.GetMethodDefinition<double>(o => Convert.ToDecimal(o)), |
| 55 | + ReflectionHelper.GetMethodDefinition<float>(o => Convert.ToDecimal(o)), |
| 56 | + ReflectionHelper.GetMethodDefinition<int>(o => Convert.ToDecimal(o)), |
| 57 | + ReflectionHelper.GetMethodDefinition<long>(o => Convert.ToDecimal(o)), |
| 58 | + ReflectionHelper.GetMethodDefinition<object>(o => Convert.ToDecimal(o)), |
| 59 | + ReflectionHelper.GetMethodDefinition<sbyte>(o => Convert.ToDecimal(o)), |
| 60 | + ReflectionHelper.GetMethodDefinition<short>(o => Convert.ToDecimal(o)), |
| 61 | + ReflectionHelper.GetMethodDefinition<string>(o => Convert.ToDecimal(o)), |
| 62 | + ReflectionHelper.GetMethodDefinition<uint>(o => Convert.ToDecimal(o)), |
| 63 | + ReflectionHelper.GetMethodDefinition<ulong>(o => Convert.ToDecimal(o)), |
| 64 | + ReflectionHelper.GetMethodDefinition<ushort>(o => Convert.ToDecimal(o)) |
| 65 | + }; |
| 66 | + } |
| 67 | + |
| 68 | + public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) |
| 69 | + { |
| 70 | + return treeBuilder.Cast(visitor.Visit(arguments[0]).AsExpression(), typeof(decimal)); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + public class ConvertToDoubleGenerator : BaseHqlGeneratorForMethod |
| 75 | + { |
| 76 | + public ConvertToDoubleGenerator() |
| 77 | + { |
| 78 | + SupportedMethods = new[] |
| 79 | + { |
| 80 | + ReflectionHelper.GetMethodDefinition<string>(s => double.Parse(s)), |
| 81 | + ReflectionHelper.GetMethodDefinition<bool>(o => Convert.ToDouble(o)), |
| 82 | + ReflectionHelper.GetMethodDefinition<byte>(o => Convert.ToDouble(o)), |
| 83 | + ReflectionHelper.GetMethodDefinition<decimal>(o => Convert.ToDouble(o)), |
| 84 | + ReflectionHelper.GetMethodDefinition<double>(o => Convert.ToDouble(o)), |
| 85 | + ReflectionHelper.GetMethodDefinition<float>(o => Convert.ToDouble(o)), |
| 86 | + ReflectionHelper.GetMethodDefinition<int>(o => Convert.ToDouble(o)), |
| 87 | + ReflectionHelper.GetMethodDefinition<long>(o => Convert.ToDouble(o)), |
| 88 | + ReflectionHelper.GetMethodDefinition<object>(o => Convert.ToDouble(o)), |
| 89 | + ReflectionHelper.GetMethodDefinition<sbyte>(o => Convert.ToDouble(o)), |
| 90 | + ReflectionHelper.GetMethodDefinition<short>(o => Convert.ToDouble(o)), |
| 91 | + ReflectionHelper.GetMethodDefinition<string>(o => Convert.ToDouble(o)), |
| 92 | + ReflectionHelper.GetMethodDefinition<uint>(o => Convert.ToDouble(o)), |
| 93 | + ReflectionHelper.GetMethodDefinition<ulong>(o => Convert.ToDouble(o)), |
| 94 | + ReflectionHelper.GetMethodDefinition<ushort>(o => Convert.ToDouble(o)) |
| 95 | + }; |
| 96 | + } |
| 97 | + |
| 98 | + public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) |
| 99 | + { |
| 100 | + return treeBuilder.Cast(visitor.Visit(arguments[0]).AsExpression(), typeof(double)); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments