Skip to content

Commit 0a9a885

Browse files
committed
Static Constuctor
1 parent bc91596 commit 0a9a885

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace CSharpClassLibrary.StaticConstructor;
2+
3+
public class Animals
4+
{
5+
private readonly string _description;
6+
private readonly string _speciesBinomialName;
7+
8+
public string Description { get { return _description; } }
9+
public string SpeciesBinomialName { get { return _speciesBinomialName; } }
10+
11+
private Animals(string description, string speciesBinomialName)
12+
{
13+
_description = description;
14+
_speciesBinomialName = speciesBinomialName;
15+
}
16+
17+
private static readonly Animals _dog;
18+
private static readonly Animals _cat;
19+
private static readonly Animals _boaConstrictor;
20+
21+
public static Animals Dog { get { return _dog; } }
22+
public static Animals Cat { get { return _cat; } }
23+
public static Animals BoaConstrictor { get { return _boaConstrictor; } }
24+
25+
static Animals()
26+
{
27+
_dog = new Animals("Man's best friend", "Canis familiaris");
28+
_cat = new Animals("Small, typically furry, killer", "Felis catus");
29+
_boaConstrictor = new Animals("Large, heavy-bodied snake", "Boa constrictor");
30+
}
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace CSharpClassLibrary.StaticConstructor;
2+
3+
class ScopeMonitor
4+
{
5+
static string firstPart = "http://www.example.com/";
6+
static string fullUrl;
7+
static string urlFragment = "foo/bar";
8+
9+
static ScopeMonitor()
10+
{
11+
fullUrl = firstPart + urlFragment;
12+
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.ObjectModel;
2+
using System.Threading.Tasks;
3+
4+
namespace CSharpClassLibrary.StaticConstructor;
5+
6+
public class ViewModel<T>
7+
{
8+
public ObservableCollection<T> Data { get; set; }
9+
10+
//static async method that behave like a constructor
11+
async public static Task<ViewModel<T>> BuildViewModelAsync()
12+
{
13+
//ObservableCollection<T> tmpData = await GetDataTask();
14+
ObservableCollection<T> tmpData = null;
15+
return new ViewModel<T>(tmpData);
16+
}
17+
18+
// private constructor called by the async method
19+
private ViewModel(ObservableCollection<T> Data)
20+
{
21+
this.Data = Data;
22+
}
23+
}

DontRunMe/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ IEnumerable<bool> FourtyTwo(string filename, string[] args)
3636
//try
3737
//{
3838
// var process = Process.Start(filename, args);
39-
// while (!process.HasExited)
39+
// while (!process.HasExited && process.Responding)
4040
// {
4141
// yield return false;
4242
// }
@@ -54,4 +54,14 @@ IEnumerable<bool> FourtyTwo(string filename, string[] args)
5454
UriBuilder uri = new UriBuilder(codeBase);
5555
string path = Uri.UnescapeDataString(uri.Path);
5656
return Path.GetDirectoryName(path);
57+
}
58+
59+
public record test
60+
{
61+
62+
}
63+
64+
public class X : test
65+
{
66+
5767
}

0 commit comments

Comments
 (0)