English 中文(简体)
复制构造静态分析工具吗?
原标题:Copy Constructor Static Analysis Tool?
  • 时间:2012-05-25 18:43:50
  •  标签:
  • c#

是否有工具可以让我标记 C# 方法/ 构建器作为复制构件, 并检查该代码, 以识别复制构件代码中可能发生的明显错误?

需要检查的明显错误如下:

  • If it s supposed to be a deep copy but a shallow copy is obviously happening
  • If it s supposed to be a shallow copy but a deep copy is happening
  • Fields on the source which are not being copied
  • Field on the target which are not being copied

可能还有其他我没想到的聪明检查

我还没有找到任何工具支持它。 代码合同似乎是一个显而易见的工具, 但是如果它确实存在, 我还没有找到它。

除了静态分析工具之外,还有没有其他办法确保制稿者不断更新?

问题回答

单位测试可能是你最好的工具

C# 不自动创建像 C++ 和其他语言一样的复制构建器。 因此, 这通常不是 C++ 中通常存在的问题 。

一般来说,在C#代码中,它们通常比许多其他语言中少得多。 因此,我怀疑你最好在单位测试中包括这种检查,必要时进行这些类型的测试,因为它们只属于少数特定类型。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签