c# - PropertyInfo SetValue and nulls -


If I have something like this:

  object value = zero; Fu fu = new foo (); Property Info Property = Foo.GetProperties (). Single (P => P. Name == "Intraparty"); Asset .set value (eff, value, blank);  

then foo.IntProperty is set to 0 , even if value = null . It appears that this is doing something like IntProperty = default (typeof (int)) . I would like to throw InvalidCastException if IntProperty is not a "faucet" type ( Nullable <> or reference). I am using reflection, so I do not know the timing of time if you work on PropertyInfo , how do I do it?

You can check for . Property Type ; If . IvValueType is true, and if is Nullable.GetUnderlyingType (property.PropertyType) is zero, then this is a non-empty value-type:

  (Value == blank & property type.yesweeppe & amp; amp; amp; amp; amp; amp; amp; amp; GetUnderlyingType (property.PropertyType) == faucet) {new invalid CastException (); }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -