I want to pass an extension method that returns void as a parameter to another extension method that returns dynamic.
public static void AddTo(this Object entity, Object parent)
{
parent.GetCollectionOf(entity).Add(entity);
}
public static dynamic And(this Object entity, Action method)
{
entity.method(parent);
return entity;
}
I’d like to use it something like this,
dynamic parent = MakeNew(parentType);
dynamic entity = MakeNew(type).And(AddTo(parent));
I like to pass any void method into And() but still return the object it extended. I hope the dynamic return type is not problematic.
What is the syntax for this kind of thing?
Could you perhaps do it like this?
Use my linq carefully, it could explode at any moment 😉
To explain this fully: