I am attempting to create an extension method for type object that will create a new way of initializing an object and setting its properties. I have however run into a few problems. The extension looks like so:
public static class ObjectExtension
{
public static TResult Select<TSource,TResult>(this TSource obj, Func<TSource, TResult> selector)
{
return selector.Invoke(obj);
}
}
And this is the kind of result that I'm looking for:
return new Product().Select(p => p.Category = new Category(), p.Name = "something");
As you can likely tell perhaps my understanding is too little. I'm having trouble grasping the idea of Func and how to use them. My question is if this is possible and how/what direction do I need to go to accomplish this?
My inspiration came from this: Here
With the following code:
IEnumerable<int> squares =
Enumerable.Range(1, 10).Select(x => x * x);
I want to do something like that except not from a list and have the ability to set multiple properties.