English 中文(简体)
是否有固定代码核查可能无效物体参考材料?
原标题:Is static code verification for potential null object references available?

我希望能够发出警告,如果某一物体可能提出“Null Reference”例外,那么我就可以为这些例外撰写防御守则。

我看着Resharper,但看不出在这方面取得的成就。

《法典》合同可能是非开端合同;申请数量很大,在《法典》合同正式公布之前,在“NET”3.5中写成。

最佳回答

Resharper does in fact accomplish something like this. Possible NullReferenceExpections are highlighted in the IDE in blue, with tooltips when you hover over them.

“entergraph

然后,Resharper在自己的检查结果窗口上跟踪潜在的错误和警告(与视觉演播室的编辑错误和警告分开)。

“entergraph

问题回答

一般说来,除非您具体提出反对, 至少就汇编者而言,它总是有可能放弃否定的参考。

为了检查提及物体是否可能无效,必须绕开你方案能够走的每一种可能途径,包括你可能使用的任何外部图书馆的道路。 即便是最简单的方案,这种算法也会杀害你的编辑。

我不反对在守则和每种方法中为每个领域盲目辩护的想法。

下面的帮助我决定,在什么地方制止无效价值:

1- Who will be invoking your methods?
If a method is private and you have control over how s it s being accessed, I don t see it makes sense to protect against null checks unless it s part of the method s logic to expect null values. If a method is exposed to the public (Such as an API), then of course null checks should be a huge concern.

2- Software Design:
Image you have are calling method1(fromAnimalToString(animal)); and for some reason fromAnimalToString() never returns null (Though might return an empty string instead).
Then in such case, it wouldn t make sense to check animal != null in method1() s body

3- Testing:
In software engineering, it s almost impossible to test all possible scenarios that can ever execute. However, test normal and alternative scenarios and make sure the flow is as expected.





相关问题
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. ...

热门标签