.NET : How do you get the Type of a null object?

前端 未结 12 1288
暗喜
暗喜 2020-11-28 13:59

I have a method with an out parameter that tries to do a type conversion. Basically:

public void GetParameterValue(out object destination)
{
    object param         


        
12条回答
  •  天涯浪人
    2020-11-28 14:51

    I don't think it is possible to get the type when the value is null. Also, since you are calling inside GetParameterValue, the best you could do (when the value is null) is to get the type of the "destination" parameter which is "object". You might consider passing the Type as a parameter to GetParameterValue where you have more information, such as:

    public void GetParameterValue(Type sourceType, out object destination) { //... }
    

提交回复
热议问题