From 8013520a8c9baff8a34d957788ce0707cfc3b86a Mon Sep 17 00:00:00 2001 From: Bipin Radhakrishnan Date: Sat, 30 May 2026 23:29:15 -0400 Subject: [PATCH] ran the sample file --- sample/dictionary-extensions.ipynb | 1877 +++++++++++++++++++++++++++- sample/enumerable-extension.ipynb | 176 ++- sample/string-extensions.ipynb | 180 ++- sample/value-extensions.ipynb | 1664 +++++++++++++++++++++++- 4 files changed, 3742 insertions(+), 155 deletions(-) diff --git a/sample/dictionary-extensions.ipynb b/sample/dictionary-extensions.ipynb index cf4640e..c13a4bb 100644 --- a/sample/dictionary-extensions.ipynb +++ b/sample/dictionary-extensions.ipynb @@ -33,10 +33,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, "outputs": [], @@ -62,13 +65,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
95
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
82
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetValueOrDefault — returns value when key exists\n", "var scores = new Dictionary\n", @@ -83,13 +170,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
0
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
<null>
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetValueOrDefault — returns default(TValue) when key is not found\n", "display(DictionaryExtensions.GetValueOrDefault(scores, \"charlie\")); // 0 (default for int)\n", @@ -100,13 +271,106 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
0
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
0
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "(2,25): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.\n", + "\n" + ] + } + ], "source": [ "// GetValueOrDefault — null-safe: returns default when dict is null\n", "IDictionary? nullDict = null;\n", @@ -130,13 +394,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Alice" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetOrAdd — returns existing value; factory is NOT called when key already exists\n", "var cache = new Dictionary { [\"user:1\"] = \"Alice\" };\n", @@ -154,13 +471,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "fetched-user:2" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "fetched-user:2" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetOrAdd — key missing: factory is called, result stored and returned\n", "var result2 = cache.GetOrAdd(\"user:2\", key => $\"fetched-{key}\");\n", @@ -171,13 +510,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
[ 2, 4, 6 ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
[ 1, 3 ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetOrAdd — practical use: lazy-initialise nested collections\n", "var grouped = new Dictionary>();\n", @@ -195,13 +618,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "null key: key" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "null factory: factory" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// GetOrAdd — throws ArgumentNullException for null key or null factory\n", "var d = new Dictionary();\n", @@ -229,13 +674,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
keyvalue
timeout
30
retries
3
pageSize
50
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Merge — no overlapping keys: all entries from other are added\n", "var defaults = new Dictionary { [\"timeout\"] = 30, [\"retries\"] = 3 };\n", @@ -247,13 +736,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "light" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "14" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Merge — overwrite: false (default) skips duplicate keys; existing values are kept\n", "var config = new Dictionary { [\"theme\"] = \"light\", [\"lang\"] = \"en\" };\n", @@ -266,13 +777,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "dark" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "14" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Merge — overwrite: true replaces existing values with values from other\n", "var base1 = new Dictionary { [\"theme\"] = \"light\", [\"lang\"] = \"en\" };\n", @@ -285,13 +818,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
1
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Merge — null other is silently ignored; returns same dict instance for chaining\n", "var dict1 = new Dictionary { [\"a\"] = 1 };\n", @@ -317,13 +934,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
keyvalue
apple
10
banana
5
cherry
20
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AddRange — adds all pairs from a list; returns same dict for chaining\n", "var inventory = new Dictionary { [\"apple\"] = 10 };\n", @@ -339,13 +1000,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
10
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
15
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AddRange — overwrite: false (default) keeps existing values for duplicate keys\n", "var inv2 = new Dictionary { [\"apple\"] = 10, [\"banana\"] = 5 };\n", @@ -358,13 +1103,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
99
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
15
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AddRange — overwrite: true replaces existing values\n", "var inv3 = new Dictionary { [\"apple\"] = 10, [\"banana\"] = 5 };\n", @@ -377,13 +1206,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
keyvalue
USD
1
GBP
1.1
EUR
1.2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AddRange — works with any IEnumerable; here from a LINQ projection\n", "var codes = new[] { \"USD\", \"GBP\", \"EUR\" };\n", @@ -395,13 +1268,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
1
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AddRange — null pairs are silently ignored\n", "var inv4 = new Dictionary { [\"a\"] = 1 };\n", @@ -425,13 +1342,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
keyvalue
db.host
localhost
db.port
5432
app.name
MyApp
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// RemoveWhere — removes all keys matching the predicate\n", "var settings = new Dictionary\n", @@ -449,13 +1410,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// RemoveWhere — no matching keys: dict is unchanged\n", "var nums = new Dictionary { [\"a\"] = 1, [\"b\"] = 2 };\n", @@ -465,13 +1470,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
keyvalue
DEBUG
true
HOST
prod.example.com
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// RemoveWhere — returns same dict instance for chaining\n", "var env = new Dictionary\n", @@ -490,13 +1579,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "null predicate: predicate" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// RemoveWhere — throws ArgumentNullException for null predicate\n", "var d2 = new Dictionary { [\"a\"] = 1 };\n", @@ -525,13 +1627,137 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
1.20
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AsReadOnly — wraps the dict as IReadOnlyDictionary; reads work normally\n", "var prices = new Dictionary\n", @@ -548,13 +1774,137 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
1
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
99
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AsReadOnly — live view: mutations to the underlying dict are visible through the wrapper\n", "var source = new Dictionary { [\"a\"] = 1 };\n", @@ -569,13 +1919,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "null dict: dict" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// AsReadOnly — throws ArgumentNullException for null dict\n", "try { DictionaryExtensions.AsReadOnly(null!); }\n", @@ -602,13 +1965,84 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "warn" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "20" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "json" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "var appDefaults = new Dictionary\n", "{\n", @@ -648,13 +2082,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
keyvalue
v2/orders
OrderHandlerV2
v2/products
ProductHandlerV2
health
HealthHandler
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Start with some registered handlers\n", "var handlers = new Dictionary { [\"v1/orders\"] = \"OrderHandlerV1\" };\n", @@ -687,13 +2165,137 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
[ order-1001, order-1002 ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
[ pay-501, pay-502 ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
[ ship-201 ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Accumulate events into per-type buckets\n", "var buckets = new Dictionary>();\n", @@ -728,13 +2330,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "9090" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "prod.example.com" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "false" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Highest-priority source first; each subsequent merge skips already-set keys\n", "var commandLine = new Dictionary { [\"port\"] = \"9090\" };\n", @@ -761,13 +2394,137 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "dotnet_interactive": { "language": "csharp" + }, + "vscode": { + "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
55
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
6765
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
19
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Cheap probe with GetValueOrDefault before the more expensive GetOrAdd\n", "var memo = new Dictionary();\n", @@ -793,7 +2550,11 @@ "name": ".net-csharp" }, "language_info": { - "name": "polyglot-notebook" + "file_extension": ".cs", + "mimetype": "text/x-csharp", + "name": "C#", + "pygments_lexer": "csharp", + "version": "13.0" }, "polyglot_notebook": { "kernelInfo": { diff --git a/sample/enumerable-extension.ipynb b/sample/enumerable-extension.ipynb index bb8e83b..fbc3370 100644 --- a/sample/enumerable-extension.ipynb +++ b/sample/enumerable-extension.ipynb @@ -40,14 +40,130 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 1, "id": "2a22ea16", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\r\n", + "
\r\n", + " \r\n", + " \r\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#r \"../src/CSharpHelperExtensions/bin/Debug/net10.0/CSharpHelperExtensions.dll\"\n", "using System.Collections.Generic;\n", @@ -73,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 2, "id": "dc1aecc2", "metadata": { "vscode": { @@ -211,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 3, "id": "e4d5ada6", "metadata": { "vscode": { @@ -349,7 +465,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 4, "id": "255332dc", "metadata": { "vscode": { @@ -502,7 +618,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 5, "id": "aac4c3a5", "metadata": { "vscode": { @@ -612,7 +728,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 6, "id": "ced3e752", "metadata": { "vscode": { @@ -753,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 7, "id": "7ba7ca89", "metadata": { "vscode": { @@ -908,7 +1024,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 8, "id": "a5133163", "metadata": { "vscode": { @@ -1049,7 +1165,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 9, "id": "1adf5527", "metadata": { "vscode": { @@ -1102,7 +1218,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 10, "id": "fc43af2c", "metadata": { "vscode": { @@ -1202,7 +1318,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 11, "id": "5679cade", "metadata": { "vscode": { @@ -1406,7 +1522,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 12, "id": "b9371ca6", "metadata": { "vscode": { @@ -1513,7 +1629,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 13, "id": "8fcab453", "metadata": { "vscode": { @@ -1630,7 +1746,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 14, "id": "6da80bb9", "metadata": { "vscode": { @@ -1727,7 +1843,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 15, "id": "658b80b3", "metadata": { "vscode": { @@ -1865,7 +1981,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 16, "id": "a2e745fe", "metadata": { "vscode": { @@ -1943,7 +2059,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 17, "id": "a954abfc", "metadata": { "vscode": { @@ -2081,7 +2197,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 18, "id": "644e29d5", "metadata": { "vscode": { @@ -2260,7 +2376,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 19, "id": "cd0af8d8", "metadata": { "vscode": { @@ -2439,7 +2555,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 20, "id": "ead2788c", "metadata": { "vscode": { @@ -2634,7 +2750,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 21, "id": "9ba17fa3", "metadata": { "vscode": { @@ -2733,7 +2849,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 22, "id": "95cc5bff", "metadata": { "vscode": { @@ -2917,7 +3033,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 23, "id": "d554fff6", "metadata": { "vscode": { @@ -3139,7 +3255,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 24, "id": "dbb983f6", "metadata": { "vscode": { @@ -3254,7 +3370,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 25, "id": "d038da52", "metadata": { "vscode": { @@ -3392,7 +3508,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 26, "id": "ede991cb", "metadata": { "vscode": { @@ -3530,7 +3646,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 27, "id": "09895039", "metadata": { "vscode": { @@ -3647,7 +3763,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 28, "id": "94da3458", "metadata": { "vscode": { @@ -3710,7 +3826,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 29, "id": "2e3539f8", "metadata": { "vscode": { diff --git a/sample/string-extensions.ipynb b/sample/string-extensions.ipynb index ea0e0c4..1545f88 100644 --- a/sample/string-extensions.ipynb +++ b/sample/string-extensions.ipynb @@ -37,13 +37,129 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\r\n", + "
\r\n", + " \r\n", + " \r\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#r \"../src/CSharpHelperExtensions/bin/Debug/net10.0/CSharpHelperExtensions.dll\"\n", "using CSharpHelperExtensions; // IsNullOrEmpty, In, IsBetween, ToJson\n", @@ -67,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "vscode": { "languageId": "csharp" @@ -286,7 +402,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": { "vscode": { "languageId": "csharp" @@ -423,7 +539,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": { "vscode": { "languageId": "csharp" @@ -465,7 +581,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": { "vscode": { "languageId": "csharp" @@ -523,7 +639,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": { "vscode": { "languageId": "csharp" @@ -711,7 +827,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": { "vscode": { "languageId": "csharp" @@ -972,7 +1088,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": { "vscode": { "languageId": "csharp" @@ -1262,7 +1378,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": { "vscode": { "languageId": "csharp" @@ -1304,7 +1420,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": { "vscode": { "languageId": "csharp" @@ -1356,7 +1472,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": { "vscode": { "languageId": "csharp" @@ -1410,7 +1526,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": { "vscode": { "languageId": "csharp" @@ -1460,7 +1576,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": { "vscode": { "languageId": "csharp" @@ -1512,7 +1628,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": { "vscode": { "languageId": "csharp" @@ -1577,7 +1693,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "metadata": { "vscode": { "languageId": "csharp" @@ -1629,7 +1745,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "metadata": { "vscode": { "languageId": "csharp" @@ -1691,7 +1807,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "metadata": { "vscode": { "languageId": "csharp" @@ -1828,7 +1944,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 18, "metadata": { "vscode": { "languageId": "csharp" @@ -2006,7 +2122,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 19, "metadata": { "vscode": { "languageId": "csharp" @@ -2200,7 +2316,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "metadata": { "vscode": { "languageId": "csharp" @@ -2244,7 +2360,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "metadata": { "vscode": { "languageId": "csharp" @@ -2288,7 +2404,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "metadata": { "vscode": { "languageId": "csharp" @@ -2357,7 +2473,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "metadata": { "vscode": { "languageId": "csharp" @@ -2535,7 +2651,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 24, "metadata": { "vscode": { "languageId": "csharp" @@ -2581,7 +2697,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 25, "metadata": { "vscode": { "languageId": "csharp" @@ -2629,7 +2745,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 26, "metadata": { "vscode": { "languageId": "csharp" @@ -2807,7 +2923,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 27, "metadata": { "vscode": { "languageId": "csharp" @@ -2944,7 +3060,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 28, "metadata": { "vscode": { "languageId": "csharp" @@ -3096,7 +3212,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "metadata": { "vscode": { "languageId": "csharp" @@ -3173,7 +3289,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "metadata": { "vscode": { "languageId": "csharp" @@ -3231,7 +3347,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 31, "metadata": { "vscode": { "languageId": "csharp" diff --git a/sample/value-extensions.ipynb b/sample/value-extensions.ipynb index 6bb3f25..6c053c0 100644 --- a/sample/value-extensions.ipynb +++ b/sample/value-extensions.ipynb @@ -32,14 +32,130 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "c9d0e1f2", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\r\n", + "
\r\n", + " \r\n", + " \r\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#r \"../src/CSharpHelperExtensions/bin/Debug/net10.0/CSharpHelperExtensions.dll\"\n", "using CSharpHelperExtensions.Values; // In, IsBetween, BetweenComparison, ToJson" @@ -62,14 +178,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "e7f8a9b0", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// String membership — role check\n", "display(\"admin\".In(\"admin\", \"superadmin\")); // True\n", @@ -79,14 +316,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "c1d2e3f4", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Integer membership\n", "display(3.In(1, 2, 3, 4)); // True\n", @@ -96,14 +454,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "a5b6c7d8", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Empty set — always false\n", "display(\"x\".In()); // False (no candidates supplied)\n", @@ -112,14 +551,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "e9f0a1b2", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Enum membership\n", "enum HttpMethod { Get, Post, Put, Delete, Patch }\n", @@ -151,14 +711,215 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "a7b8c9d0", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// BetweenComparison.None (default) — inclusive on both ends\n", "display(5.IsBetween(1, 10)); // True (interior)\n", @@ -170,14 +931,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "e1f2a3b4", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// BetweenComparison.ExcludeBoth — exclusive on both ends\n", "display(5.IsBetween(1, 10, BetweenComparison.ExcludeBoth)); // True (interior)\n", @@ -187,14 +1069,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "c5d6e7f8", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// BetweenComparison.ExcludeLower — exclusive lower, inclusive upper\n", "display(5.IsBetween(1, 10, BetweenComparison.ExcludeLower)); // True\n", @@ -204,14 +1207,135 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "a9b0c1d2", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// BetweenComparison.ExcludeUpper — inclusive lower, exclusive upper\n", "display(5.IsBetween(1, 10, BetweenComparison.ExcludeUpper)); // True\n", @@ -221,14 +1345,215 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "e3f4a5b6", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
False
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Works on any IComparable — DateTime and string\n", "\n", @@ -264,14 +1589,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "a1b2e3f4", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{\"Name\":\"Alice\",\"Age\":30}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\"Tags\":[\"a\",\"b\",\"c\"],\"Active\":true}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Compact output (default)\n", "display(new { Name = \"Alice\", Age = 30 }.ToJson()); // {\"Name\":\"Alice\",\"Age\":30}\n", @@ -283,14 +1627,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "c5d6f7a8", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{\n", + " \"Name\": \"Alice\",\n", + " \"Age\": 30\n", + "}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Indented (pretty-printed) output\n", "display(new { Name = \"Alice\", Age = 30 }.ToJson(indentation: true));\n", @@ -302,14 +1659,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "b9c0d1e2", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "42" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "true" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "3.14" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "\"2024-06-15T00:00:00\"" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Value types — works directly on int, bool, DateTime, etc.\n", "display(42.ToJson()); // 42\n", @@ -320,14 +1714,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "f3a4b5c6", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
<null>
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
<null>
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Null-safe — returns null for null input (no exception)\n", "display(((object)null).ToJson()); // null\n", @@ -357,14 +1832,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "f5a6b7c8", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + " -5: invalid score" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + " 0: F" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + " 45: F" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + " 75: B" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + " 90: A" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + " 101: invalid score" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Categorise a score only when it falls in the valid range [0, 100]\n", "int[] scores = { -5, 0, 45, 75, 90, 101 };\n", @@ -402,14 +1932,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "e5f6a7b9", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Can write: True" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Can delete: False" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\n", + " \"Name\": \"Carol\",\n", + " \"Role\": \"editor\",\n", + " \"Action\": \"login\"\n", + "}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "var user = new { Name = \"Carol\", Role = \"editor\", LastLogin = \"2024-06-15\" };\n", "\n", @@ -443,14 +2005,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "a8b9c0d1", "metadata": { "vscode": { "languageId": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{\"Status\":\"succeeded\",\"Timestamp\":\"2024-06-15T12:00:00Z\"}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\"Status\":\"failed\",\"Timestamp\":\"2024-06-15T12:00:00Z\"}" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\"Status\":\"cancelled\",\"Timestamp\":\"2024-06-15T12:00:00Z\"}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// Emit a JSON status event only for terminal states; ignore transient ones\n", "string[] statuses = { \"pending\", \"running\", \"succeeded\", \"failed\", \"cancelled\" };\n", @@ -478,7 +2068,11 @@ "name": ".net-csharp" }, "language_info": { - "name": "C#" + "file_extension": ".cs", + "mimetype": "text/x-csharp", + "name": "C#", + "pygments_lexer": "csharp", + "version": "13.0" } }, "nbformat": 4,