【发布时间】:2023-03-10 00:31:01
【问题描述】:
已编辑:对不起,但这个示例正在工作......简化我的问题我找到了问题的根源:const 的类型。在示例中是“int”,而在我的真实代码中是“short”。然后我必须重新提出这个问题:为什么我不能访问一个短常量?我无法更改 const 的类型。
我想将对象的属性与内部类中定义的常量进行比较。 示例:
public class A {
public const int A_CONST = 1;
public class B {
public const int AB_CONST = 1;
}
}
现在,当我尝试在 spring.net 的 ExpressionEvaluator 中评估包含 A.B.AB_CONST 的表达式时,我不知道该怎么做。我已经尝试了很多东西,但没有奏效。
我已经注册了A型:
TypeRegistry.RegisterType(typeof(A))
我可以访问 A_CONST
ExpressionEvaluator.GetValue(null, "A.A_CONST")
但是对于 A.B 类,它不起作用。我尝试使用“。”使用别名注册类型。和“+”。也可以通过不同的方式访问它,但对我来说没有任何方法。
TypeRegistry.RegisterType(typeof(A.B))
ExpressionEvaluator.GetValue(null, "A.B.AB_CONST")
ExpressionEvaluator.GetValue(null, "A+B.AB_CONST")
TypeRegistry.RegisterType("AB", typeof(A.B))
ExpressionEvaluator.GetValue(null, "AB.AB_CONST")
TypeRegistry.RegisterType("A.B", typeof(A.B))
ExpressionEvaluator.GetValue(null, "A.B.AB_CONST")
ExpressionEvaluator.GetValue(null, "A+B.AB_CONST")
有什么想法吗?
【问题讨论】:
标签: c# .net spring.net