Open tugberkugurlu opened 10 years ago
Potential Bug: What if the implement of the Interface is a structure?
It is already covered with this, isn't it?
@AdamSpeight2008 if you are talking about the below situation, it's safe AFAIK.
var bar = new FooBar(new Foo());
public class FooBar
{
public FooBar(IFoo foo)
{
if (foo == null)
{
throw new ArgumentNullException(nameof(foo));
}
}
}
public interface IFoo
{
}
public struct Foo : IFoo
{
}
I'm gonna have a look at this, as I think I have Idea how to implements. (I'll Branch the build)
This is also applicable for VB implementation. @AdamSpeight2008 can you take a look at VB implementation for this, too?
This is the basic idea was thinking of implementing.
Dim Guards As New List( )( Parameters.Count )
For Each ExistingGuard In ExistingGuards
Dim Index = FindParameterIndexOfGuard( ExistingGuard )
If Index.HasValue Then Guards( Index.Value ) = ExistingGuard
Next
' Remove Existing Guards
' Add new Parameter Guard
Dim NewGuard = CreateSingleLineIfGuard( parameter )
Dim Index = FindParameterIndexOfGuard( NewGuard )
If Index.HasValue Then Guards( Index.Value )
For Each Guard In Guards
' Insert Guard in method
Next
I'll try and get a working prototype later one.
I lean towards this instead:
addNullCheck(x):
insertionIndex = 0
for i = 0...(x - 1)
if isGuardForParameter(i, statements[insertionIndex])
insertionIndex++
statements.insert(insertionIndex, createGuard(x))
Implemented for VB.net
Current implementation doesn't preserve the parameter order for the added if statements: