@@ -23,12 +23,11 @@ public static class ColumnCursorExtensions
23
23
/// <param name="columnName">The name of the column to extract.</param>
24
24
public static IEnumerable < T > GetColumn < T > ( this IDataView data , string columnName )
25
25
{
26
- var env = RetrieveHost ( data ) ;
27
- env . CheckValue ( data , nameof ( data ) ) ;
28
- env . CheckNonEmpty ( columnName , nameof ( columnName ) ) ;
26
+ Contracts . CheckValue ( data , nameof ( data ) ) ;
27
+ Contracts . CheckNonEmpty ( columnName , nameof ( columnName ) ) ;
29
28
30
29
if ( ! data . Schema . TryGetColumnIndex ( columnName , out int col ) )
31
- throw env . ExceptSchemaMismatch ( nameof ( columnName ) , "input" , columnName ) ;
30
+ throw Contracts . ExceptSchemaMismatch ( nameof ( columnName ) , "input" , columnName ) ;
32
31
33
32
// There are two decisions that we make here:
34
33
// - Is the T an array type?
@@ -56,7 +55,7 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, string columnName
56
55
{
57
56
// Output is an array type.
58
57
if ( ! ( colType is VectorType colVectorType ) )
59
- throw env . ExceptSchemaMismatch ( nameof ( columnName ) , "input" , columnName , "vector" , "scalar" ) ;
58
+ throw Contracts . ExceptSchemaMismatch ( nameof ( columnName ) , "input" , columnName , "vector" , "scalar" ) ;
60
59
var elementType = typeof ( T ) . GetElementType ( ) ;
61
60
if ( elementType == colVectorType . ItemType . RawType )
62
61
{
@@ -75,24 +74,7 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, string columnName
75
74
}
76
75
// Fall through to the failure.
77
76
}
78
- throw env . Except ( $ "Could not map a data view column '{ columnName } ' of type { colType } to { typeof ( T ) } .") ;
79
- }
80
-
81
- /// <summary>
82
- /// Return a <see cref="IHost"/> assigned in a given <see cref="IDataView"/> implementation.
83
- /// </summary>
84
- /// <param name="data">an <see cref="IDataView"/> implementation.</param>
85
- private static IHost RetrieveHost ( IDataView data )
86
- {
87
- // Search for the first (if there are multiples) field typed to IHost.
88
- var fields = data . GetType ( ) . GetFields ( System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) ;
89
- var fieldInfo = fields . Where ( ( field , index ) => field . FieldType == typeof ( IHost ) ) . FirstOrDefault ( ) ;
90
-
91
- // Check if a IHost really gets retrieved.
92
- string errorMessage = nameof ( data ) + " should contains a field of " + typeof ( IHost ) ;
93
- Contracts . CheckValue ( fieldInfo , nameof ( data ) , errorMessage ) ;
94
-
95
- return ( IHost ) fieldInfo . GetValue ( data ) ;
77
+ throw Contracts . Except ( $ "Could not map a data view column '{ columnName } ' of type { colType } to { typeof ( T ) } .") ;
96
78
}
97
79
98
80
private static IEnumerable < T > GetColumnDirect < T > ( IDataView data , int col )
0 commit comments