Lambda Expressions and Unity

Oct 29, 2009 at 3:30 PM


I would like to declare a Lambda expression (or delegate) in Unity, is this possible?
I would like to create something like this:

	<!-- Lifetime manager types -->

	<!-- User-defined type aliases -->
	<typeAlias alias="When" type="System.Func`2[[string],[System.Boolean, mscorlib]], System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

			<!-- Type mapping with no lifetime – defaults to "transient" -->
			<type name="conditionalRule" type="ConditionalRule" mapTo="ConditionalRule">
				<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
					<property name="When" propertyType="When">
						<value value="s => s.Length > 1" />


Oct 29, 2009 at 6:10 PM

There's no support for that in Unity. The problem is that in order to generate the actual delegate object, we'd need to be able to run the compiler over that lambda expression at runtime. This is not something that's easily done, and has tons of issues around assembly and type references.


Nov 2, 2009 at 12:17 PM

Ok, thanks!