hello-polyglot.dib 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!meta
  2. {"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}}
  3. #!markdown
  4. # Polyglot Notebook
  5. #!csharp
  6. Console.WriteLine("Hello World")
  7. #!csharp
  8. #r "nuget: System.Net.Http, 4.3.4"
  9. using System.Net.Http;
  10. var httpClient = new HttpClient();
  11. var response = await httpClient.GetAsync("https://httpbin.org/get");
  12. var content = await response.Content.ReadAsStringAsync();
  13. Console.WriteLine(content);
  14. #!csharp
  15. public class Person {
  16. public string FirstName { get; set; }
  17. public string LastName { get; set; }
  18. public int Age { get; set; }
  19. override public string ToString() {
  20. return $"{FirstName} {LastName} is {Age} years old.";
  21. }
  22. }
  23. var person = new Person {
  24. FirstName = "john",
  25. LastName = "Doe",
  26. Age = 25
  27. };
  28. Console.WriteLine(person);
  29. person.Display();
  30. #!csharp
  31. #!import ../utils/EnumHelper.cs
  32. enum DayOfWeek {
  33. [Description("星期一")]
  34. Monday = 1,
  35. [Description("星期二")]
  36. Tuesday = 2,
  37. [Description("星期三")]
  38. Wednesday = 3,
  39. [Description("星期四")]
  40. Thursday = 4,
  41. [Description("星期五")]
  42. Friday = 5,
  43. [Description("星期六")]
  44. Saturday = 6,
  45. [Description("星期日")]
  46. Sunday = 7
  47. }
  48. var desc = EnumHelper.GetDescription(DayOfWeek.Monday);
  49. desc.Display();
  50. #!csharp
  51. var msg = "Hello Ployglot Notebook!";
  52. #!csharp
  53. #!set --name message --value @csharp:msg
  54. message.Display();
  55. #!csharp
  56. #!share --from csharp message --as newMessage
  57. newMessage.Display();
  58. #!csharp
  59. #!set --name url --value @input:"Please enter a URL"
  60. url.Display();
  61. #!csharp
  62. #!set --name age --value 19
  63. age.Display();
  64. #!csharp
  65. #!value --name products --mime-type application/json
  66. [
  67. {"id": 1, "name": "video game"},
  68. {"id": 2, "name": "book"}
  69. ]
  70. #!csharp
  71. #!share products --from value --as productsJson
  72. using System.Text.Json;
  73. class Product {
  74. public int Id { get; set; }
  75. public string Name { get; set; }
  76. }
  77. var jsonSerializerOptions = new JsonSerializerOptions {
  78. PropertyNameCaseInsensitive = true
  79. };
  80. var products = JsonSerializer.Deserialize<Product[]>(productsJson, jsonSerializerOptions);
  81. products.Display();
  82. #!csharp
  83. #!value --from-file ../data/json/test.json --name TestJsonData
  84. #!csharp
  85. #!share TestJsonData --from value --as jsonData
  86. using System.Text.Json;
  87. jsonData.Display();
  88. var jsonDoc = JsonDocument.Parse(jsonData);
  89. jsonDoc.Display();
  90. var jsonSerializerOptions = new JsonSerializerOptions {
  91. PropertyNameCaseInsensitive = true
  92. };
  93. var products = JsonSerializer.Deserialize<Product[]>(jsonDoc, jsonSerializerOptions);
  94. products.Display();
  95. #!csharp
  96. #!time
  97. var msg = "Hello Ployglot Notbool!";
  98. Console.Write(msg);
  99. #!http
  100. GET https://httpbin.org/get
  101. #!http
  102. POST https://httpbin.org/post