Skip to content

Commit 59d378e

Browse files
committed
Merge branch 'rjperes-NH-3415'
2 parents 4f7bad4 + 878df55 commit 59d378e

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

src/NHibernate.Test/MappingByCode/ExplicitMappingTests/BasicMappingOfSimpleClass.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
24
using System.Linq;
35
using NHibernate.Cfg.MappingSchema;
46
using NHibernate.Mapping.ByCode;
@@ -32,6 +34,24 @@ public void MapClassWithIdAndProperty()
3234
ModelIsWellFormed(hbmMapping);
3335
}
3436

37+
[Test]
38+
public void MapClassWithIdAndPropertyWithParamsDictionary()
39+
{
40+
var mapper = new ModelMapper();
41+
mapper.Class<MyClass>(ca =>
42+
{
43+
ca.Id(x => x.Id, map =>
44+
{
45+
map.Column("MyClassId");
46+
//NH-3415
47+
map.Generator(Generators.HighLow, gmap => gmap.Params(new Dictionary<string, object> { { "max_low", 100 } }));
48+
});
49+
ca.Property(x => x.Something, map => map.Length(150));
50+
});
51+
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
52+
ModelIsWellFormed(hbmMapping);
53+
}
54+
3555
[Test]
3656
public void WhenMapClassWithoutIdThenApplyTypeOfGeneratorDef()
3757
{

src/NHibernate.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_SPACES</s:String>
3+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">True</s:Boolean>
45
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">True</s:Boolean>
56
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">True</s:Boolean>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
using System.Collections.Generic;
12
namespace NHibernate.Mapping.ByCode
23
{
34
public interface IGeneratorMapper
45
{
56
void Params(object generatorParameters);
7+
8+
void Params(IDictionary<string, object> generatorParameters);
69
}
710
}

src/NHibernate/Mapping/ByCode/Impl/GeneratorMapper.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
1+
using System.Collections.Generic;
12
using System.Linq;
23
using NHibernate.Cfg.MappingSchema;
34

45
namespace NHibernate.Mapping.ByCode.Impl
56
{
67
public class GeneratorMapper : IGeneratorMapper
78
{
8-
private readonly HbmGenerator generator;
9+
private readonly HbmGenerator _generator;
910

1011
public GeneratorMapper(HbmGenerator generator)
1112
{
12-
this.generator = generator;
13+
_generator = generator;
1314
}
1415

1516
#region Implementation of IGeneratorMapper
1617

1718
public void Params(object generatorParameters)
19+
{
20+
var dictionary = generatorParameters.GetType()
21+
.GetProperties()
22+
.ToDictionary(x => x.Name, x => x.GetValue(generatorParameters, null));
23+
Params(dictionary);
24+
}
25+
26+
public void Params(IDictionary<string, object> generatorParameters)
1827
{
1928
if (generatorParameters == null)
2029
{
2130
return;
2231
}
23-
generator.param = (from pi in generatorParameters.GetType().GetProperties()
24-
let pname = pi.Name
25-
let pvalue = pi.GetValue(generatorParameters, null)
26-
select
27-
new HbmParam
28-
{name = pname, Text = new[] {ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString()}}).
29-
ToArray();
32+
33+
_generator.param = (from pi in generatorParameters
34+
let pname = pi.Key
35+
let pvalue = pi.Value
36+
select new HbmParam
37+
{
38+
name = pname,
39+
Text = new[] {ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString()}
40+
}).ToArray();
3041
}
3142

3243
#endregion

0 commit comments

Comments
 (0)