You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,27 +38,27 @@ delegate for default constructor can be obtained with DelegateFactory in followi
38
38
39
39
1. If you are have access to type in compile time:
40
40
41
-
`var cd = DelegateFactory.DefaultContructor<TestClass>();`
41
+
`var cd = DelegateFactory.DefaultConstructor<TestClass>();`
42
42
43
43
Created delegate in such case is `Func<TestClass>`
44
-
The same delegate can be created with Contructor method:
44
+
The same delegate can be created with Constructor method:
45
45
46
-
`var cd = DelegateFactory.Contructor<Func<TestClass>>();`
46
+
`var cd = DelegateFactory.Constructor<Func<TestClass>>();`
47
47
48
48
2. If you do not have access to type in compile time (private type, dynamic or otherwise inaccessible)
49
49
50
-
`var cd = TestClassType.DefaultContructor();`
50
+
`var cd = TestClassType.DefaultConstructor();`
51
51
52
52
Created delegate in such case is `Func<object>`
53
-
The same delegate can be created with Contructor method:
53
+
The same delegate can be created with Constructor method:
54
54
55
-
`var cd = TestClassType.Contructor<Func<object>>();`
55
+
`var cd = TestClassType.Constructor<Func<object>>();`
56
56
57
57
Return value is of object type, so we cannot access its members directly, without casting or if it is not possible, members can be accessed via delegates.
58
58
59
-
3. If for some reason you want to create delegate to different constructor depending on some arbitrary, runtime conditions or you do not have access to parameter types in compile time, Contructor(params Type[]) method overload can be used:
59
+
3. If for some reason you want to create delegate to different constructor depending on some arbitrary, runtime conditions or you do not have access to parameter types in compile time, Constructor(params Type[]) method overload can be used:
60
60
61
-
`var cd = TestClassType.Contructor();`
61
+
`var cd = TestClassType.Constructor();`
62
62
63
63
Created delegate in such case is `Func<object[]. object>`
64
64
You can call it in following way:
@@ -80,25 +80,25 @@ delegate can be created in following ways:
80
80
81
81
1. If you are have access to type in compile time:
82
82
83
-
`var c = DelegateFactory.Contructor<Func<int, TestClass>>();`
83
+
`var c = DelegateFactory.Constructor<Func<int, TestClass>>();`
84
84
85
85
Created delegate can be called as any other method that accepts single parameter of Int type:
86
86
87
87
`var instance = c(0);`
88
88
89
89
2. If you do not have access to type in compile time:
90
90
91
-
`var c = TestClassType.Contructor<Func<int, object>>();`
91
+
`var c = TestClassType.Constructor<Func<int, object>>();`
92
92
93
93
Created delegate can be called as any other method that accepts single parameter of Int type:
94
94
95
95
`var instance = c(0);`
96
96
97
97
Return value is type of object, so we cannot access its members directly, without casting or if it is not possible, members can be accessed via delegates.
98
98
99
-
3. If for some reason you want to create delegate to different constructor depending on some arbitrary, runtime conditions or you do not have access to parameter types in compile time, Contructor(params Type[]) method overload can be used:
99
+
3. If for some reason you want to create delegate to different constructor depending on some arbitrary, runtime conditions or you do not have access to parameter types in compile time, Constructor(params Type[]) method overload can be used:
100
100
101
-
`var c = TestClassType.Contructor(typeof(int));`
101
+
`var c = TestClassType.Constructor(typeof(int));`
102
102
103
103
Created delegate in such case is `Func<object[]. object>`
104
104
You can call it in following way:
@@ -109,7 +109,7 @@ delegate can be created in following ways:
109
109
110
110
Delegates can be created for any constructor (visibility do not matter) with any combination of parameters. There is no limitation for number of parameters of constructor. All of above methods works for both classes and structures.
111
111
112
-
If you have access to all neccessary types and can create compatible delegate type, `Contructor<TDelegate>` method can be used. TDelegate type must follow these rules:
112
+
If you have access to all neccessary types and can create compatible delegate type, `Constructor<TDelegate>` method can be used. TDelegate type must follow these rules:
113
113
- parameters of delegate *must be* exactly of the same types and order as constructor
114
114
- return type of delegate *must be* type with constructor
115
115
@@ -119,26 +119,26 @@ I.e. if you constructor have 3 parameters:
119
119
120
120
TDelegate *must be*`Func<string,int,bool,TestClass>`. It is because collection of constructor parameters are taked from TDelegate definition and constructor is searched in return type of defined TDelegate.
121
121
122
-
`var c = DelegateFactory.Contructor<Func<string, int, bool, TestClass>>();`
122
+
`var c = DelegateFactory.Constructor<Func<string, int, bool, TestClass>>();`
123
123
124
124
There is no limitation for type of delegate that can be accepted. For example, it can be `Func<>`, but do not have to. You can create your own delegate type, but it is must follow above restrictions.
var cd = DelegateFactory.Contructor<CustomCtrSingleParam>();
127
+
var cd = DelegateFactory.Constructor<CustomCtrSingleParam>();
128
128
var instance = cd(0);`
129
129
130
130
131
-
If you do not have access to type with constructor in compile time and still have access to constructor parameters types, `Contructor<TDelegate>(this Type)` extension method can be used. In this case return type of delegate can be any type that can be casted from source type (i.e. interface of TestClass, base type or object).
131
+
If you do not have access to type with constructor in compile time and still have access to constructor parameters types, `Constructor<TDelegate>(this Type)` extension method can be used. In this case return type of delegate can be any type that can be casted from source type (i.e. interface of TestClass, base type or object).
132
132
133
-
`var c = TestClassType.Contructor<Func<string, string, DateTime, object>>();`
133
+
`var c = TestClassType.Constructor<Func<string, string, DateTime, object>>();`
134
134
135
135
Restriction for parameters types and order still applies.
136
136
137
137
138
-
However if you do not have access to parameters types `Contructor(this Type, params Type[])` extension method ca be used. Array of parameters types must be *exactly the same* order and length as type of parameters of constructor. Overload do not require any delegate type. Instead have fixed delegate to `Func<object[], object>`. First parameter of created delegate is array of all constructor parameters values. It can be larger than required collection. Returned object is created instance. There is no limitation of number of parameters of constructor.
138
+
However if you do not have access to parameters types `Constructor(this Type, params Type[])` extension method ca be used. Array of parameters types must be *exactly the same* order and length as type of parameters of constructor. Overload do not require any delegate type. Instead have fixed delegate to `Func<object[], object>`. First parameter of created delegate is array of all constructor parameters values. It can be larger than required collection. Returned object is created instance. There is no limitation of number of parameters of constructor.
139
139
140
-
`var c = TestClassType.Contructor(typeof(bool));`
141
-
`var c = TestClassType.Contructor(typeof(string), typeof(bool), typeof(IDisposable));`
140
+
`var c = TestClassType.Constructor(typeof(bool));`
141
+
`var c = TestClassType.Constructor(typeof(string), typeof(bool), typeof(IDisposable));`
0 commit comments