Skip to content

Commit abb1900

Browse files
authored
Merge pull request #12 from I-RzR-I/feature/AddImprovements
Feature/add improvements
2 parents abafa2a + dfe4262 commit abb1900

12 files changed

+107
-80
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-2024 RzR
3+
Copyright (c) 2022-2025 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

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@
3131
-> Add own implementation `EntityPropChangeEventBase` for `INotifyPropertyChanged` .<br />
3232

3333
### **1.0.10.3531**
34-
-> Add methods to set content `SetContent` with internal property changed event.<br />
34+
-> Add methods to set content `SetContent` with internal property changed event;<br />
35+
36+
### **1.1.0.0**
37+
-> Add small adjustments and fixes;<br />
38+
-> Small core reorganization;<br />
39+
-> Parameters rename;<br />
40+
-> Update the packages reference version;<br />

src/EntityMaxLengthTrim/EntityMaxLengthTrim.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
5252
<PackageReference Include="CodeSource">
53-
<Version>1.0.6.933</Version>
53+
<Version>2.0.0.0</Version>
5454
</PackageReference>
5555
<PackageReference Include="System.ComponentModel.Annotations">
5656
<Version>5.0</Version>
@@ -59,7 +59,7 @@
5959

6060
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.5'">
6161
<PackageReference Include="CodeSource">
62-
<Version>1.0.6.933</Version>
62+
<Version>2.0.0.0</Version>
6363
</PackageReference>
6464
<PackageReference Include="System.ComponentModel.Annotations">
6565
<Version>5.0</Version>
@@ -74,7 +74,7 @@
7474

7575
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
7676
<PackageReference Include="CodeSource">
77-
<Version>1.0.6.933</Version>
77+
<Version>2.0.0.0</Version>
7878
</PackageReference>
7979
<PackageReference Include="System.ComponentModel.Annotations">
8080
<Version>5.0</Version>
@@ -83,7 +83,7 @@
8383

8484
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
8585
<PackageReference Include="CodeSource">
86-
<Version>1.0.6.933</Version>
86+
<Version>2.0.0.0</Version>
8787
</PackageReference>
8888
<PackageReference Include="System.ComponentModel.Annotations">
8989
<Version>5.0</Version>

