1
1

Program.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Masuit.Tools;
  2. using Masuit.Tools.Models;
  3. using Masuit.Tools.Reflection;
  4. using Masuit.Tools.Security;
  5. using Microsoft.AspNetCore;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Linq;
  12. namespace NetCoreTest
  13. {
  14. public class Program
  15. {
  16. public static void Main(string[] args)
  17. {
  18. var myClass = new MyClass()
  19. {
  20. MyProperty1 = 1,
  21. Id = "mcc",
  22. Pid = "mc",
  23. Parent = new MyClass()
  24. {
  25. Id = "mc",
  26. Pid = "ccc",
  27. Parent = new MyClass()
  28. {
  29. Id = "ccc"
  30. }
  31. }
  32. };
  33. var allParent = myClass.AllParent().Append(myClass);
  34. var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);
  35. Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
  36. {
  37. ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
  38. Formatting = Formatting.Indented
  39. }));
  40. var path = myClass.Path(c => c.Id);
  41. Console.WriteLine(path);
  42. myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
  43. Console.ReadKey();
  44. var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);
  45. Console.WriteLine(rsaKey.PrivateKey);
  46. Console.WriteLine(rsaKey.PublicKey);
  47. var enc = "123456".RSAEncrypt();
  48. Console.WriteLine(enc);
  49. Console.Beep();
  50. var dec = enc.RSADecrypt();
  51. Console.WriteLine(dec);
  52. Console.ReadKey();
  53. //CreateWebHostBuilder(args).Build().Run();
  54. }
  55. public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  56. WebHost.CreateDefaultBuilder(args)
  57. .UseStartup<Startup>();
  58. }
  59. public class MyClass : ITree<MyClass>
  60. {
  61. [Description("test")]
  62. public string Pid { get; set; }
  63. public int? MyProperty1 { get; set; }
  64. /// <summary>
  65. /// 名字
  66. /// </summary>
  67. public string Id { get; set; }
  68. /// <summary>
  69. /// 父节点
  70. /// </summary>
  71. [JsonIgnore]
  72. public virtual MyClass Parent { get; set; }
  73. /// <summary>
  74. /// 子级
  75. /// </summary>
  76. [JsonIgnore]
  77. public ICollection<MyClass> Children { get; set; } = new List<MyClass>();
  78. /// <summary>
  79. /// 名字
  80. /// </summary>
  81. public string Name { get; set; }
  82. }
  83. }