0

I have an object myClassType of Type

string typeName = @"MyCompany.MyApp.MyDomain.MyClass"; Type myClassType = Type.GetType(typeName); 

and I want to create a lambda expression (similar to the one below), but how do I get the MyClass from the myClassType so that I can pass it to the Func

Expression.Lambda<Func<MyClass, bool>>() 

Is it possible to do so? any alternative ways or suggestions welcome.

5
  • so do you need an object from myClassType type definition? Then use Activator.CreateInstance(myClassType) and cast it to MyClass. Notice there is an inconsistency: you have one type defined in two different ways: in string and in usual way as Type parameter Commented Jun 12, 2014 at 23:38
  • Would the result from Activator.CreateInstance(myclassType) can be used in Func<????, bool> ? Commented Jun 13, 2014 at 0:03
  • I am not looking to create an instance object of that type, but to use that type myClassType to create a Func<**MyClass**, bool> Commented Jun 13, 2014 at 0:11
  • Are you wanting to create an Expression<Func<MyClass, bool>> or just a Func<MyClass, bool>? Commented Jun 13, 2014 at 1:46
  • Actually I want to create Expression.Lambda<Func<MyClass, bool>>(...) Commented Jun 13, 2014 at 4:13

1 Answer 1

1

Use

Expression.Lambda(...) 

Non generic signature and treat the result as your known type.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.