src/EntityMaxLengthTrim/EntityPropChangeEventBase.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace EntityMaxLengthTrim
2929
/// <remarks></remarks>
3030
/// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
3131
/// =================================================================================================
32-
public class EntityPropChangeEventBase : INotifyPropertyChanged
32+
public abstract class EntityPropChangeEventBase : INotifyPropertyChanged
3333
{
3434
/// <summary>
3535
/// Property changed event handler
@@ -41,7 +41,9 @@ public class EntityPropChangeEventBase : INotifyPropertyChanged
4141
/// </summary>
4242
/// <param name="callingEntity">Calling entity</param>
4343
/// <param name="propertyName">Changed property name</param>
44-
protected virtual void OnPropertyChanged<T>(T callingEntity, string propertyName)
44+
/// <typeparam name="TEntity">Calling entity type</typeparam>
45+
protected virtual void OnPropertyChanged<TEntity>(TEntity callingEntity, string propertyName)
46+
where TEntity : class
4547
{
4648
StringInterceptor.ApplyStringMaxAllowedLength(callingEntity, propertyName, false);
4749
PropertyChanged?.Invoke(callingEntity, new PropertyChangedEventArgs(propertyName));
@@ -54,10 +56,11 @@ protected virtual void OnPropertyChanged<T>(T callingEntity, string propertyName
5456
/// <param name="propertyName">Changed property name</param>
5557
/// <param name="getValue">Get property value</param>
5658
/// <param name="setValue">Set property value</param>
57-
/// <typeparam name="T">Calling entity type</typeparam>
59+
/// <typeparam name="TEntity">Calling entity type</typeparam>
5860
/// <returns></returns>
59-
protected virtual void SetContent<T>(T callingEntity, string propertyName, ref string getValue,
61+
protected virtual void SetContent<TEntity>(TEntity callingEntity, string propertyName, ref string getValue,
6062
ref string setValue)
63+
where TEntity : class
6164
{
6265
if (getValue == setValue) return;
6366

@@ -74,10 +77,11 @@ protected virtual void SetContent<T>(T callingEntity, string propertyName, ref s
7477
/// <param name="getValue">Get property value</param>
7578
/// <param name="setValue">Set property value</param>
7679
/// <param name="length">Property maximum allowed length.</param>
77-
/// <typeparam name="T">Calling entity type</typeparam>
80+
/// <typeparam name="TEntity">Calling entity type</typeparam>
7881
/// <returns></returns>
79-
protected virtual void SetContent<T>(T callingEntity, string propertyName, ref string getValue,
82+
protected virtual void SetContent<TEntity>(TEntity callingEntity, string propertyName, ref string getValue,
8083
ref string setValue, int length)
84+
where TEntity : class
8185
{
8286
if (getValue == setValue) return;
8387

src/EntityMaxLengthTrim/Extensions/FluentExtensions.cs

+15-16
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public static class FluentExtensions
4040
/// <returns></returns>
4141
/// <typeparam name="TEntity">Type of initialized object.</typeparam>
4242
/// <remarks></remarks>
43-
public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject, bool useDotOnEnd = false)
43+
public static TEntity ToSafeStoreStrings<TEntity>(
44+
this TEntity initSourceObject,
45+
bool useDotOnEnd = false)
4446
where TEntity : class
45-
{
46-
return StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, useDotOnEnd);
47-
}
48-
47+
=> StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, useDotOnEnd);
48+
4949
/// <summary>
5050
/// Prepare initialized object to save store string properties.
5151
/// </summary>
@@ -61,13 +61,12 @@ public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject,
6161
/// <returns></returns>
6262
/// <typeparam name="TEntity">Type of initialized object.</typeparam>
6363
/// <remarks></remarks>
64-
public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject,
64+
public static TEntity ToSafeStoreStrings<TEntity>(
65+
this TEntity initSourceObject,
6566
IReadOnlyCollection<string> truncateWithDots,
66-
bool processOnlyAssigned = false) where TEntity : class
67-
{
68-
return StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, truncateWithDots,
69-
processOnlyAssigned);
70-
}
67+
bool processOnlyAssigned = false)
68+
where TEntity : class
69+
=> StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, truncateWithDots, processOnlyAssigned);
7170

7271
/// <summary>
7372
/// Prepare initialized object to save store string properties.
@@ -81,11 +80,11 @@ public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject,
8180
/// <returns></returns>
8281
/// <typeparam name="TEntity">Type of initialized object.</typeparam>
8382
/// <remarks></remarks>
84-
public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject,
83+
public static TEntity ToSafeStoreStrings<TEntity>(
84+
this TEntity initSourceObject,
8585
IReadOnlyCollection<PropertyOption> options,
86-
bool processOnlyAssigned = false) where TEntity : class
87-
{
88-
return StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, options, processOnlyAssigned);
89-
}
86+
bool processOnlyAssigned = false)
87+
where TEntity : class
88+
=> StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, options, processOnlyAssigned);
9089
}
9190
}

src/EntityMaxLengthTrim/Extensions/IntExtensions.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,14 @@ internal static class IntExtensions
3333
/// <param name="source">Source object to be checked</param>
3434
/// <returns>Return bool value (validation result).</returns>
3535
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
36-
internal static bool IsNullOrZero(this int source)
37-
{
38-
return source.IsNull() || source == 0;
39-
}
36+
internal static bool IsNullOrZero(this int source) => source.IsNull() || source == 0;
4037

4138
/// <summary>
4239
/// Check if source object is less or equals with 0
4340
/// </summary>
4441
/// <param name="source">Source object to be checked</param>
4542
/// <returns>Return bool value (validation result).</returns>
4643
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
47-
internal static bool IsLessOrEqualWithZero(this int source)
48-
{
49-
return source <= 0;
50-
}
44+
internal static bool IsLessOrEqualWithZero(this int source) => source <= 0;
5145
}
5246
}

src/EntityMaxLengthTrim/Extensions/ObjectExtensions.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,14 @@ internal static class ObjectExtensions
3333
/// <param name="source">Object to be checked</param>
3434
/// <returns>Return bool value (validation result).</returns>
3535
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
36-
internal static bool IsNull(this object source)
37-
{
38-
return source == null;
39-
}
36+
internal static bool IsNull(this object source) => source == null;
4037

