Open BADF00D opened 6 years ago
New version
Attribute | Description | Target |
---|---|---|
Piped | Defines that return value it that marked argument. Only on per argument in signature is allowed to be marked with this attribute | Argument |
Tracked | On a Argument, it defined that the argument will get tracked by the method; On a ReturnValue, it defines that the return value is tracked by the method | Argument or ReturnValue |
TrackedSet | Show file differences that haven't been staged | Property |
DisposeCall | Defines that method is equivalent to a Dispose method | Method |
Often fluent APIs use this pattern to configure a object wit (extension) method. In order to allow the callee to detect such a pattern, the Argument that is used an input an output can be marked with this attribute.
Example:
We need an additional attribute to mark an setter as Safe during ObjectInitialization. E.g.
using System.Net;
using System.Net.Http;
namespace SomeNamespace
{
internal class HttpResponseMessageSpec
{
public HttpResponseMessage CreateResponse1()
{
var msg = new HttpResponseMessage(HttpStatusCode.Accepted)
{
/* This should not yield an error because this is initialization and we Content if null after ctor was called. */
Content = new StringContent("some content")
};
return msg;
}
}
}
There should be a Attribute that marks Content in order to signal, that Content is Null after ctor of HttpResponseMessage was called. Therefore the first set to Content with an IDisposable is allowed, We can modify TrackedSet. It can have a mode Always or Once. In order to simplify the code, a property marked with TrackedSet(Once) could only be set when using object initializer.
When DisposeCallAttribute is put on an interface method, the implementations and overrides should be treated as dispose calls as well
Prerequisites
Description
In order to detect possible NullReferencesExceptions, JetBrains implemented some attributes within JetBrains.Annotations, so that everybody can mark their custom methods with attributes like CanBeNull. Something like that can be useful, too.
IgnoreMethodDuringDisposeDetectionAttribute
IgnoreClassDuringDisposeDetectionAttribute
TrackingMethodAttribute
CallsDisposeAttribute
if this method was called,
instance
should be considered as disposed. Example