I want to determine if it is assigned to MyBindingSource.DataSourcea set of constructors Type, or if an object instance has been assigned to it. This is my current (rather ugly) solution:
MyBindingSource.DataSource
Type
Type sourceT = MyBindingSource.DataSource.GetType(); if( sourceT == null || sourceT.ToString().Equals("System.RuntimeType") ) { return null; } return (ExpectedObjType) result;
System.RuntimeType is closed and inaccessible, so I can not do this:
System.RuntimeType
Type sourceT = MyBindingSource.DataSource.GetType(); if ( object.ReferenceEquals(sourceT, typeof(System.RuntimeType)) ) { return null; } return (ExpectedObjType) result;
I'm just wondering if there is a better solution? In particular, this does not apply to the name Type.
Since System.RuntimeTypeobtained from System.Type, you should be able to do the following:
System.Type
object result = MyBindingSource.DataSource; if (typeof(Type).IsAssignableFrom(result.GetType())) { return null; } return (ExpectedObjType)result;
or even more briefly:
object result = MyBindingSource.DataSource; if (result is Type) { return null; } return (ExpectedObjType)result;
By the way, this is the approach taken here .
ToString(); GetType() ( ). , , , " ", , , , RuntimeType. " " , .
, , RuntimeType, , . , Type, RuntimeType, " ".
Source: https://habr.com/ru/post/1767575/More articles:VS 2010: How to cancel Find and Replace? - visual-studioPassing a value from a button to a WPF ListView - listviewFailed to load type Error creating new Integration Services package using SQL Server Business Intelligence Development Studio - ssisRegEx Question - remove everything between: and ~ - javascriptBest way to create graphic, cross-platform, e-books? - html5Why do file formats have magic numbers? - file-formatWhy doesn't the compiler warn about definitions without names? - c ++How to determine if browser window is activated - javascriptCreating an administration area for managing a dynamic website - c #C # DateTime, Trim without conversion to string - c #All Articles