I want to instantiate this class with reflection:
new DbAccess<ProductMoveRequestView>(dbSet);
I have found ProductMoveRequestView
with reflection. I have it as a Type object.
I have tried with Activator, seen through MakeGenericType
property on Type, and other variations, but I cannot seem to find a way to instantiate this.
It is like duplicate reference, but, as I said in the comments, I still have to instantiate it with an argument.
Type tableType = propertyInfo.PropertyType.GenericTypeArguments.First();
var dbSet = _context.Set(tableType);
Type[] typeArgs = { tableType };
var makeme = typeof(IRepository<>).MakeGenericType(typeArgs);
var o = Activator.CreateInstance(makeme);
The dbSet variable should be sent in as argument when creating the o.
Solution:(I found later) That was easier than I hoped.
Activator.CreateInstance(makeme, constructor, arguments, here);
Sorry guys :) (Hope this helps for anyone else who can't get this to work :)