別のタイプ()に暗黙の演算子SpecialImageを実装する特定のタイプ()のオブジェクトがあります。Image
SpecialImageから派生していませんImage。ただし、オペレーターを介して次のことが可能です。
var someImage = new Image();
(SpecialImage)someImage;
リフレクションとオブジェクトによってループしているプロパティを持つオブジェクトがありImageます。
info.PropertyType値を設定する前に、オブジェクトがキャスト可能かどうかを確認することはできますか?
var someImage = new Image();
foreach(PropertyInfo info in someOjbect.GetType().GetProperties()) {
//info.PropertyType == typeof(SomeImage);
//Is it possible to check if the object is castable to
//info.PropertyType before trying to set the value?
info.SetValue(someObject, someImage, null);
}