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(
87 this BadObject elem,
88 string propName,
89 Func<BadExecutionContext, BadObject> func,
90 BadClassPrototype returnType)
91 {
92 elem.SetProperty(propName, new BadDynamicInteropFunction(propName, func, returnType), new BadPropertyInfo(BadFunction.Prototype, true));
93 }
94
103 public static void SetFunction<T>(
104 this BadObject elem,
105 string propName,
106 Func<BadExecutionContext, T, BadObject> func,
107 BadClassPrototype returnType)
108 {
109 elem.SetProperty(
110 propName,
111 new BadDynamicInteropFunction<T>(propName, func, returnType, GetParameters(typeof(T))),
113 );
114 }
115
125 public static void SetFunction<T1, T2>(
126 this BadObject elem,
127 string propName,
128 Func<BadExecutionContext, T1, T2, BadObject> func,
129 BadClassPrototype returnType)
130 {
131 elem.SetProperty(
132 propName,
133 new BadDynamicInteropFunction<T1, T2>(propName, func, returnType, GetParameters(typeof(T1), typeof(T2)))
134 );
135 }
136
147 public static void SetFunction<T1, T2, T3>(
148 this BadObject elem,
149 string propName,
150 Func<BadExecutionContext, T1, T2, T3, BadObject> func,
151 BadClassPrototype returnType)
152 {
153 elem.SetProperty(
154 propName,
156 propName,
157 func,
158 returnType,
159 GetParameters(typeof(T1), typeof(T2), typeof(T3))
160 )
161 );
162 }
163
175 public static void SetFunction<T1, T2, T3, T4>(
176 this BadObject elem,
177 string propName,
178 Func<BadExecutionContext, T1, T2, T3, T4, BadObject> func,
179 BadClassPrototype returnType)
180 {
181 elem.SetProperty(
182 propName,
184 propName,
185 func,
186 returnType,
187 GetParameters(typeof(T1), typeof(T2), typeof(T3), typeof(T4))
188 )
189 );
190 }
191
205 this BadObject elem,
206 string propName,
207 Func<BadExecutionContext, T1, T2, T3, T4, T5, BadObject> func,
208 BadClassPrototype returnType)
209 {
210 elem.SetProperty(
211 propName,
213 propName,
214 func,
215 returnType,
216 GetParameters(typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5))
217 )
218 );
219 }
220
235 this BadObject elem,
236 string propName,
237 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, BadObject> func,
238 BadClassPrototype returnType)
239 {
240 elem.SetProperty(
241 propName,
243 propName,
244 func,
245 returnType,
246 GetParameters(typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6))
247 )
248 );
249 }
250
266 this BadObject elem,
267 string propName,
268 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, BadObject> func,
269 BadClassPrototype returnType)
270 {
271 elem.SetProperty(
272 propName,
274 propName,
275 func,
276 returnType,
277 GetParameters(typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7))
278 )
279 );
280 }
281
298 this BadObject elem,
299 string propName,
300 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, BadObject> func,
301 BadClassPrototype returnType)
302 {
303 elem.SetProperty(
304 propName,
306 propName,
307 func,
308 returnType,
310 typeof(T1),
311 typeof(T2),
312 typeof(T3),
313 typeof(T4),
314 typeof(T5),
315 typeof(T6),
316 typeof(T7),
317 typeof(T8)
318 )
319 )
320 );
321 }
322
340 this BadObject elem,
341 string propName,
342 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, BadObject> func,
343 BadClassPrototype returnType)
344 {
345 elem.SetProperty(
346 propName,
348 propName,
349 func,
350 returnType,
352 typeof(T1),
353 typeof(T2),
354 typeof(T3),
355 typeof(T4),
356 typeof(T5),
357 typeof(T6),
358 typeof(T7),
359 typeof(T8),
360 typeof(T9)
361 )
362 )
363 );
364 }
365
384 this BadObject elem,
385 string propName,
386 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, BadObject> func,
387 BadClassPrototype returnType)
388 {
389 elem.SetProperty(
390 propName,
392 propName,
393 func,
394 returnType,
396 typeof(T1),
397 typeof(T2),
398 typeof(T3),
399 typeof(T4),
400 typeof(T5),
401 typeof(T6),
402 typeof(T7),
403 typeof(T8),
404 typeof(T9),
405 typeof(T10)
406 )
407 )
408 );
409 }
410
430 this BadObject elem,
431 string propName,
432 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, BadObject> func,
433 BadClassPrototype returnType)
434 {
435 elem.SetProperty(
436 propName,
438 propName,
439 func,
440 returnType,
442 typeof(T1),
443 typeof(T2),
444 typeof(T3),
445 typeof(T4),
446 typeof(T5),
447 typeof(T6),
448 typeof(T7),
449 typeof(T8),
450 typeof(T9),
451 typeof(T10),
452 typeof(T11)
453 )
454 )
455 );
456 }
457
478 this BadObject elem,
479 string propName,
480 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, BadObject> func,
481 BadClassPrototype returnType)
482 {
483 elem.SetProperty(
484 propName,
486 propName,
487 func,
488 returnType,
490 typeof(T1),
491 typeof(T2),
492 typeof(T3),
493 typeof(T4),
494 typeof(T5),
495 typeof(T6),
496 typeof(T7),
497 typeof(T8),
498 typeof(T9),
499 typeof(T10),
500 typeof(T11),
501 typeof(T12)
502 )
503 )
504 );
505 }
506
528 this BadObject elem,
529 string propName,
530 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, BadObject> func,
531 BadClassPrototype returnType)
532 {
533 elem.SetProperty(
534 propName,
536 propName,
537 func,
538 returnType,
540 typeof(T1),
541 typeof(T2),
542 typeof(T3),
543 typeof(T4),
544 typeof(T5),
545 typeof(T6),
546 typeof(T7),
547 typeof(T8),
548 typeof(T9),
549 typeof(T10),
550 typeof(T11),
551 typeof(T12),
552 typeof(T13)
553 )
554 )
555 );
556 }
557
580 this BadObject elem,
581 string propName,
582 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, BadObject> func,
583 BadClassPrototype returnType)
584 {
585 elem.SetProperty(
586 propName,
588 propName,
589 func,
590 returnType,
592 typeof(T1),
593 typeof(T2),
594 typeof(T3),
595 typeof(T4),
596 typeof(T5),
597 typeof(T6),
598 typeof(T7),
599 typeof(T8),
600 typeof(T9),
601 typeof(T10),
602 typeof(T11),
603 typeof(T12),
604 typeof(T13),
605 typeof(T14)
606 )
607 )
608 );
609 }
610
634 this BadObject elem,
635 string propName,
636 Func<BadExecutionContext, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, BadObject> func,
637 BadClassPrototype returnType)
638 {
639 elem.SetProperty(
640 propName,
642 propName,
643 func,
644 returnType,
646 typeof(T1),
647 typeof(T2),
648 typeof(T3),
649 typeof(T4),
650 typeof(T5),
651 typeof(T6),
652 typeof(T7),
653 typeof(T8),
654 typeof(T9),
655 typeof(T10),
656 typeof(T11),
657 typeof(T12),
658 typeof(T13),
659 typeof(T14),
660 typeof(T15)
661 )
662 )
663 );
664 }
665}
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