工具来写一个对象实例到C#(为单元测试)来写、实例、单元测试、对象

2023-09-06 15:42:32 作者:朝夕相处

说我有一个方法,需要的对象的列表。该方法通常需要20个对象容易。每个对象对他们有15个左右的属性。

Say I have a method that takes a list of objects. The method will normally take 20 objects easy. Each object has 15 or so properties on them.

为单元测试这一点,我需要键入的所有20个对象,这样我可以将它们传递到我的方法。

To unit test this, I need to type out all 20 objects so that I can pass them into my method.

这是令人沮丧的时候,我可以看到什么,我需要在我的调试器监视窗口坐在那里非常好的例子。

This is frustrating when I can see perfectly good examples of what I need sitting there in my debugger watch window.

是否有工具来采取我并使其输出到C#对象?

Is there a tool to take an object that I have and make it output to C#?

注:我看到了这样一个问题:是否有工具来序列化对象到C#对象初始化code 但code它会产生不工作...

NOTE: I saw this question: Is there a tool to serialize an object to C# object initializer code? but the code it generates does not work...

我不认为我是第一个想这一点。它比我想象的更难?还是有工具,有做到这一点了吗?

I can't think I am the first to want this. Is it harder than I think? or are there tools out there that do it already?

推荐答案

我创建了一个Visual Studio插件称为的对象导出这正是这一点。你可以在C#中,JSON或XML导出对象实例。

I created a visual studio plugin called Object Exporter which does exactly this. You can export an object instance in C#, JSON or XML.