C# implicit cast “overloading” and reflection problem

前端 未结 2 1628
清歌不尽
清歌不尽 2021-01-21 07:50

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         


        
2条回答
  •  我在风中等你
    2021-01-21 08:43

    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.

提交回复
热议问题