I want to determine whether MyBindingSource.DataSource is assigned to the designer set Type, or if it has been assigned an object instance. This is my current (rather ugly) solution:
Type sourceT = MyBindingSource.DataSource.GetType();
if( sourceT == null || sourceT.ToString().Equals("System.RuntimeType") ) {
return null;
}
return (ExpectedObjType) result;
The System.RuntimeType is private and non-accessible, so I can’t do this:
Type sourceT = MyBindingSource.DataSource.GetType();
if ( object.ReferenceEquals(sourceT, typeof(System.RuntimeType)) ) {
return null;
}
return (ExpectedObjType) result;
I was just wondering if a better solution exists? Particularly one that doesn’t rely on the Type name.
Since
System.RuntimeTypeis derived fromSystem.Typeyou should be able to do the following:or even more concisely:
Coincidentally this is the approach adopted here.