-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
61 lines (50 loc) · 1.25 KB
/
Program.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
51
52
53
54
55
56
57
58
59
60
61
String connectionString = new ConnectionBuilder()
.SetServer("127.0.0.1")
.SetDatabase("Northwind")
.SetUserId("Nancy")
.SetPassword("123456")
.Build();
Console.WriteLine(connectionString);
class ConnectionBuilder
{
private class Connection
{
public string database;
public string server;
public string userId;
public string password;
public override string ToString()
{
return $"Server={server};Database={database};UserId={userId};Password={password}";
}
}
private readonly Connection connection;
public ConnectionBuilder()
{
connection = new Connection();
}
public ConnectionBuilder SetDatabase(String database)
{
connection.database = database;
return this;
}
public ConnectionBuilder SetServer(String server)
{
connection.server = server;
return this;
}
public ConnectionBuilder SetUserId(String userId)
{
connection.userId = userId;
return this;
}
public ConnectionBuilder SetPassword(String password)
{
connection.password = password;
return this;
}
public String Build()
{
return connection.ToString();
}
}