Skip to content

Commit

Permalink
1. add ParamAttribute.FieldType
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Mar 29, 2019
1 parent 68e8dec commit f686227
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/SmartSql.DyRepository/Annotations/ParamAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public ParamAttribute(string name)
/// DbDataParameter.Name
/// </summary>
public String Name { get; set; }
public Type FieldType { get; set; }
}
}
3 changes: 1 addition & 2 deletions src/SmartSql.DyRepository/EmitRepositoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ private void BuildMethod(Type interfaceType, TypeBuilder typeBuilder, MethodInfo
ilGen.LoadType(reqParam.ParameterType);
ilGen.New(SqlParameterType.Ctor.SqlParameter);
ilGen.Dup();
var column = reqParam.GetCustomAttribute<ColumnAttribute>();
var getHandlerMethod = column?.FieldType != null ? TypeHandlerCacheType.GetHandlerMethod(reqParam.ParameterType, column?.FieldType)
var getHandlerMethod = paramAttr?.FieldType != null ? TypeHandlerCacheType.GetHandlerMethod(reqParam.ParameterType, paramAttr?.FieldType)
: PropertyTypeHandlerCacheType.GetHandlerMethod(reqParam.ParameterType);
ilGen.Call(getHandlerMethod);
ilGen.Call(SqlParameterType.Method.SetTypeHandler);
Expand Down
9 changes: 5 additions & 4 deletions src/SmartSql.Test.Unit/DI/DITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using SmartSql.DataSource;
using SmartSql.DbSession;
using SmartSql.Test.Repositories;
using SmartSql.Test.Unit.DyRepository;
using Xunit;

Expand Down Expand Up @@ -57,10 +58,10 @@ public void AddRepositoryFromAssembly()
services.AddSmartSql()
.AddRepositoryFromAssembly(o =>
{
o.AssemblyString = "SmartSql.Test.Unit";
o.AssemblyString = "SmartSql.Test";
o.Filter = (type) =>
{
return type.Namespace == "SmartSql.Test.Unit.DyRepository";
return type.Namespace == "SmartSql.Test.Repositories";
};
});
var serviceProvider = services.BuildServiceProvider();
Expand All @@ -75,10 +76,10 @@ public void AddRepositoryFromAssembly_Alias()
.AddRepositoryFromAssembly(o =>
{
o.SmartSqlAlias = "AddRepositoryFromAssembly_Alias";
o.AssemblyString = "SmartSql.Test.Unit";
o.AssemblyString = "SmartSql.Test";
o.Filter = (type) =>
{
return type.Namespace == "SmartSql.Test.Unit.DyRepository";
return type.Namespace == "SmartSql.Test.Repositories";
};
});
var serviceProvider = services.BuildServiceProvider();
Expand Down
19 changes: 19 additions & 0 deletions src/SmartSql.Test.Unit/DyRepository/AllPrimitiveRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using SmartSql.Test.Repositories;
using Xunit;

namespace SmartSql.Test.Unit.DyRepository
{
public class AllPrimitiveRepositoryTest : DyRepositoryTest
{
[Fact]
public void Build()
{
var smartSqlBuilder = new SmartSqlBuilder().UseXmlConfig().Build();
var repositoryType = RepositoryBuilder.Build(typeof(IAllPrimitiveRepository), smartSqlBuilder.SmartSqlConfig);
Assert.NotNull(repositoryType);
}
}
}
18 changes: 18 additions & 0 deletions src/SmartSql.Test.Unit/DyRepository/DyRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using SmartSql.DyRepository;

namespace SmartSql.Test.Unit.DyRepository
{
public class DyRepositoryTest
{
protected IRepositoryBuilder RepositoryBuilder { get; set; }
protected IRepositoryFactory RepositoryFactory { get; set; }
public DyRepositoryTest()
{
RepositoryBuilder = new EmitRepositoryBuilder(null, null, Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance);
RepositoryFactory = new RepositoryFactory(RepositoryBuilder, Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance);
}
}
}
14 changes: 0 additions & 14 deletions src/SmartSql.Test.Unit/DyRepository/IAllPrimitiveRepository.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using SmartSql.Test.Repositories;
using Xunit;

namespace SmartSql.Test.Unit.DyRepository
Expand Down Expand Up @@ -35,7 +36,6 @@ public void CreateInstance()

}


[Fact]
public void NoMapperRepository_GetGuidFromDb()
{
Expand Down
1 change: 1 addition & 0 deletions src/SmartSql.Test/Repositories/IAllPrimitiveRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IAllPrimitiveRepository
{
[Statement(Sql = "SELECT Top (@Taken) T.* From T_AllPrimitive T With(NoLock)")]
IEnumerable<AllPrimitive> Query([Param("Taken")]int taken);
long Insert(AllPrimitive entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Text;

namespace SmartSql.Test.Unit.DyRepository
namespace SmartSql.Test.Repositories
{
public interface INoMapperRepository
{
Expand Down

0 comments on commit f686227

Please sign in to comment.