internal CodeExpression CompileExpression (MemberInfo member, Type type, string value, bool useSetAttribute)
{
// First let's find the correct expression builder
value = value.Substring (3, value.Length - 5).Trim ();
int colon = value.IndexOf (':');
if (colon == -1)
return null;
string prefix = value.Substring (0, colon).Trim ();
string expr = value.Substring (colon + 1).Trim ();
CompilationSection cs = (CompilationSection)WebConfigurationManager.GetWebApplicationSection ("system.web/compilation");
if (cs == null)
return null;
if (cs.ExpressionBuilders == null || cs.ExpressionBuilders.Count == 0)
return null;
System.Web.Configuration.ExpressionBuilder ceb = cs.ExpressionBuilders[prefix];
if (ceb == null)
return null;
string builderType = ceb.Type;
Type t;
try {
t = HttpApplication.LoadType (builderType, true);
} catch (Exception e) {
throw new HttpException (String.Format ("Failed to load expression builder type `{0}'", builderType), e);
}
if (!typeof (System.Web.Compilation.ExpressionBuilder).IsAssignableFrom (t))
throw new HttpException (String.Format ("Type {0} is not descendant from System.Web.Compilation.ExpressionBuilder", builderType));
System.Web.Compilation.ExpressionBuilder eb = null;
object parsedData;
ExpressionBuilderContext ctx;
try {
eb = Activator.CreateInstance (t) as System.Web.Compilation.ExpressionBuilder;
ctx = new ExpressionBuilderContext (HttpContext.Current.Request.FilePath);
parsedData = eb.ParseExpression (expr, type, ctx);
} catch (Exception e) {
throw new HttpException (String.Format ("Failed to create an instance of type `{0}'", builderType), e);
}
BoundPropertyEntry bpe = CreateBoundPropertyEntry (member as PropertyInfo, prefix, expr, useSetAttribute);
return eb.GetCodeExpression (bpe, parsedData, ctx);
}