Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public class UpperString : IUserType
  2. {
  3. public UpperString()
  4. {
  5. }
  6.  
  7. #region IUserType Members
  8.  
  9. public new bool Equals(object x, object y)
  10. {
  11. bool returnvalue = false;
  12. if ((x != null) && (y != null))
  13. {
  14. returnvalue = x.Equals(y);
  15. }
  16. return returnvalue;
  17. }
  18.  
  19. public NHibernate.SqlTypes.SqlType[] SqlTypes
  20. {
  21. get
  22. {
  23. NHibernate.SqlTypes.SqlType[] types = { NHibernate.SqlTypes.SqlTypeFactory.GetString(255) };
  24. return types;
  25. }
  26. }
  27.  
  28. public Type ReturnedType
  29. {
  30. get
  31. {
  32. return typeof(String);
  33. }
  34. }
  35.  
  36. /// <summary>
  37. /// Takes care of null values.
  38. /// </summary>
  39. public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
  40. {
  41. object value = rs.GetValue(rs.GetOrdinal(names[0]));
  42. if (value == DBNull.Value)
  43. {
  44. return String.Empty;
  45. }
  46. return value;
  47. }
  48.  
  49. /// <summary>
  50. /// Faz o UpperCase na sua string sempre que for setar o valor
  51. /// </summary>
  52. public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
  53. {
  54. if (Convert.ToString(value) == String.Empty)
  55. {
  56. ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
  57. }
  58. else
  59. {
  60. //faz o upper
  61. ((IDataParameter)cmd.Parameters[index]).Value = ((string)value).ToUpper();
  62. }
  63. }
  64.  
  65. public object DeepCopy(object value)
  66. {
  67. return value;
  68. }
  69.  
  70. public bool IsMutable
  71. {
  72. get { return true; }
  73. }
  74.  
  75. public object Assemble(object cached, object owner)
  76. { return DeepCopy(cached); }
  77.  
  78. public object Disassemble(object value)
  79. { return value; }
  80.  
  81. public int GetHashCode(object x)
  82. { return x.GetHashCode(); }
  83.  
  84. public object Replace(object original, object target, object owner)
  85. { return original; }
  86.  
  87. #endregion
  88. }
  89.  
  90. <property length="24" name="PropriedadeUpper" column="ColunaUpper">
  91. <type name="MeuAssembly.NHUserTypes.UpperString, MeuAssembly">
  92. </type>
  93. </property>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement