Essayez ça :
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Linq.Expressions; namespace ConsoleApplication1 { class Program { static void Main(string [] args) { var ctor = typeof(EvilBug).GetConstructor(new Type [] { typeof(object) }); var arguments = new Expression [] { Expression.Constant("BUG !!!") }; var members = typeof(EvilBug).GetMember("Object"); var e = Expression.New( ctor, arguments, members ); } } class EvilBug { public object Object { get; set; } public EvilBug(object obj) { } } }
Logiquement, je dois pouvoir créer une instance de "EvilBug", même si le paramètre "obj" est de type string, ou n'importe quoi d'autre.
Et bien non, pas avec Expression.New....
Partager