0
string assembly = "Ektron.Cms.ObjectFactory.dll";
string asspath = path + "bin\\" + assembly;
Assembly run_obj = Assembly.LoadFrom(@asspath);
paraObj[0] = run_obj.GetType(
    "Ektron.Cms.Search.SearchContentProperty",
    true,
    true
).GetProperty("Language");

string equalExp = "Ektron.Cms.Search.Expressions.EqualsExpression";
Type objclass = run_obj.GetType(equalExp, true, true);       
object objObj = Activator.CreateInstance(objclass, paraObj);

Activator.CreateInstance(objclass, paraObj)抛出错误:

System.Reflection.RuntimeParameterInfo 不能隐式转换为 Ektron.Cms.Search.Expresions.PropertyExpression

4

2 回答 2

1

存储的值paraObj[0]是 type RuntimeParameterInfo,而 for 的构造函数EqualsExpression需要一个 type 的对象PropertyExpression。您需要确保其中的对象类型paraObj可以绑定到合适的构造函数,以便 Activator 能够实例化新对象。

要解决您的问题,您需要创建一个实例PropertyExpression并将其用作paraObj数组中的第一个元素:

string assembly = "Ektron.Cms.ObjectFactory.dll";
string asspath = path + "bin\\" + assembly;
Assembly run_obj = Assembly.LoadFrom(@asspath);

PropertyInfo propertyInfo = run_obj.GetType("Ektron.Cms.Search.SearchContentProperty", true, true).GetProperty("Language");
PropertyExpression propertyExpression = new PropertyExpression(propertyInfo); // create the property expression here, I am unsure how to instantiate it.
paraObj[0] = propertyExpression;
paraObj[1] = longValue;

string equalExp = "Ektron.Cms.Search.Expressions.EqualsExpression";
Type objclass = run_obj.GetType(equalExp, true, true);       
object objObj = Activator.CreateInstance(objclass, paraObj);
于 2012-01-10T13:16:11.070 回答
0

您没有提供 Constructor 期望从您的代码中获得的类型,很明显您正在传递PropertyInfo.

如果您需要来自PropertyInfo指向您的属性的值,则必须使用 PropertyInfo.GetValue

我从您的代码片段中推测(因为我没有 Ektron 代码),您应该做类似的事情 -

var propInfo  = run_obj.GetType(
                  "Ektron.Cms.Search.SearchContentProperty",
                   true,true).GetProperty("Language");

paraObj[0] = propInfo.GetValue(null,null)  //depending on the requirement
于 2012-01-10T13:46:59.067 回答