@@ -199,6 +199,53 @@ public void VisualBasic_ChangeCompiler()
199
199
VisualBasicSettings . Default . CompilerFactory = references => new VbJitCompiler ( references ) ;
200
200
}
201
201
202
+ [ Theory ]
203
+ [ InlineData ( null ) ]
204
+ [ InlineData ( typeof ( object ) ) ]
205
+ public async Task VisualBasic_CompileAnonymousTypes ( Type targetType )
206
+ {
207
+ SetupCompilation ( out var location , out var namespaces , out var assemblyReferences ) ;
208
+ string expressionText = "in_dt_OrderExport.AsEnumerable().Where(Function(row) row.Field(Of String)(\" Country\" ) = in_CountryName).GroupBy(Function(row) New With {Key .SKU = row.Field(Of String)(\" SKU\" ), Key .ProductTitle = row.Field(Of String)(\" Product Title\" )}).Select(Function(g) New With {Key .SKU = g.Key.SKU, Key .ProductTitle = g.Key.ProductTitle, Key .NetQTY = g.Sum(Function(row) row.Field(Of Decimal)(\" Net QTY\" )), Key .SD = g.Sum(Function(row) row.Field(Of Decimal)(\" S-D\" )), Key .Taxes = g.Sum(Function(row) row.Field(Of Decimal)(\" Taxes\" ))})" ;
209
+
210
+ var compilationResult = await VisualBasicDesignerHelper . CreatePrecompiledValueAsync ( targetType , expressionText , namespaces , assemblyReferences , location ) ;
211
+
212
+ Assert . Equal ( typeof ( IEnumerable < object > ) , compilationResult . ReturnType ) ;
213
+ }
214
+
215
+ [ Theory ]
216
+ [ InlineData ( null ) ]
217
+ [ InlineData ( typeof ( object ) ) ]
218
+ public async Task CSharp_CompileAnonymousTypes ( Type targetType )
219
+ {
220
+ SetupCompilation ( out var location , out var namespaces , out var assemblyReferences ) ;
221
+ string expressionText = "in_dt_OrderExport.AsEnumerable().Where(row => row.Field<String>(\" Country\" ) == in_CountryName).GroupBy(row => new { SKU = row.Field<String>(\" SKU\" ), ProductTitle = row.Field<String>(\" Product Title\" )}).Select(g => new{SKU = g.Key.SKU,ProductTitle = g.Key.ProductTitle,NetQTY = g.Sum(row => row.Field<Decimal>(\" Net QTY\" )),SD = g.Sum(row => row.Field<Decimal>(\" S-D\" )),Taxes = g.Sum(row => row.Field<Decimal>(\" Taxes\" ))})" ;
222
+
223
+ var compilationResult = await CSharpDesignerHelper . CreatePrecompiledValueAsync ( targetType , expressionText , namespaces , assemblyReferences , location ) ;
224
+
225
+ Assert . Equal ( typeof ( IEnumerable < object > ) , compilationResult . ReturnType ) ;
226
+ }
227
+
228
+ private static void SetupCompilation ( out ActivityLocationReferenceEnvironment location , out string [ ] namespaces , out AssemblyReference [ ] assemblyReferences )
229
+ {
230
+ var seq = new Sequence ( ) ;
231
+ IList < ValidationError > errors = [ ] ;
232
+ location = new ActivityLocationReferenceEnvironment ( ) ;
233
+ WorkflowInspectionServices . CacheMetadata ( seq , location ) ;
234
+ location . Declare ( new Variable < string > ( "in_CountryName" ) , seq , ref errors ) ;
235
+ location . Declare ( new Variable < DataTable > ( "in_dt_OrderExport" ) , seq , ref errors ) ;
236
+ namespaces = [ "System" , "System.Linq" , "System.Data" ] ;
237
+ assemblyReferences =
238
+ [
239
+ new AssemblyReference ( ) { Assembly = typeof ( string ) . Assembly } ,
240
+ new AssemblyReference ( ) { Assembly = typeof ( DataTable ) . Assembly } ,
241
+ new AssemblyReference ( ) { Assembly = typeof ( Enumerable ) . Assembly } ,
242
+ new AssemblyReference ( ) { Assembly = typeof ( System . ComponentModel . TypeConverter ) . Assembly } ,
243
+ new AssemblyReference ( ) { Assembly = typeof ( IServiceProvider ) . Assembly } ,
244
+ new AssemblyReference ( ) { Assembly = Assembly . Load ( "System.Xml.ReaderWriter" ) } ,
245
+ new AssemblyReference ( ) { Assembly = Assembly . Load ( "System.Private.Xml" ) }
246
+ ] ;
247
+ }
248
+
202
249
private class ThrowingJitCompiler : JustInTimeCompiler
203
250
{
204
251
public override LambdaExpression CompileExpression ( ExpressionToCompile compilerRequest ) => throw new NotImplementedException ( ) ;
0 commit comments