-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleWritelineObject.cs
50 lines (45 loc) · 968 Bytes
/
ConsoleWritelineObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
public class Program
{
public class Admin
{
public string name { get; set; }
public string adminName { get; set; }
public string password { get; set; }
public string email { get; set; }
public bool isSuperAdmin { get; set; }
public Admin()
{
this.name = "admin";
this.adminName = "admin";
this.password = "password";
this.email = "admin@localhost";
this.isSuperAdmin = true;
}
}
public static void Main()
{
var admin = new Admin();
admin.name = "martin";
WriteObjectToConsole(admin);
Console.WriteLine("Lort");
}
public static string WriteObjectToConsole(object obj)
{
try
{
var properties = obj.GetType().GetProperties();
foreach (var property in properties)
{
Console.WriteLine("{0,-20}: {1,-20}", property.Name, property.GetValue(obj));
}
return "";
}
catch (Exception e)
{
Console.WriteLine("EXCEPTION");
Console.WriteLine(e.Message);
return "";
}
}
}