Skip to content

Commit

Permalink
v2.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Apr 13, 2023
1 parent 0eca3d2 commit 6bef8e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/YANLib/YANLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Title>YANLib</Title>
<Authors>Yami An</Authors>
<Company>YAN</Company>
<Description>Warning: test beta optimize</Description>
<Description>Warning: test alpha optimize</Description>
<Copyright>Copyright © 2023</Copyright>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/Tynab</PackageProjectUrl>
Expand All @@ -22,7 +22,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageId>Tynab.YANLib</PackageId>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 8 additions & 17 deletions lib/YANLib/YANModel.Property.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using static System.Activator;
using System.Reflection;
using static System.Activator;
using static System.Reflection.BindingFlags;

namespace YANLib;

Expand Down Expand Up @@ -130,22 +132,11 @@ public static IEnumerable<bool> AllPropertiesNotDefault<T>(this IReadOnlySet<T>
/// <typeparam name="T">The type of the object to check.</typeparam>
/// <param name="mdl">The object to check.</param>
/// <returns><see langword="true"/> if all properties of the specified object have default values; otherwise, <see langword="false"/>.</returns>
public static bool AllPropertiesDefault<T>(this T mdl) where T : class
public static bool AllPropertiesDefault<T>(this T mdl) where T : class => !mdl.GetType().GetProperties(Public | Instance | DeclaredOnly).Any(prop =>
{
if (mdl is null)
{
return false;
}
foreach (var prop in typeof(T).GetProperties())
{
var type = prop.PropertyType;
if (!EqualityComparer<object>.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default(T)))
{
return false;
}
}
return true;
}
var type = prop.PropertyType;
return !EqualityComparer<object>.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default);
});

/// <summary>
/// Checks whether all properties of the specified objects have default values, including all their nested properties and properties in lists.
Expand Down Expand Up @@ -249,7 +240,7 @@ public static IEnumerable<bool> AllPropertiesDefault<T>(this IReadOnlySet<T> mdl
/// <typeparam name="T">The type of the object to check.</typeparam>
/// <param name="mdl">The object to check.</param>
/// <returns><see langword="true"/> if any property of the specified object has a value other than the default value; otherwise, <see langword="false"/>.</returns>
public static bool AnyPropertiesNotDefault<T>(this T mdl) where T : class => mdl.GetType().GetProperties().Any(prop =>
public static bool AnyPropertiesNotDefault<T>(this T mdl) where T : class => mdl.GetType().GetProperties(Public | Instance | DeclaredOnly).Any(prop =>
{
var type = prop.PropertyType;
return !EqualityComparer<object>.Default.Equals(prop.GetValue(mdl), type.IsValueType ? CreateInstance(type) : default);
Expand Down
2 changes: 1 addition & 1 deletion lib/YANLib/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packageSourceCredentials>
<github>
<add key="Username" value="Tynab" />
<add key="ClearTextPassword" value="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" />
<add key="ClearTextPassword" value="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" />
</github>
</packageSourceCredentials>
<repository url="https://github.com/Tynab/YANLib" />
Expand Down

0 comments on commit 6bef8e4

Please sign in to comment.