public Delegate ToDelegate() { var innerSource = _interceptionPlan ?? Inner; var builder = innerSource.ToExpression(Parameters.Session, Parameters.Context); if (builder.Type != PluginType) { builder = Expression.Convert(builder, PluginType); } var message = "Failure while building '{0}', check the inner exception for details".ToFormat(Instance.Description); var wrapped = TryCatchWrapper.WrapFunc <StructureMapBuildException>(message, PluginType, builder, Instance); // Push/Pop for contextual construction and bi-directional dependency checking wrapped = PushPopWrapper.WrapFunc(PluginType, Instance, wrapped); wrapped = TryCatchWrapper.WrapFunc <StructureMapBuildException>(message, PluginType, wrapped, this); if (!wrapped.Type.GetTypeInfo().IsClass) { wrapped = Expression.Convert(wrapped, typeof(object)); } var lambdaType = typeof(Func <, ,>).MakeGenericType(typeof(IBuildSession), typeof(IContext), typeof(object)); var lambda = Expression.Lambda(lambdaType, wrapped, Parameters.Session, Parameters.Context); return(lambda.Compile()); }
public Expression ToExpression(ParameterExpression session, ParameterExpression context) { var expression = buildInnerExpression(session, context); return (TryCatchWrapper.WrapFunc <StructureMapBuildException>( "Error while building type {0}. See the inner exception for details".ToFormat( _concreteType.GetFullName()), _concreteType, expression, this)); }