Skip to content

Commit 2183cd2

Browse files
committed
add ClearPropertyVersion Method to IEntityPropertyChangedTrackProxy
1 parent e904e5e commit 2183cd2

File tree

8 files changed

+53
-29
lines changed

8 files changed

+53
-29
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>4</VersionMajor>
44
<VersionMinor>0</VersionMinor>
5-
<VersionPatch>84</VersionPatch>
5+
<VersionPatch>85</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

src/SmartSql.DIExtension/SmartSql.DIExtension.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
9-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
8+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.0" />
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

src/SmartSql.Test/Entities/EntityProxy.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class EntityProxy : Entity, IEntityPropertyChangedTrackProxy
99

1010
public EntityProxy(bool enablePropertyChangedTrack)
1111
{
12+
_enablePropertyChangedTrack = enablePropertyChangedTrack;
1213
_changedVersion = new Dictionary<string, int>(2);
1314
}
1415

@@ -51,6 +52,11 @@ public int GetPropertyVersion(string propName)
5152
return _changedVersion.TryGetValue(propName, out var count) ? count : 0;
5253
}
5354

55+
public void ClearPropertyVersion()
56+
{
57+
_changedVersion.Clear();
58+
}
59+
5460

5561
public override long Id
5662
{

src/SmartSql/Reflection/EntityProxy/EntityProxyFactory.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public Type CreateProxyType(Type entityType)
5151

5252
BuildGetEnableTrackMethod(typeBuilder, enableTrackField);
5353
BuildSetEnableTrackMethod(typeBuilder, enableTrackField);
54-
55-
var onUpdatedMethodInfo = BuildOnUpdatedMethod(typeBuilder, enableTrackField, changedVersionField);
54+
BuildClearPropertyVersionMethod(typeBuilder, changedVersionField);
55+
var onPropertyChangedMethodInfo = BuildOnPropertyChangedMethod(typeBuilder, enableTrackField, changedVersionField);
5656
BuildGetPropertyVersionMethod(typeBuilder, enableTrackField, changedVersionField);
5757

5858
foreach (var propertyInfo in virtualProperties)
5959
{
60-
BuildSetMethod(typeBuilder, propertyInfo, onUpdatedMethodInfo);
60+
BuildSetMethod(typeBuilder, propertyInfo, onPropertyChangedMethodInfo);
6161
}
6262

6363
return typeBuilder.CreateTypeInfo();
@@ -93,7 +93,23 @@ private MethodBuilder BuildGetEnableTrackMethod(TypeBuilder typeBuilder, FieldBu
9393
ilGen.Return();
9494
return getEnableTrackMethodBuilder;
9595
}
96-
96+
97+
private MethodBuilder BuildClearPropertyVersionMethod(TypeBuilder typeBuilder, FieldBuilder changedVersionField)
98+
{
99+
var clearPropertyVersionBuilder = typeBuilder.DefineMethod(
100+
nameof(IEntityPropertyChangedTrackProxy.ClearPropertyVersion),
101+
MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.HideBySig |
102+
MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.SpecialName,
103+
CommonType.Void,
104+
Type.EmptyTypes);
105+
var ilGen = clearPropertyVersionBuilder.GetILGenerator();
106+
ilGen.LoadArg(0);
107+
ilGen.FieldGet(changedVersionField);
108+
ilGen.Call(DictionaryStringIntType.Method.Clear);
109+
ilGen.Return();
110+
return clearPropertyVersionBuilder;
111+
}
112+
97113
private void BuildCtor(TypeBuilder typeBuilder, Type entityType, FieldBuilder changedVersionField,
98114
int propertyCount)
99115
{
@@ -125,7 +141,7 @@ private void BuildCtor(TypeBuilder typeBuilder, Type entityType, FieldBuilder ch
125141
}
126142
}
127143

128-
private void BuildSetMethod(TypeBuilder typeBuilder, PropertyInfo propertyInfo, MethodInfo onUpdatedMethodInfo)
144+
private void BuildSetMethod(TypeBuilder typeBuilder, PropertyInfo propertyInfo, MethodInfo onPropertyChangedMethodInfo)
129145
{
130146
var setMethod = propertyInfo.SetMethod;
131147
var paramTypes = setMethod.GetParameters().Select(p => p.ParameterType).ToArray();
@@ -139,7 +155,7 @@ private void BuildSetMethod(TypeBuilder typeBuilder, PropertyInfo propertyInfo,
139155

140156
ilGen.LoadArg(0);
141157
ilGen.LoadString(propertyInfo.Name);
142-
ilGen.Call(onUpdatedMethodInfo);
158+
ilGen.Call(onPropertyChangedMethodInfo);
143159
ilGen.Return();
144160
}
145161

@@ -155,7 +171,7 @@ private void BuildGetMethod(TypeBuilder typeBuilder, PropertyInfo propertyInfo)
155171
ilGen.Return();
156172
}
157173

158-
private MethodInfo BuildOnUpdatedMethod(TypeBuilder typeBuilder, FieldBuilder enableTrackField,
174+
private MethodInfo BuildOnPropertyChangedMethod(TypeBuilder typeBuilder, FieldBuilder enableTrackField,
159175
FieldBuilder changedVersionField)
160176
{
161177
var onUpdatedBuilder = typeBuilder.DefineMethod(nameof(IEntityPropertyChangedTrackProxy.OnPropertyChanged),

src/SmartSql/Reflection/EntityProxy/IEntityPropertyChangedTrackProxy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface IEntityPropertyChangedTrackProxy
99
void SetEnablePropertyChangedTrack(bool enablePropertyChangedTrack);
1010
void OnPropertyChanged(string propName);
1111
int GetPropertyVersion(string propName);
12+
void ClearPropertyVersion();
1213
}
1314
}

src/SmartSql/Reflection/TypeConstants/DictionaryStringIntType.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ public static class DictionaryStringIntType
1010

1111
public static class Method
1212
{
13-
public static readonly MethodInfo TryGetValue = Type.GetMethod("TryGetValue");
14-
13+
public static readonly MethodInfo TryGetValue = Type.GetMethod(nameof(Dictionary<String, int>.TryGetValue));
14+
1515
public static readonly MethodInfo IndexerSet = Type.GetMethod("set_Item");
16-
public static readonly MethodInfo Add = Type.GetMethod("Add");
16+
public static readonly MethodInfo Add = Type.GetMethod(nameof(Dictionary<String, int>.Add));
17+
public static readonly MethodInfo Clear = Type.GetMethod(nameof(Dictionary<String, int>.Clear));
1718
}
18-
19+
1920
public static class Ctor
2021
{
21-
public static readonly ConstructorInfo Capacity = Type.GetConstructor(new Type[] { CommonType.Int32 });
22+
public static readonly ConstructorInfo Capacity = Type.GetConstructor(new Type[] {CommonType.Int32});
2223
}
2324
}
2425
}

