自定义业务对象比较器
我需要实现比较两个业务对象并返回差异列表(过去值、新值、isDifferenceBetter)的机制。
因为并非类的所有字段都必须进行比较,并且一个字段需要与不同的函数进行比较,然后另一个字段(有时 < 更好,有时 > 更好...)我发现我需要实现自定义属性并给出它与该对象中必须进行比较的每个字段。
该属性必须具有: - 姓名 - 委托或某物指向将应用于比较的函数(到目前为止不知道如何做)
那么有人可以建议我如果这是一个好主意吗?也许还有其他想法。
使用属性,我将能够使用反射来迭代具有属性的每个字段并调用所需的委托。
谢谢你的帮助 再见
I need to implement mechanism that compares two business objects and return the list of differences (past value, new value, isDifferenceBetter).
Because not all fields of class has to be compared and one fields need to be compared with different function then the other (sometimes < is better sometimes > is better ... ) I figured out that I need to implelemnt custom attribute and give it to each field that has to be compared in this object.
This attribute must have:
- name
- delegate or sth to point to the function which would be applied for comparision (dont know how to do it so far)
So could anyone suggest me if its a good idea? Maybe any other ideas.
Using attributes I would be able to use refflection to iterate through each field with attribute and invoke needed delegate.
thanks for help
bye
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅下面我的示例。
也许,它可以帮助您:
See my example below.
May be, it can help you:
搜索一下自跟踪对象以及 ORM(如 NHibernate)检查对象是否有脏字段的方式
Do some search about self tracking objects and the way ORMs(like NHibernate) checking an object for dirty fields
当然可能,但也许您应该考虑更抽象的术语。也许一对属性 [LowerValueIsBetter] 和 [HigherValueIsBetter] 将使您能够以更有凝聚力的方式表达此信息。
Certainly possible but perhaps you should be thinking along more abstract terms. Maybe a pair of attributes [LowerValueIsBetter] and [HigherValueIsBetter] would enable you to express this information in a more cohesive way.