DbParameterExpression.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Ant.Common;
  2. using Ant.Utility;
  3. using System;
  4. namespace Ant.DbExpressions
  5. {
  6. [System.Diagnostics.DebuggerDisplay("Value = {Value}")]
  7. public class DbParameterExpression : DbExpression
  8. {
  9. object _value;
  10. Type _type;
  11. public DbParameterExpression(object value)
  12. : base(DbExpressionType.Parameter)
  13. {
  14. this._value = value;
  15. if (value != null)
  16. this._type = value.GetType();
  17. else
  18. this._type = UtilConstants.TypeOfObject;
  19. }
  20. public DbParameterExpression(object value, Type type)
  21. : base(DbExpressionType.Parameter)
  22. {
  23. AntUtils.CheckNull(type);
  24. if (value != null)
  25. {
  26. Type t = value.GetType();
  27. if (!type.IsAssignableFrom(t))
  28. throw new ArgumentException();
  29. }
  30. this._value = value;
  31. this._type = type;
  32. }
  33. public override Type Type { get { return this._type; } }
  34. public object Value { get { return this._value; } }
  35. public override T Accept<T>(DbExpressionVisitor<T> visitor)
  36. {
  37. return visitor.Visit(this);
  38. }
  39. }
  40. }