src/SmartSql/Reflection/TypeConstants/IDataReaderDeserializerType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public static class IDataReaderDeserializerType
1111
public static readonly Type Type = typeof(IDataReaderDeserializer);
1212
public static class Method
1313
{
14-
public static readonly MethodInfo ToSinge = Type.GetMethod("ToSinge");
15-
public static readonly MethodInfo ToList = Type.GetMethod("ToList");
14+
public static readonly MethodInfo ToSinge = Type.GetMethod(nameof(IDataReaderDeserializer.ToSinge));
15+
public static readonly MethodInfo ToList = Type.GetMethod(nameof(IDataReaderDeserializer.ToList));
1616
public static MethodInfo MakeGenericToSinge(Type resultType)
1717
{
1818
return ToSinge.MakeGenericMethod(resultType);

src/SmartSql/Reflection/TypeConstants/ISqlMapperType.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ public static class ISqlMapperType
1010
public static readonly Type Type = typeof(ISqlMapper);
1111
public static class Method
1212
{
13-
public static readonly MethodInfo Execute = Type.GetMethod("Execute");
14-
public static readonly MethodInfo ExecuteScalar = Type.GetMethod("ExecuteScalar");
15-
public static readonly MethodInfo Query = Type.GetMethod("Query");
16-
public static readonly MethodInfo QuerySingle = Type.GetMethod("QuerySingle");
17-
public static readonly MethodInfo GetDataSet = Type.GetMethod("GetDataSet");
18-
public static readonly MethodInfo GetDataTable = Type.GetMethod("GetDataTable");
13+
public static readonly MethodInfo Execute = Type.GetMethod(nameof(ISqlMapper.Execute));
14+
public static readonly MethodInfo ExecuteScalar = Type.GetMethod(nameof(ISqlMapper.ExecuteScalar));
15+
public static readonly MethodInfo Query = Type.GetMethod(nameof(ISqlMapper.Query));
16+
public static readonly MethodInfo QuerySingle = Type.GetMethod(nameof(ISqlMapper.QuerySingle));
17+
public static readonly MethodInfo GetDataSet = Type.GetMethod(nameof(ISqlMapper.GetDataSet));
18+
public static readonly MethodInfo GetDataTable = Type.GetMethod(nameof(ISqlMapper.GetDataTable));
1919

20-
public static readonly MethodInfo ExecuteAsync = Type.GetMethod("ExecuteAsync");
21-
public static readonly MethodInfo ExecuteScalarAsync = Type.GetMethod("ExecuteScalarAsync");
22-
public static readonly MethodInfo QueryAsync = Type.GetMethod("QueryAsync");
23-
public static readonly MethodInfo QuerySingleAsync = Type.GetMethod("QuerySingleAsync");
24-
public static readonly MethodInfo GetDataSetAsync = Type.GetMethod("GetDataSetAsync");
25-
public static readonly MethodInfo GetDataTableAsync = Type.GetMethod("GetDataTableAsync");
20+
public static readonly MethodInfo ExecuteAsync = Type.GetMethod(nameof(ISqlMapper.ExecuteAsync));
21+
public static readonly MethodInfo ExecuteScalarAsync = Type.GetMethod(nameof(ISqlMapper.ExecuteScalarAsync));
22+
public static readonly MethodInfo QueryAsync = Type.GetMethod(nameof(ISqlMapper.QueryAsync));
23+
public static readonly MethodInfo QuerySingleAsync = Type.GetMethod(nameof(ISqlMapper.QuerySingleAsync));
24+
public static readonly MethodInfo GetDataSetAsync = Type.GetMethod(nameof(ISqlMapper.GetDataSetAsync));
25+
public static readonly MethodInfo GetDataTableAsync = Type.GetMethod(nameof(ISqlMapper.GetDataTableAsync));
2626
}
2727
}
2828
}

0 commit comments

Comments
 (0)