How do I define null checking methods?

Hi JetBrainers,

how can I define my own null checking methods so that R# does not warn
for possible 'null' assignment to entity marked with 'NotNull'
attribute? I have a method 'Expect.NotNull(x)' for these checks.


Regards,
Stefan Lieser
--
http://www.lieser-online.de

8 comments
Comment actions Permalink


public static void
IsNotNull(object
value)
{...}


--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Stefan Lieser" <stefan@lieser-online.de> wrote in message
news:fr80cc$blo$1@is.intellij.net...

Hi JetBrainers,

>

how can I define my own null checking methods so that R# does not warn for
possible 'null' assignment to entity marked with 'NotNull' attribute? I
have a method 'Expect.NotNull(x)' for these checks.

>
>

Regards,
Stefan Lieser
--
http://www.lieser-online.de



0
Comment actions Permalink

Hello Eugene,

what if I don't have the source? What if I don't want to attach R#
attributes at my source?

R# 3.x uses its config files for that and I must say that I find it a
much better solution.


Regards,
Stefan Lieser

Eugene Pasynkov (JetBrains) schrieb:


public static void
IsNotNull(object
value)
{...}

0
Comment actions Permalink

We've fixed attribute full names for these purposes.
You either should reference JetBrains.Annotations assembly, either define
these attributes in your sources.

This is done so to unify attribute names across different libraries, and for
our external annotations feature

These scema is preliminary, so we are currently searching for solution which
will suit the majority.

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Stefan Lieser" <stefan@lieser-online.de> wrote in message
news:fr87ou$bt6$1@is.intellij.net...

Hello Eugene,

>

what if I don't have the source? What if I don't want to attach R#
attributes at my source?

>

R

  1. 3.x uses its config files for that and I must say that I find it a much

better solution.

>
>

Regards,
Stefan Lieser

>

Eugene Pasynkov (JetBrains) schrieb:

>>
>> public static void
>> IsNotNull(object
>> value)
>> {...}
>>

0
Comment actions Permalink

Unfortunateley, there already exist many different attributes to indicate "MayBeNull" or "MayNotBeNull", so it is too late for R# to require customers to use a specific R# attribute. Also, for various legal purposes requiring commercial customers to include R# binaries in production code is problematic, as is requiring specific namespace issues (if a namespace component is a trademark or other "owned" character sequence fear prevails).

A better solution is to A) revert to the 3.* technique of allowing the project to define names for "MayBeNull" and "MayNotBeNull", and B) allow specification of more than one name for each concept.

B) is required because the R# options are solution-wide, but different projects (or binary dll's referenced) may use different attribute names.

0
Comment actions Permalink

Please could you clarify which tools already use "MayBeNull"/"MayNotBeNull"
attributes?

We are going to discuss this problem internally, and I hope we will provide
solution wich will suit everybody

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Brian Strelioff" <BKStrelioff@Hotmail.com> wrote in message
news:19935374.1205327680752.JavaMail.itn@is.intellij.net...

Unfortunateley, there already exist many different attributes to indicate
"MayBeNull" or "MayNotBeNull", so it is too late for R# to require
customers to use a specific R# attribute. Also, for various legal purposes
requiring commercial customers to include R# binaries in production code
is problematic, as is requiring specific namespace issues (if a namespace
component is a trademark or other "owned" character sequence fear
prevails).

>

A better solution is to A) revert to the 3.* technique of allowing the
project to define names for "MayBeNull" and "MayNotBeNull", and B) allow
specification of more than one name for each concept.

>

B) is required because the R# options are solution-wide, but different
projects (or binary dll's referenced) may use different attribute names.



0
Comment actions Permalink

Well, in addition to other code verification tools, there are unit-test generation tools that will use these kinds of attributes to verify that code properly handles associated cases. Also, some projects use these types of attributes solely for documentation purposes currently, but it would be nice to have R# automatically verify the code as documented.

Also, there are semantic differences between May/Can/Shall, and sometimes these types of attributes also indicate the name of the exception thrown for a violation. And different projects have adopted different "default" constraint and handling.

The failure of C#/CLR to support nullity issues from day 1 has, unfortunately, led to many grass-roots attempts to address this shortcoming, so I think R# is more useful if it is more flexible.

0
Comment actions Permalink

I agree, introducing a dependency to an R# library simply to avoid R# warnings is not good. Not to mention the name collision.

Could R# simply look for attributes by name, not by type?

0
Comment actions Permalink

We've modified ReSharper behavior, now it looks for specific attributes in
multiple namespaces, including those defined in your code.
Please look forward for detailed description of this feature

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Peter Ritchie" <no_reply@jetbrains.com> wrote in message
news:24130290.7411206638873780.JavaMail.jive@app4.labs.intellij.net...
>I agree, introducing a dependency to an R# library simply to avoid R#
>warnings is not good. Not to mention the name collision.
>

Could R# simply look for attributes by name, not by type?



0

Please sign in to leave a comment.