Injecting to a dynamic

Feb 23, 2011 at 12:12 PM

I've managed to inject values to a static target type from a dynamic source type.

However, I can't manage to inject to a dynamic target type from a static source type.

There is probably a built-in injecter/option for this, I just can't find it.

Thanks!
Johan

Coordinator
Feb 23, 2011 at 1:46 PM

I think this isn't possible because you can't get a list of properties of the dynamic type

Feb 28, 2011 at 11:47 AM

I managed to solve it using something like the following code:

private class VersionInjection : ValueInjection
{
	protected override void Inject(object source, dynamic target)
	{ 
		var expando = target as IDictionary<string, object>;
		if (expando == null)
			return;

		foreach (var s in source.GetProps())
		{
			expando[s.Name] = s.GetValue(source);
		}
	}
}

 

Coordinator
Feb 28, 2011 at 11:50 AM

gj, keep it up