C
C#2y ago
PontiacGTX

How to define an Anonymous type lambda parameter in Linq Expression

0 I had found in a stackoverflow post how they created an anonymous object but I would like to create a Lambda expression which select only a field within an object to be able to Group by Id currently the coude from here Linq: Group by multiple columns using Expression-tree syntax creates a new type but I would like that it could be able to work on GroupBy linq method....
public static Type CreateNewType(List<PropertyInfo> props)
{
AssemblyName asmName = typeof(Program).Assembly.GetName();
AssemblyBuilder dynamicAssembly = AssemblyBuilder
.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
ModuleBuilder dynamicModule = dynamicAssembly.DefineDynamicModule("MyAsm");
TypeBuilder dynamicAnonymousType = dynamicModule
.DefineType("MyType", TypeAttributes.Public);

foreach (var p in props)
{
dynamicAnonymousType.DefineField(p.Name, p.PropertyType, FieldAttributes.Public);
}
return dynamicAnonymousType.CreateType();
}
public static Type CreateNewType(List<PropertyInfo> props)
{
AssemblyName asmName = typeof(Program).Assembly.GetName();
AssemblyBuilder dynamicAssembly = AssemblyBuilder
.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
ModuleBuilder dynamicModule = dynamicAssembly.DefineDynamicModule("MyAsm");
TypeBuilder dynamicAnonymousType = dynamicModule
.DefineType("MyType", TypeAttributes.Public);

foreach (var p in props)
{
dynamicAnonymousType.DefineField(p.Name, p.PropertyType, FieldAttributes.Public);
}
return dynamicAnonymousType.CreateType();
}
using this type using a single field(I only need the field rather the class... groups by an entity MyType which doesnt exist...it should group by either of the entities/fields in my class linq.net-coresystem.reflection
0 Replies
No replies yetBe the first to reply to this messageJoin