自动填充 CLR 对象的任何库
有人知道有什么库可以自动填充 CLR 对象吗?
例如:
我有一个用户对象,其中名字和姓氏作为成员。我会 想要用一些随机值自动填充对象,以便用户 对象可以立即使用。
User user = new User ();
// Explicit member assignment
user.setFirstName ("John");
user.setLastName ("Doe");
// 我需要这个,
AutoPopulateLibrary.fill (user);
我将传递用户对象或类名或其他内容以及目标 对象必须被神奇地填充。
这可以完成吗,还是我在这里遗漏了一些东西?
Anyone know of any libraries that can autopopulate a CLR object?
Ex:
I have a User object with first name and last name as members. I would
want to auto populate the object with some random values so the user
object can be used right away.
User user = new User ();
// Explicit member assignment
user.setFirstName ("John");
user.setLastName ("Doe");
// I need this
AutoPopulateLibrary.fill (user);
I'll pass the user object or the class name or whatever and the target
object must be magically filled.
Can this be done, or Am i missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之前有人问过这个问题 - 有一些很好的答案:
This was asked before - there are some good answers:
@Oded 引用的帖子均未提及 约束不确定性,如 AutoFixture,它是简化测试(包括自动生成数据)的强大力量。
None of @Oded's cited posts mention Constrained Nondeterminism as embodied by AutoFixture, which is a powerful force for simplifying tests, including the autogeneration of data.