对于您的第一个问题,也许此链接可以提供一些帮助: 在调用异步委托时防止 Lazy<T> 缓存异常 对于第二个问题,是否要为属性中的属性设置值? 这似乎是不可能的(也可能是我缺乏知识),我试图找到这样的方法,但一无所获。 是否可以在编写属性时定义属性,然后在代码中检查属性的值,如果它不符合预期,则使用反射来获取属性中的属性值并将其分配给目标属性? 像这样:
if (xxx)
{
PropertyInfo propertyInfo = xxx;
CachedWebElementAttribute attribute =(CachedWebElementAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(CachedWebElementAttribute));
if (attribute != null)
{
//propertyInfo.SetValue(myClass, attribute.Lazy, null); // null means no indexes
//Here is the body of the code. We can get the property directly, so we can assign values directly without using reflection.
lazyModal = attribute.Lazy;
}
}
如果回复有帮助,请单击“接受答案”并投赞成票。
注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知。