Skip to content

Commit abafa2a

Browse files
authored
Merge pull request #11 from I-RzR-I/feature/AddAdjustContentSet
Adjust set content method
2 parents 63ca016 + 477f267 commit abafa2a

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2023 RzR
3+
Copyright (c) 2022-2024 RzR
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@
2828

2929
### **1.0.9.5667**
3030
-> Add internal extension.<br />
31-
-> Add own implementation `EntityPropChangeEventBase` for `INotifyPropertyChanged` .<br />
31+
-> Add own implementation `EntityPropChangeEventBase` for `INotifyPropertyChanged` .<br />
32+
33+
### **1.0.10.3531**
34+
-> Add methods to set content `SetContent` with internal property changed event.<br />

docs/usage.md

+31
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,35 @@ public class Foo : INotifyPropertyChanged
117117
}
118118
```
119119

120+
Add own implementation of `EntityPropChangeEventBase` and methods to set content and activate property changed event.
121+
122+
```csharp
123+
public class Foo : EntityPropChangeEventBase
124+
{
125+
private string _name;
126+
private string _fullName;
127+
private string _description;
128+
129+
[MaxLength(PropertyMaxLengthHelper.NameMaxLength)]
130+
public string Name
131+
{
132+
get => _name;
133+
set => SetContent(this, nameof(Name), ref _name, ref value);
134+
}
135+
136+
[StringLength(PropertyMaxLengthHelper.FullNameMaxLength)]
137+
public string FullName
138+
{
139+
get => _fullName;
140+
set => SetContent(this, nameof(FullName), ref _fullName, ref value);
141+
}
142+
143+
public string Description
144+
{
145+
get => _description;
146+
set => SetContent(this, nameof(Description), ref _description, ref value, PropertyMaxLengthHelper.DescriptionMaxLength);
147+
}
148+
}
149+
```
150+
120151

src/EntityMaxLengthTrim/EntityPropChangeEventBase.cs

+20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#region U S A G E S
1818

1919
using System.ComponentModel;
20+
using EntityMaxLengthTrim.Extensions;
2021
using EntityMaxLengthTrim.Interceptors;
2122

2223
#endregion
@@ -64,5 +65,24 @@ protected virtual void SetContent<T>(T callingEntity, string propertyName, ref s
6465
StringInterceptor.ApplyStringMaxAllowedLength(callingEntity, propertyName, false);
6566
PropertyChanged?.Invoke(callingEntity, new PropertyChangedEventArgs(propertyName));
6667
}
68+
69+
/// <summary>
70+
/// Set content to property
71+
/// </summary>
72+
/// <param name="callingEntity">Calling entity</param>
73+
/// <param name="propertyName">Changed property name</param>
74+
/// <param name="getValue">Get property value</param>
75+
/// <param name="setValue">Set property value</param>
76+
/// <param name="length">Property maximum allowed length.</param>
77+
/// <typeparam name="T">Calling entity type</typeparam>
78+
/// <returns></returns>
79+
protected virtual void SetContent<T>(T callingEntity, string propertyName, ref string getValue,
80+
ref string setValue, int length)
81+
{
82+
if (getValue == setValue) return;
83+
84+
getValue = setValue.Truncate(length);
85+
PropertyChanged?.Invoke(callingEntity, new PropertyChangedEventArgs(propertyName));
86+
}
6787
}
6888
}

src/shared/GeneralAssemblyInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
[assembly: AssemblyCompany("RzR ®")]
3131
[assembly: AssemblyProduct("")]
32-
[assembly: AssemblyCopyright("Copyright © 2022-2023 RzR All rights reserved.")]
32+
[assembly: AssemblyCopyright("Copyright © 2022-2024 RzR All rights reserved.")]
3333
[assembly: AssemblyTrademark("® RzR™")]
3434
[assembly: AssemblyDescription("One important thing about this repository, you have the possibility to avoid database exceptions related to exceeding the limit of the maximum allowed length of the string type columns. To specify the maximum allowed string length you can use data annotation attributes predefined in `System.ComponentModel.DataAnnotations` or a new custom attribute.")]
3535

@@ -44,6 +44,6 @@
4444
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
4545
#endif
4646

47-
[assembly: AssemblyVersion("1.0.9.5667")]
48-
[assembly: AssemblyFileVersion("1.0.9.5667")]
49-
[assembly: AssemblyInformationalVersion("1.0.9.5667")]
47+
[assembly: AssemblyVersion("1.0.10.3531")]
48+
[assembly: AssemblyFileVersion("1.0.10.3531")]
49+
[assembly: AssemblyInformationalVersion("1.0.10.3531")]

src/tests/EntityModelStringTruncateTest/Models/FooModelIntercept2.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ public string FullName
4141
set => SetContent(this, nameof(FullName), ref _fullName, ref value);
4242
}
4343

44-
[MaxAllowedLength(PropertyMaxLengthHelper.DescriptionMaxLength)]
4544
public string Description
4645
{
4746
get => _description;
48-
set => SetContent(this, nameof(Description), ref _description, ref value);
47+
set => SetContent(this, nameof(Description), ref _description, ref value, PropertyMaxLengthHelper.DescriptionMaxLength);
4948
}
5049
}
5150
}

0 commit comments

Comments
 (0)