lundi 25 février 2019

How to create an instance of byte[] with lambda expressions?

The code below works perfectly with a lot of objects in the "T" parameter.

ConstructorInfo constructorInfo = typeof(T).GetConstructor(Type.EmptyTypes);
NewExpression newExpression = Expression.New(constructorInfo);
dynamic instance = Expression.Lambda<Func<dynamic>>(newExpression).Compile()();

But, if "T" is a byte[], an exception occurs.

ArgumentNullException: Value cannot be null. Parameter name: construtor at Expression.New(ConstructorInfo consctructor)

I would like to operate this code with a byte array parameter, while keeping it generic.

I hope you can help me solve this error.





Aucun commentaire:

Enregistrer un commentaire