如何从单个方法填充多种类型的业务对象?
我有四个不同的 Business 对象,每个对象都调用其相应的 FillBusinessObject 方法来一一填充所有单独的对象属性。现在我希望创建一个通用方法,它应该能够填充每种类型的业务对象。我创建了一个基类,所有业务对象都从该基类继承,但我无法弄清楚如何从通用方法填充各个对象属性。
这可能吗(如果是,那么如何)或者我在梦境世界中?
PS 我不想采取像 LINQ 这样的不同路线。
I have four different Business objects and each calls its corresponding FillBusinessObject method to fill all the individual object properties one by one. Now I wish to create a common method which should be able to fill each type of business object. I've created a base class from which all business objects inherit but I am not able to figure out how to fill individual object properties from a common method.
Is this possible (if yes, then how) or am I in dreamworld?
P.S. I don't wish to take a different route like LINQ.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来你把事情过于复杂化了。
您可以编写一个方法来填充属于公共基类的部分,然后为每种类型调用专用方法。
Looks like you're over-complicating things.
You could write a method that fills the part that belongs to a common base-class and then calls a specialize method for each type.
像这样的事情怎么样:
How about something like this: