And I just realized the sample I sent you to doesn't have any meaningful
implementation, so here's a quick and dirty one that reads from the appSettings.
You'd modify this to get your own data:
public class MyAppSettingsExpression : ExpressionBuilder
{
public static object GetSetting(string param)
{
return ConfigurationManager.AppSettings[param];
}
public static object GetSetting(string param, Type propType, string propName)
{
return ConfigurationManager.AppSettings[param];
}
public override System.CodeDom.CodeExpression GetCodeExpression(
BoundPropertyEntry entry,
object parsedData,
ExpressionBuilderContext context)
{
if ((entry.DeclaringType == null) || (entry.PropertyInfo == null))
{
CodeExpression[] expressionArray1 =
new CodeExpression[1] { new CodePrimitiveExpression(entry.Expression.Trim())
};
return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()),
"GetSetting", expressionArray1);
}
CodeExpression[] expressionArray2 = new CodeExpression[3] { new CodePrimitiveExpression(entry.Expression.Trim()),
new CodeTypeOfExpression(entry.DeclaringType), new CodePrimitiveExpression(entry.PropertyInfo.Name)
};
return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()),
"GetSetting", expressionArray2);
}
public override object EvaluateExpression(object target, BoundPropertyEntry
entry, object parsedData, ExpressionBuilderContext context)
{
return GetSetting(entry.Expression, target.GetType(), entry.PropertyInfo.Name);
}
public override bool SupportsEvaluate
{
get { return true; }
}
}