File tree 5 files changed +80
-0
lines changed
5 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
+
3
+ <PropertyGroup >
4
+ <OutputType >Exe</OutputType >
5
+ <TargetFramework >net6.0</TargetFramework >
6
+ <ImplicitUsings >enable</ImplicitUsings >
7
+ <Nullable >enable</Nullable >
8
+ </PropertyGroup >
9
+
10
+ </Project >
Original file line number Diff line number Diff line change
1
+
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" ) = "CursedCSharp" , "CursedCSharp.csproj" , "{7945A0D2-76A7-49AB-8AA8-24D14D6139F7}"
4
+ EndProject
5
+ Global
6
+ GlobalSection (SolutionConfigurationPlatforms ) = preSolution
7
+ Debug| Any CPU = Debug| Any CPU
8
+ Release| Any CPU = Release| Any CPU
9
+ EndGlobalSection
10
+ GlobalSection (ProjectConfigurationPlatforms ) = postSolution
11
+ {7945A0D2-76A7-49AB-8AA8-24D14D6139F7} .Debug| Any CPU .ActiveCfg = Debug| Any CPU
12
+ {7945A0D2-76A7-49AB-8AA8-24D14D6139F7} .Debug| Any CPU .Build .0 = Debug| Any CPU
13
+ {7945A0D2-76A7-49AB-8AA8-24D14D6139F7} .Release| Any CPU .ActiveCfg = Release| Any CPU
14
+ {7945A0D2-76A7-49AB-8AA8-24D14D6139F7} .Release| Any CPU .Build .0 = Release| Any CPU
15
+ EndGlobalSection
16
+ EndGlobal
Original file line number Diff line number Diff line change
1
+ using System . Runtime . CompilerServices ;
2
+
3
+ foreach ( var i in 12 )
4
+ {
5
+ Console . WriteLine ( i ) ;
6
+ }
7
+
8
+ await new TimeSpan ( 0 , 0 , 2 ) ;
9
+ await 2 . Seconds ( ) ;
10
+
11
+ // Real shenanigans start here
12
+ public static class Extensions
13
+ {
14
+ public static IntEnumerator GetEnumerator ( this int i ) => new ( i ) ;
15
+ public static TaskAwaiter GetAwaiter ( this TimeSpan timeSpan )
16
+ {
17
+ Console . WriteLine ( $ "Waiting { timeSpan } ") ;
18
+ return Task . Delay ( timeSpan ) . GetAwaiter ( ) ;
19
+ }
20
+
21
+ public static TimeSpan Seconds ( this int i ) => new ( 0 , 0 , i ) ;
22
+ }
23
+
24
+ public struct IntEnumerator
25
+ {
26
+ private readonly List < int > _listOfInts ;
27
+ private int _index = - 1 ;
28
+
29
+ public IntEnumerator ( int num )
30
+ {
31
+ _listOfInts = new List < int > ( ) ;
32
+ while ( num > 0 )
33
+ {
34
+ _listOfInts . Add ( num % 10 ) ;
35
+ num /= 10 ;
36
+ }
37
+ _listOfInts . Reverse ( ) ;
38
+ }
39
+
40
+ public int Current => _listOfInts [ _index ] ;
41
+
42
+ public bool MoveNext ( )
43
+ {
44
+ _index ++ ;
45
+ return _listOfInts . Count > _index ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ # Cursed C# - Doing shenanigans in C#
2
+
3
+ In this short blog post I want to show you two silly things so that you can apply right now! Both of them equally silly, but that is not the point (is it ever?).
4
+
5
+ We will see how to await an integer or ` TimeSpan ` and how to foreach through an integer. All of this thanks to the magic of extensions methods.
6
+ Found [ here] ( https://steven-giesel.com/blogPost/5360d1c3-89f6-4a08-9ee3-6ddbe1b44236 )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ Contains all of my examples from various blog posts. You can find a comprehensiv
4
4
5
5
| BlogPost | Publish Date |
6
6
| ---------------------------------------------------------------------------------------- | ------------ |
7
+ | [ Cursed C# - Doing shenanigans in C#] ( CursedCSharp/ ) | 15.10.2022 |
7
8
| [ Introduction to WebApplicationFactory] ( WebAppFactory/ ) | 02.10.2022 |
8
9
| [ EF7 - Bulk updates and Bulk deletes] ( EF7Bulk/ ) | 21.08.2022 |
9
10
| [ Mediator Pattern - CQRS with MediatR] ( MediatorPattern/ ) | 06.08.2022 |
You can’t perform that action at this time.
0 commit comments