Skip to content

Commit

Permalink
Adds Optional/Named parameter constructors for the Parakeet attribute
Browse files Browse the repository at this point in the history
fixes #5
  • Loading branch information
Scott Offen committed Sep 19, 2019
1 parent 5367428 commit 5ac3e69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 84 deletions.
17 changes: 16 additions & 1 deletion src/Parakeet.Tests/ParakeetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,27 @@ public void default_attribute_values()
var attr = new ParakeetAttribute("MyName");

attr.Name.ShouldBe("MyName");
attr.TableName.ShouldBeNull();
attr.Direction.ShouldBe(ParameterDirection.Input);
attr.DbType.ShouldBeNull();
attr.Size.ShouldBeNull();
attr.Precision.ShouldBeNull();
attr.Scale.ShouldBeNull();
}

[Fact]
public void optional_named_parameters()
{
var attr = new ParakeetAttribute(propertyName: "MyName", tableName: "dbo.MyTable", dbType: DbType.Binary);

attr.Name.ShouldBe("MyName");
attr.TableName.ShouldBe("dbo.MyTable");
attr.Direction.ShouldBe(ParameterDirection.Input);
attr.DbType.ShouldBe(DbType.Binary);
attr.Size.ShouldBeNull();
attr.Precision.ShouldBeNull();
attr.Scale.ShouldBeNull();
}
}

public class TestClass
Expand Down Expand Up @@ -122,7 +137,7 @@ public class TestClass
[ParakeetIgnore]
public string Ignored { get; set; }

[Parakeet("NewName")]
[Parakeet(propertyName: "NewName")]
public string OldName { get; set; }

public NotEligible NotEligibleValue { get; set; } = new NotEligible();
Expand Down
2 changes: 1 addition & 1 deletion src/Parakeet/Parakeet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>dapper dynamicparameter</PackageTags>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version>1.0.5.0</Version>
<Version>1.1.0.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/scottoffen/parakeet</RepositoryUrl>
Expand Down
95 changes: 13 additions & 82 deletions src/Parakeet/ParakeetAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Runtime.InteropServices;

namespace Parakeet
{
Expand All @@ -26,97 +27,27 @@ public class ParakeetAttribute : Attribute

public ParakeetAttribute() { }

public ParakeetAttribute(string name)
public ParakeetAttribute(string propertyName = null, ParameterDirection direction = ParameterDirection.Input, string tableName = null, int size = -1, byte precision = 0, byte scale = 0)
{
Name = name;
}

public ParakeetAttribute(ParameterDirection direction)
{
Direction = direction;
}

public ParakeetAttribute(DbType dbType)
{
DbType = dbType;
}

public ParakeetAttribute(string name, ParameterDirection direction)
{
Name = name;
Direction = direction;
}

public ParakeetAttribute(string name, DbType dbType)
{
Name = name;
DbType = dbType;
}

public ParakeetAttribute(ParameterDirection direction, DbType dbType)
{
Direction = direction;
DbType = dbType;
}

public ParakeetAttribute(string name, ParameterDirection direction, DbType dbType)
{
Name = name;
Direction = direction;
DbType = dbType;
}

public ParakeetAttribute(string name, ParameterDirection direction, DbType dbType, int size)
{
Name = name;
Name = propertyName;
Direction = direction;
DbType = dbType;
Size = size;
}
TableName = tableName;

public ParakeetAttribute(string name, ParameterDirection direction, DbType dbType, int size, byte precision)
{
Name = name;
Direction = direction;
DbType = dbType;
Size = size;
Precision = precision;
if (size > 0) Size = size;
if (precision > 0) Precision = precision;
if (scale > 0) Scale = scale;
}

public ParakeetAttribute(string name, ParameterDirection direction, DbType dbType, int size, byte precision, byte scale)
public ParakeetAttribute(DbType dbType, string propertyName = null, ParameterDirection direction = ParameterDirection.Input, string tableName = null, int size = -1, byte precision = 0, byte scale = 0)
{
Name = name;
Name = propertyName;
Direction = direction;
DbType = dbType;
Size = size;
Precision = precision;
Scale = scale;
}
TableName = tableName;

public ParakeetAttribute(DbType dbType, int size, byte precision, byte scale)
{
DbType = dbType;
Size = size;
Precision = precision;
Scale = scale;
}

public ParakeetAttribute(string name, DbType dbType, int size, byte precision, byte scale)
{
Name = name;
DbType = dbType;
Size = size;
Precision = precision;
Scale = scale;
}

public ParakeetAttribute(ParameterDirection direction, DbType dbType, int size, byte precision, byte scale)
{
Direction = direction;
DbType = dbType;
Size = size;
Precision = precision;
Scale = scale;
if (size > 0) Size = size;
if (precision > 0) Precision = precision;
if (scale > 0) Scale = scale;
}
}
}

0 comments on commit 5ac3e69

Please sign in to comment.