我试图让表达与继承动态类工作DynamicObject
是这样的:
// Dynamic class defintion
public class DynamicClass1 : DynamicObject { // Code here... }
// Here is where I try to create where "someproperty" is untyped and the DynamicClass1 is referenced (not shown here)
public static IQueryable DoStuff(this IQueryable source, string predicate, params object[] values)
{
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, values);
return Expression.Call(
typeof(Queryable), "DoStuff",
new Type[] { source.ElementType },
source.Expression, Expression.Quote(lambda));
}
// Later in the DoStuff() parsing of the Lambda expression the error happens here
Expression ParseMemberAccess(Type type, Expression instance)
{
if (type.IsSubclassOf(typeof(System.Dynamic.DynamicObject)) && instance != null)
{
/*
* Dynamic object found; so create a dummy property since we can't know if it exists or not before after
* we try to retrieve it from the storage.
*/
return Expression.Property(instance, id);
}
}
在返回的错误如下:
An exception of type 'System.ArgumentException' occurred in System.Core.dll but was not handled in user code. Additional information: Property "someproperty" is not defined for type DynamicClass1.
是否有创建的方式Expression
使用非类型化特性的动态对象?