4138
/// <summary>
4239
/// Check if the source object is not null
4340
/// </summary>
4441
/// <param name="source">Object to be checked</param>
4542
/// <returns>Return bool value (validation result).</returns>
4643
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
47-
internal static bool IsNotNull(this object source)
48-
{
49-
return !source.IsNull();
50-
}
44+
internal static bool IsNotNull(this object source) => !source.IsNull();
5145
}
5246
}

src/EntityMaxLengthTrim/Extensions/StringExtensions.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,33 @@ namespace EntityMaxLengthTrim.Extensions
2828
/// <remarks>Extension for string data type, which allows more efficient use and implement code</remarks>
2929
internal static class StringExtensions
3030
{
31+
/// <summary>
32+
/// Check if the source string value is present
33+
/// </summary>
34+
/// <param name="source">Source string to be checked</param>
35+
/// <returns>Verification value, if is present > true, otherwise false</returns>
36+
internal static bool IsPresent(this string source)
37+
=> !string.IsNullOrEmpty(source) && !string.IsNullOrWhiteSpace(source);
38+
3139
/// <summary>
3240
/// Truncates the string to a specified length and replace the truncated to a ...
3341
/// </summary>
3442
/// <param name="text">string that will be truncated</param>
3543
/// <param name="maxLength">total length of characters to maintain before the truncate happens</param>
3644
/// <param name="useDots">Use 3 dots(...) in the end of string</param>
3745
/// <returns>Truncated string</returns>
38-
[CodeSource(
39-
"https://github.com/I-RzR-I/DomainCommonExtensions/blob/main/src/DomainCommonExtensions/DataTypeExtensions/StringExtensions.cs",
40-
"RzR", "RzR", "2022-09-27")]
46+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", "RzR", "2022-09-27")]
4147
internal static string Truncate(this string text, int maxLength, bool useDots = false)
4248
{
49+
if (maxLength.IsLessOrEqualWithZero()) return text;
50+
4351
const string suffix = "...";
4452
var truncatedString = text;
4553

46-
if (maxLength.IsLessOrEqualWithZero()) return truncatedString;
4754
var strLength = maxLength - (useDots.Equals(true) ? suffix.Length : 0);
4855

4956
if (strLength.IsLessOrEqualWithZero()) return truncatedString;
50-
51-
if (text == null || text.Length <= maxLength) return truncatedString;
57+
if (!text.IsPresent() || text.Length <= maxLength) return truncatedString;
5258

5359
truncatedString = text.Substring(0, strLength);
5460
truncatedString = truncatedString.TrimEnd();

src/EntityMaxLengthTrim/Extensions/StringMaxAllowedLengthExtensions.cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ internal static class StringMaxAllowedLengthExtensions
4343
/// <param name="propertyName">Property name</param>
4444
/// <returns>Return property length decorated with DatAnnotation</returns>
4545
/// <remarks>Decoration allowed attributes: MaxLengthAttribute or StringLengthAttribute or MaxAllowedLengthAttribute</remarks>
46-
internal static int? GetMaxAllowedLength<T>(this string propertyName)
46+
internal static int? GetMaxAllowedLength<TEntity>(this string propertyName)
47+
where TEntity : class
4748
{
4849
try
4950
{
50-
var length = propertyName.GetFromMaxLengthAttribute<T>();
51+
var length = propertyName.GetFromMaxLengthAttribute<TEntity>();
5152
if (length.IsNotNull())
5253
return length;
5354

54-
length = propertyName.GetFromStringLengthAttribute<T>();
55+
length = propertyName.GetFromStringLengthAttribute<TEntity>();
5556
if (length.IsNotNull())
5657
return length;
5758

58-
length = propertyName.GetFromMaxAllowedLengthAttribute<T>();
59+
length = propertyName.GetFromMaxAllowedLengthAttribute<TEntity>();
5960
if (length.IsNotNull())
6061
return length;
6162
}
@@ -79,11 +80,12 @@ internal static class StringMaxAllowedLengthExtensions
7980
/// <param name="propertyName">Property name</param>
8081
/// <returns>Return property length decorated with MaxLengthAttribute</returns>
8182
/// <remarks>Return 'null' or '0' length in case of exception or not set property length value</remarks>
82-
private static int? GetFromMaxLengthAttribute<T>(this string propertyName)
83+
private static int? GetFromMaxLengthAttribute<TEntity>(this string propertyName)
84+
where TEntity : class
8385
{
8486
try
8587
{
86-
var length = typeof(T).GetProperty(propertyName)
88+
var length = typeof(TEntity).GetProperty(propertyName)
8789
?.GetCustomAttributes(typeof(MaxLengthAttribute), false).Cast<MaxLengthAttribute>()
8890
.FirstOrDefault();
8991

@@ -98,11 +100,12 @@ internal static class StringMaxAllowedLengthExtensions
98100
/// <param name="propertyName">Property name</param>
99101
/// <returns>Return property length decorated with StringLengthAttribute</returns>
100102
/// <remarks>Return 'null' or '0' length in case of exception or not set property length value</remarks>
101-
private static int? GetFromStringLengthAttribute<T>(this string propertyName)
103+
private static int? GetFromStringLengthAttribute<TEntity>(this string propertyName)
104+
where TEntity : class
102105
{
103106
try
104107
{
105-
var length = typeof(T).GetProperty(propertyName)
108+
var length = typeof(TEntity).GetProperty(propertyName)
106109
?.GetCustomAttributes(typeof(StringLengthAttribute), false).Cast<StringLengthAttribute>()
107110
.FirstOrDefault();
108111

@@ -117,11 +120,12 @@ internal static class StringMaxAllowedLengthExtensions
117120
/// <param name="propertyName">Property name</param>
118121
/// <returns>Return property length decorated with MaxAllowedLengthAttribute</returns>
119122
/// <remarks>Return 'null' or '0' length in case of exception or not set property length value</remarks>
120-
private static int? GetFromMaxAllowedLengthAttribute<T>(this string propertyName)
123+
private static int? GetFromMaxAllowedLengthAttribute<TEntity>(this string propertyName)
124+
where TEntity : class
121125
{
122126
try
123127
{
124-
var length = typeof(T).GetProperty(propertyName)
128+
var length = typeof(TEntity).GetProperty(propertyName)
125129
?.GetCustomAttributes(typeof(MaxAllowedLengthAttribute), false).Cast<MaxAllowedLengthAttribute>()
126130
.FirstOrDefault();
127131

src/EntityMaxLengthTrim/Extensions/TypeExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal static class TypeExtensions
3737
/// </summary>
3838
/// <param name="type">Entity type</param>
3939
/// <returns>Return list of properties(PropertyInfo) from specified 'System.Type'.</returns>
40-
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions/blob/9a580a3604f5d6127e887da837e7954f3e47c9d6/src/DomainCommonExtensions/CommonExtensions/TypeExtensions.cs#L1", "RzR", 1.0)]
40+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
4141
internal static IEnumerable<PropertyInfo> GetPropertyInfos(this Type type)
4242
{
4343
try
@@ -54,7 +54,7 @@ internal static IEnumerable<PropertyInfo> GetPropertyInfos(this Type type)
5454
/// </summary>
5555
/// <param name="type">Entity type</param>
5656
/// <returns>Return list of properties(PropertyInfo, string properties) from specified 'System.Type'</returns>
57-
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions/blob/9a580a3604f5d6127e887da837e7954f3e47c9d6/src/DomainCommonExtensions/CommonExtensions/TypeExtensions.cs#L1", "RzR", 1.0)]
57+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
5858
internal static IEnumerable<PropertyInfo> GetStringPropertyInfos(this Type type)
5959
{
6060
try
@@ -72,7 +72,7 @@ internal static IEnumerable<PropertyInfo> GetStringPropertyInfos(this Type type)
7272
/// </summary>
7373
/// <param name="type">Entity type</param>
7474
/// <returns>Return list of properties (string properties) from specified 'System.Type'</returns>
75-
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions/blob/9a580a3604f5d6127e887da837e7954f3e47c9d6/src/DomainCommonExtensions/CommonExtensions/TypeExtensions.cs#L1", "RzR", 1.0)]
75+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
7676
internal static IEnumerable<string> GetStringPropertyNames(this Type type)
7777
{
7878
try

0 commit comments

Comments
 (0)