File tree Expand file tree Collapse file tree
TryCSharp.DotNetCore2.Tutorial Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace TryCSharp . DotNetCore2 . Tutorial
4+ {
5+ internal class HelloWorld : IExecutable
6+ {
7+ public void Execute ( )
8+ {
9+ Console . WriteLine ( "Hello world" ) ;
10+ }
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ namespace TryCSharp . DotNetCore2 . Tutorial
2+ {
3+ internal interface IExecutable
4+ {
5+ void Execute ( ) ;
6+ }
7+ }
Original file line number Diff line number Diff line change 22
33namespace TryCSharp . DotNetCore2 . Tutorial
44{
5- class Program
5+ internal class Program
66 {
7- static void Main ( string [ ] args )
7+ private static void Main ( string [ ] args )
88 {
9- Console . WriteLine ( "Hello World!" ) ;
9+ var me = new Program ( ) ;
10+ me . Execute ( ) ;
11+ }
12+
13+ private void Execute ( )
14+ {
15+ var input = Console . ReadLine ( ) ;
16+ if ( string . IsNullOrWhiteSpace ( input ) )
17+ {
18+ Console . WriteLine ( "please enter class name. exit...." ) ;
19+ return ;
20+ }
21+
22+ var fullTypeName = string . Format ( "TryCSharp.DotNetCore2.Tutorial.{0}" , input ) ;
23+ var type = Type . GetType ( fullTypeName ) ;
24+ if ( type == null )
25+ {
26+ Console . WriteLine ( "[ERROR] target type does not found. exit...." ) ;
27+ return ;
28+ }
29+
30+ var instance = Activator . CreateInstance ( type ) ;
31+ if ( instance == null )
32+ {
33+ Console . WriteLine ( "[ERROR] error has occured exit...." ) ;
34+ return ;
35+ }
36+
37+ if ( ! ( instance is IExecutable executable ) )
38+ {
39+ Console . WriteLine ( "[ERROR] can't cast to IExecutable. exit..." ) ;
40+ return ;
41+ }
42+
43+ executable . Execute ( ) ;
44+
45+ Console . WriteLine ( "exit" ) ;
1046 }
1147 }
1248}
Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" >
2-
1+ <Project Sdk =" Microsoft.NET.Sdk" >
32 <PropertyGroup >
43 <OutputType >Exe</OutputType >
54 <TargetFramework >netcoreapp2.0</TargetFramework >
65 </PropertyGroup >
7-
8- </Project >
6+ </Project >
You can’t perform that action at this time.
0 commit comments