@@ -101,11 +101,11 @@ private static bool CheckScoreColumnKind(Schema schema, int col)
101
101
}
102
102
103
103
/// <summary>
104
- /// Find the score column to use. If name is specified, that is used. Otherwise, this searches for the
105
- /// most recent score set of the given kind. If there is no such score set and defName is specifed it
106
- /// uses defName. Otherwise, it throws.
104
+ /// Find the score column to use. If <paramref name="name"/> is specified, that is used. Otherwise, this searches
105
+ /// for the most recent score set of the given <paramref name=" kind"/> . If there is no such score set and
106
+ /// <paramref name="defName"/> is specifed it uses <paramref name=" defName"/> . Otherwise, it throws.
107
107
/// </summary>
108
- public static ColumnInfo GetScoreColumnInfo ( IExceptionContext ectx , Schema schema , string name , string argName , string kind ,
108
+ public static Schema . Column GetScoreColumn ( IExceptionContext ectx , Schema schema , string name , string argName , string kind ,
109
109
string valueKind = MetadataUtils . Const . ScoreValueKind . Score , string defName = null )
110
110
{
111
111
Contracts . CheckValueOrNull ( ectx ) ;
@@ -115,51 +115,52 @@ public static ColumnInfo GetScoreColumnInfo(IExceptionContext ectx, Schema schem
115
115
ectx . CheckNonEmpty ( kind , nameof ( kind ) ) ;
116
116
ectx . CheckNonEmpty ( valueKind , nameof ( valueKind ) ) ;
117
117
118
- int colTmp ;
119
- ColumnInfo info ;
120
118
if ( ! string . IsNullOrWhiteSpace ( name ) )
121
119
{
122
- #pragma warning disable MSML_ContractsNameUsesNameof
123
- if ( ! ColumnInfo . TryCreateFromName ( schema , name , out info ) )
120
+ #pragma warning disable MSML_ContractsNameUsesNameof // This utility method is meant to reflect the argument name of whatever is calling it, so we take that as a parameter, rather than using nameof directly as in most cases.
121
+ var col = schema . GetColumnOrNull ( name ) ;
122
+ if ( ! col . HasValue )
124
123
throw ectx . ExceptUserArg ( argName , "Score column is missing" ) ;
125
124
#pragma warning restore MSML_ContractsNameUsesNameof
126
- return info ;
125
+ return col . Value ;
127
126
}
128
127
129
- var maxSetNum = schema . GetMaxMetadataKind ( out colTmp , MetadataUtils . Kinds . ScoreColumnSetId ,
128
+ var maxSetNum = schema . GetMaxMetadataKind ( out int colTmp , MetadataUtils . Kinds . ScoreColumnSetId ,
130
129
( s , c ) => IsScoreColumnKind ( ectx , s , c , kind ) ) ;
131
130
132
131
ReadOnlyMemory < char > tmp = default ;
133
- foreach ( var col in schema . GetColumnSet ( MetadataUtils . Kinds . ScoreColumnSetId , maxSetNum ) )
132
+ foreach ( var colIdx in schema . GetColumnSet ( MetadataUtils . Kinds . ScoreColumnSetId , maxSetNum ) )
134
133
{
134
+ var col = schema [ colIdx ] ;
135
135
#if DEBUG
136
- schema [ col ] . Metadata . GetValue ( MetadataUtils . Kinds . ScoreColumnKind , ref tmp ) ;
136
+ col . Metadata . GetValue ( MetadataUtils . Kinds . ScoreColumnKind , ref tmp ) ;
137
137
ectx . Assert ( ReadOnlyMemoryUtils . EqualsStr ( kind , tmp ) ) ;
138
138
#endif
139
139
// REVIEW: What should this do about hidden columns? Currently we ignore them.
140
- if ( schema [ col ] . IsHidden )
140
+ if ( col . IsHidden )
141
141
continue ;
142
- if ( schema . TryGetMetadata ( TextType . Instance , MetadataUtils . Kinds . ScoreValueKind , col , ref tmp ) &&
143
- ReadOnlyMemoryUtils . EqualsStr ( valueKind , tmp ) )
142
+ if ( col . Metadata . Schema . GetColumnOrNull ( MetadataUtils . Kinds . ScoreValueKind ) ? . Type == TextType . Instance )
144
143
{
145
- return ColumnInfo . CreateFromIndex ( schema , col ) ;
144
+ col . Metadata . GetValue ( MetadataUtils . Kinds . ScoreValueKind , ref tmp ) ;
145
+ if ( ReadOnlyMemoryUtils . EqualsStr ( valueKind , tmp ) )
146
+ return col ;
146
147
}
147
148
}
148
149
149
- if ( ! string . IsNullOrWhiteSpace ( defName ) && ColumnInfo . TryCreateFromName ( schema , defName , out info ) )
150
- return info ;
150
+ if ( ! string . IsNullOrWhiteSpace ( defName ) && schema . GetColumnOrNull ( defName ) is Schema . Column defCol )
151
+ return defCol ;
151
152
152
153
#pragma warning disable MSML_ContractsNameUsesNameof
153
154
throw ectx . ExceptUserArg ( argName , "Score column is missing" ) ;
154
155
#pragma warning restore MSML_ContractsNameUsesNameof
155
156
}
156
157
157
158
/// <summary>
158
- /// Find the optional auxilliary score column to use. If name is specified, that is used.
159
- /// Otherwise, if colScore is part of a score set, this looks in the score set for a column
160
- /// with the given valueKind. If none is found, it returns null.
159
+ /// Find the optional auxilliary score column to use. If <paramref name="name"/> is specified, that is used.
160
+ /// Otherwise, if <paramref name=" colScore"/> is part of a score set, this looks in the score set for a column
161
+ /// with the given <paramref name=" valueKind"/> . If none is found, it returns <see langword=" null"/> .
161
162
/// </summary>
162
- public static ColumnInfo GetOptAuxScoreColumnInfo ( IExceptionContext ectx , Schema schema , string name , string argName ,
163
+ public static Schema . Column ? GetOptAuxScoreColumn ( IExceptionContext ectx , Schema schema , string name , string argName ,
163
164
int colScore , string valueKind , Func < ColumnType , bool > testType )
164
165
{
165
166
Contracts . CheckValueOrNull ( ectx ) ;
@@ -171,14 +172,14 @@ public static ColumnInfo GetOptAuxScoreColumnInfo(IExceptionContext ectx, Schema
171
172
172
173
if ( ! string . IsNullOrWhiteSpace ( name ) )
173
174
{
174
- ColumnInfo info ;
175
175
#pragma warning disable MSML_ContractsNameUsesNameof
176
- if ( ! ColumnInfo . TryCreateFromName ( schema , name , out info ) )
176
+ var col = schema . GetColumnOrNull ( name ) ;
177
+ if ( ! col . HasValue )
177
178
throw ectx . ExceptUserArg ( argName , "{0} column is missing" , valueKind ) ;
178
- if ( ! testType ( info . Type ) )
179
+ if ( ! testType ( col . Value . Type ) )
179
180
throw ectx . ExceptUserArg ( argName , "{0} column has incompatible type" , valueKind ) ;
180
181
#pragma warning restore MSML_ContractsNameUsesNameof
181
- return info ;
182
+ return col . Value ;
182
183
}
183
184
184
185
// Get the score column set id from colScore.
@@ -192,17 +193,18 @@ public static ColumnInfo GetOptAuxScoreColumnInfo(IExceptionContext ectx, Schema
192
193
schema [ colScore ] . Metadata . GetValue ( MetadataUtils . Kinds . ScoreColumnSetId , ref setId ) ;
193
194
194
195
ReadOnlyMemory < char > tmp = default ;
195
- foreach ( var col in schema . GetColumnSet ( MetadataUtils . Kinds . ScoreColumnSetId , setId ) )
196
+ foreach ( var colIdx in schema . GetColumnSet ( MetadataUtils . Kinds . ScoreColumnSetId , setId ) )
196
197
{
197
198
// REVIEW: What should this do about hidden columns? Currently we ignore them.
198
- if ( schema [ col ] . IsHidden )
199
+ var col = schema [ colIdx ] ;
200
+ if ( col . IsHidden )
199
201
continue ;
200
- if ( schema . TryGetMetadata ( TextType . Instance , MetadataUtils . Kinds . ScoreValueKind , col , ref tmp ) &&
201
- ReadOnlyMemoryUtils . EqualsStr ( valueKind , tmp ) )
202
+
203
+ if ( col . Metadata . Schema . GetColumnOrNull ( MetadataUtils . Kinds . ScoreValueKind ) ? . Type == TextType . Instance )
202
204
{
203
- var res = ColumnInfo . CreateFromIndex ( schema , col ) ;
204
- if ( testType ( res . Type ) )
205
- return res ;
205
+ col . Metadata . GetValue ( MetadataUtils . Kinds . ScoreValueKind , ref tmp ) ;
206
+ if ( ReadOnlyMemoryUtils . EqualsStr ( valueKind , tmp ) && testType ( col . Type ) )
207
+ return col ;
206
208
}
207
209
}
208
210
0 commit comments