BaseRowMapper.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) Tribal Media AB, http://tribalmedia.se/
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * The name of Tribal Media AB may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  18. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. */
  26. using TribalMedia.Framework.Data;
  27. namespace TribalMedia.Framework.Data
  28. {
  29. public abstract class BaseRowMapper
  30. {
  31. public abstract void FillObject(BaseDataReader reader);
  32. }
  33. public class BaseRowMapper<TObj> : BaseRowMapper
  34. {
  35. private readonly BaseSchema m_schema;
  36. private readonly TObj m_obj;
  37. public TObj Object
  38. {
  39. get { return m_obj; }
  40. }
  41. public BaseRowMapper(BaseSchema schema, TObj obj)
  42. {
  43. m_schema = schema;
  44. m_obj = obj;
  45. }
  46. public override void FillObject(BaseDataReader reader)
  47. {
  48. foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values)
  49. {
  50. fieldMapper.SetPropertyFromReader(this, reader);
  51. }
  52. }
  53. }
  54. }