Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Objects.cs 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
  5. namespace Luticate2.Auth.Tests.Business.ObjectConverter
  6. {
  7. public static class StaticDbo
  8. {
  9. public static bool StaticField;
  10. public static bool StaticProperty { get; set; }
  11. }
  12. public class TestDbo1
  13. {
  14. public Guid Id { get; set; }
  15. public string Name { get; set; }
  16. public IList<TestDbo2> TestDbo2s { get; set; }
  17. public string ToString()
  18. {
  19. throw new NotImplementedException();
  20. }
  21. }
  22. public class TestDbo2
  23. {
  24. public Guid Id { get; set; }
  25. public string Name { get; set; }
  26. public string NameVirtual { get; set; }
  27. public TestDbo1 TestDbo1 { get; set; }
  28. public TestDbo2 Parent { get; set; }
  29. public TestDbo1 Unused { get; set; }
  30. }
  31. public class TestModel1
  32. {
  33. public Guid id { get; set; }
  34. public string name { get; set; }
  35. public ICollection<TestModel2> test_model2 { get; set; }
  36. }
  37. public class TestModel2
  38. {
  39. public Guid id { get; set; }
  40. public string name { get; set; }
  41. public Guid test_model1_id { get; set; }
  42. public TestModel1 test_model1 { get; set; }
  43. public TestModel2 parent { get; set; }
  44. }
  45. public class LuOcdTest1 : LuObjectConverterDescriptor<TestDbo1, TestModel1>
  46. {
  47. public LuOcdTest1()
  48. {
  49. AddMemberConverter(x => x.Id, y => y.id);
  50. AddMemberConverter(x => x.Name, y => y.name);
  51. AddMemberConverter(x => x.TestDbo2s, y => y.test_model2);
  52. AddStaticMethodConverter(
  53. (Expression<Func<TestDbo1, string>>)(x => x.ToString()),
  54. (Expression<Func<TestModel1, string>>)(x => x.id + ": " + x.name)
  55. );
  56. }
  57. }
  58. public class LuOcdTest2 : LuObjectConverterDescriptor<TestDbo2, TestModel2>
  59. {
  60. public LuOcdTest2()
  61. {
  62. AddMemberConverter(x => x.Id, y => y.id);
  63. AddMemberConverter(x => x.Name, y => y.name);
  64. AddMemberConverter(x => x.NameVirtual, y => y.name + " " + y.name);
  65. AddMemberConverter(x => x.TestDbo1, y => y.test_model1);
  66. AddMemberConverter(x => x.Parent, y => y.parent);
  67. AddMemberConverter((LambdaExpression) (Expression<Func<TestDbo2, TestDbo1>>) (x => x.Unused), (Expression<Func<TestModel2, TestModel1>>) (y => null));
  68. }
  69. }
  70. }