BadScript 2
Loading...
Searching...
No Matches
BadDynamicFunctionExtensions_Func.cs
Go to the documentation of this file.
5
7
8public static partial class BadDynamicFunctionExtensions
9{
15 private static BadClassPrototype? TryConvertType(Type t)
16 {
17 if (t == typeof(string))
18 {
19 return BadNativeClassBuilder.GetNative("string");
20 }
21
22 if (t == typeof(bool))
23 {
24 return BadNativeClassBuilder.GetNative("bool");
25 }
26
27 if (t.IsNumericType())
28 {
29 return BadNativeClassBuilder.GetNative("num");
30 }
31
32 if (t.IsArray ||
33 (t.IsGenericType &&
34 (t.GetGenericTypeDefinition() == typeof(List<>) || t.GetGenericTypeDefinition() == typeof(IList<>))))
35 {
36 return BadNativeClassBuilder.GetNative("Array");
37 }
38
39 //if (t.IsFunction() || t.IsAction()) return BadNativeClassBuilder.GetNative("Function");
40
41 return null;
42 }
43
49 private static BadFunctionParameter[] GetParameters(params Type[] t)
50 {
51 List<BadFunctionParameter> ret = new List<BadFunctionParameter>();
52 bool canBeOptional = true;
53
54 for (int i = t.Length - 1; i >= 0; i--)
55 {
56 Type type = t[i];
57 bool isNullable = false;
58
59 if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(BadNullable<>))
60 {
61 isNullable = true;
62 type = type.GetGenericArguments()[0];
63 }
64
65 bool optional = canBeOptional && isNullable;
66 bool nullChecked = !isNullable;
67 BadClassPrototype? bType = TryConvertType(type);
68 ret.Insert(0, new BadFunctionParameter(type.Name, optional, nullChecked, false, null, bType));
69
70 if (!isNullable)
71 {
72 canBeOptional = false;
73 }
74 }
75
76 return ret.ToArray();
77 }
78
86 public static void SetFunction(this BadObject elem,
87 string propName,
88 Func<BadExecutionContext, BadObject> func,
89 BadClassPrototype returnType)
90 {
91 elem.SetProperty(propName,
92 new BadDynamicInteropFunction(propName, func, returnType),
94 );
95 }
96
105 public static void SetFunction<T>(this BadObject elem,
106 string propName,
107 Func<BadExecutionContext, T, BadObject> func,
108 BadClassPrototype returnType)
109 {
110 elem.SetProperty(propName,
111 new BadDynamicInteropFunction<T>(propName, func, returnType, GetParameters(typeof(T))),
113 );
114 }
115
125 public static void SetFunction<T1, T2>(this BadObject elem,
126 string propName,
127 Func<BadExecutionContext, T1, T2, BadObject> func,
128 BadClassPrototype returnType)
129 {
130 elem.SetProperty(propName,
132 func,
133 returnType,
134 GetParameters(typeof(T1), typeof(T2))
135 )
136 );
137 }
138
149 public static void SetFunction<T1, T2, T3>(this BadObject elem,
150 string propName,
151 Func<BadExecutionContext, T1, T2, T3, BadObject> func,
152 BadClassPrototype returnType)
153 {
154 elem.SetProperty(propName,
156 func,
157 returnType,
158 GetParameters(typeof(T1), typeof(T2), typeof(T3))
159 )
160 );
161 }
162
174 public static void SetFunction<T1, T2, T3, T4>(this BadObject elem,
175 string propName,
176 Func<BadExecutionContext, T1, T2, T3, T4, BadObject> func,
177 BadClassPrototype returnType)
178 {
179 elem.SetProperty(propName,
181 func,
182 returnType,
183 GetParameters(typeof(T1),
184 typeof(T2),
185 typeof(T3),
186 typeof(T4)
187 )
188 )
189 );
190 }
191
204 public static void SetFunction<T1, T2, T3, T4, T5>(this BadObject elem,
205 string propName,
206 Func<BadExecutionContext, T1, T2, T3, T4, T5, BadObject> func,
207 BadClassPrototype returnType)
208 {
209 elem.SetProperty(propName,
211 func,
212 returnType,
213 GetParameters(typeof(T1),
214 typeof(T2),
215 typeof(T3),
216 typeof(T4),
217 typeof(T5)
218 )
219 )
220 );
221 }
222
236 public static void SetFunction<T1, T2, T3, T4, T5, T6>(this BadObject elem,
237 string propName,
238 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, BadObject>
239 func,
240 BadClassPrototype returnType)
241 {
242 elem.SetProperty(propName,
244 func,
245 returnType,
246 GetParameters(typeof(T1),
247 typeof(T2),
248 typeof(T3),
249 typeof(T4),
250 typeof(T5),
251 typeof(T6)
252 )
253 )
254 );
255 }
256
272 string propName,
273 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7,
274 BadObject> func,
275 BadClassPrototype returnType)
276 {
277 elem.SetProperty(propName,
279 func,
280 returnType,
281 GetParameters(typeof(T1),
282 typeof(T2),
283 typeof(T3),
284 typeof(T4),
285 typeof(T5),
286 typeof(T6),
287 typeof(T7)
288 )
289 )
290 );
291 }
292
309 string propName,
310 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7,
311 T8, BadObject> func,
312 BadClassPrototype returnType)
313 {
314 elem.SetProperty(propName,
316 func,
317 returnType,
318 GetParameters(typeof(T1),
319 typeof(T2),
320 typeof(T3),
321 typeof(T4),
322 typeof(T5),
323 typeof(T6),
324 typeof(T7),
325 typeof(T8)
326 )
327 )
328 );
329 }
330
348 string propName,
349 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6,
350 T7, T8, T9, BadObject> func,
351 BadClassPrototype returnType)
352 {
353 elem.SetProperty(propName,
355 func,
356 returnType,
357 GetParameters(typeof(T1),
358 typeof(T2),
359 typeof(T3),
360 typeof(T4),
361 typeof(T5),
362 typeof(T6),
363 typeof(T7),
364 typeof(T8),
365 typeof(T9)
366 )
367 )
368 );
369 }
370
389 string propName,
390 Func<BadExecutionContext, T1, T2, T3, T4, T5
391 , T6, T7, T8, T9, T10, BadObject> func,
392 BadClassPrototype returnType)
393 {
394 elem.SetProperty(propName,
396 func,
397 returnType,
398 GetParameters(typeof(T1),
399 typeof(T2),
400 typeof(T3),
401 typeof(T4),
402 typeof(T5),
403 typeof(T6),
404 typeof(T7),
405 typeof(T8),
406 typeof(T9),
407 typeof(T10)
408 )
409 )
410 );
411 }
412
432 string propName,
433 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, BadObject> func,
434 BadClassPrototype returnType)
435 {
436 elem.SetProperty(propName,
438 func,
439 returnType,
440 GetParameters(typeof(T1),
441 typeof(T2),
442 typeof(T3),
443 typeof(T4),
444 typeof(T5),
445 typeof(T6),
446 typeof(T7),
447 typeof(T8),
448 typeof(T9),
449 typeof(T10),
450 typeof(T11)
451 )
452 )
453 );
454 }
455
476 string propName,
477 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, BadObject> func,
478 BadClassPrototype returnType)
479 {
480 elem.SetProperty(propName,
482 func,
483 returnType,
484 GetParameters(typeof(T1),
485 typeof(T2),
486 typeof(T3),
487 typeof(T4),
488 typeof(T5),
489 typeof(T6),
490 typeof(T7),
491 typeof(T8),
492 typeof(T9),
493 typeof(T10),
494 typeof(T11),
495 typeof(T12)
496 )
497 )
498 );
499 }
500
522 string propName,
523 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, BadObject> func,
524 BadClassPrototype returnType)
525 {
526 elem.SetProperty(propName,
528 func,
529 returnType,
530 GetParameters(typeof(T1),
531 typeof(T2),
532 typeof(T3),
533 typeof(T4),
534 typeof(T5),
535 typeof(T6),
536 typeof(T7),
537 typeof(T8),
538 typeof(T9),
539 typeof(T10),
540 typeof(T11),
541 typeof(T12),
542 typeof(T13)
543 )
544 )
545 );
546 }
547
570 string propName,
571 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, BadObject> func,
572 BadClassPrototype returnType)
573 {
574 elem.SetProperty(propName,
575 new BadDynamicInteropFunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
576 T14>(propName,
577 func,
578 returnType,
579 GetParameters(typeof(T1),
580 typeof(T2),
581 typeof(T3),
582 typeof(T4),
583 typeof(T5),
584 typeof(T6),
585 typeof(T7),
586 typeof(T8),
587 typeof(T9),
588 typeof(T10),
589 typeof(T11),
590 typeof(T12),
591 typeof(T13),
592 typeof(T14)
593 )
594 )
595 );
596 }
597
621 this BadObject elem,
622 string propName,
623 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, BadObject> func,
624 BadClassPrototype returnType)
625 {
626 elem.SetProperty(propName,
627 new BadDynamicInteropFunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
628 T15>(propName,
629 func,
630 returnType,
631 GetParameters(typeof(T1),
632 typeof(T2),
633 typeof(T3),
634 typeof(T4),
635 typeof(T5),
636 typeof(T6),
637 typeof(T7),
638 typeof(T8),
639 typeof(T9),
640 typeof(T10),
641 typeof(T11),
642 typeof(T12),
643 typeof(T13),
644 typeof(T14),
645 typeof(T15)
646 )
647 )
648 );
649 }
650}
The Execution Context. Every execution of a script needs a context the script is running in....
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2 > func)
Sets a Function on the given Object.
static void SetFunction(this BadObject elem, string propName, Func< BadExecutionContext, BadObject > func, BadClassPrototype returnType)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7 > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 > func)
Sets a Function on the given Object.
static void SetFunction< T >(this BadObject elem, string propName, Action< BadExecutionContext, T > func)
Sets a Function on the given Object.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 > func)
Sets a Function on the given Object.
static BadFunctionParameter[] GetParameters(params Type[] t)
Returns a list of BadFunctionParameters for the given Types.
static void SetFunction< T1, T2, T3, T4, T5, T6 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6 > func)
Sets a Function on the given Object.
static ? BadClassPrototype TryConvertType(Type t)
Tries to convert a Type to a BadClassPrototype.
static void SetFunction< T1, T2, T3, T4, T5, T6, T7, T8 >(this BadObject elem, string propName, Action< BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8 > func)
Sets a Function on the given Object.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Stores Meta Information about a Property.
Implements a function that can be called from the script.
static readonly BadClassPrototype Prototype
The Prototype for the Function Object.
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static BadClassPrototype GetNative(string name)
Returns a Native Class Prototype for the given Native Type.
Contains the Extension Classes for Functions.
Contains the Interop Reflection Classes for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
This is a helper type that can be used when using the .SetFunction extensions to allow for nullable p...
Definition BadNullable.cs:8