I\'ve got a problem with the following code (which compiles but crashes):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
u
Try implementing IConvertible. Convert
casts your instance to that interface in an attempt to perform conversion.
As for PropertyInfo.SetValue, it gets the Set
method of the property. When this method is invoked via reflection, AFAICT, the arguments are checked by type rather than the ability to implicitly be cast to the proper type. This cast must be performed before invoking.
Convert.ChangeType()
does not use implicit operators. You'll need to have your MyBoolean type implement IConvertible
.
The second problem is related. User-defined conversion operators are not used. You'd need to convert it manually before passing it to SetValue()
.