Skip to content

Commit

Permalink
SetProperty方法支持Null 值
Browse files Browse the repository at this point in the history
  • Loading branch information
ldqk committed Mar 4, 2023
1 parent 0b6dcae commit 7533bb1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 17 deletions.
9 changes: 7 additions & 2 deletions Masuit.Tools.Abstractions/Masuit.Tools.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5;net6;net7</TargetFrameworks>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>2.5.9.2</Version>
<Version>2.5.9.3</Version>
<Authors>懒得勤快</Authors>
<Description>Masuit.Tools基础公共库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。</Description>
<Copyright>懒得勤快,长空X</Copyright>
Expand Down Expand Up @@ -48,7 +48,6 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
Expand All @@ -60,26 +59,31 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5'">
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6'">
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7'">
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
Expand All @@ -89,6 +93,7 @@
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
<PackageReference Include="System.ValueTuple" version="4.5.0" targetFramework="net461" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions Masuit.Tools.Abstractions/Models/Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Masuit.Tools.Models
{
#pragma warning disable 1591

public class Email : Disposable
{
/// <summary>
Expand Down Expand Up @@ -62,7 +63,8 @@ private MailMessage GetClient()
{
if (string.IsNullOrEmpty(Tos)) return null;
var mailMessage = new MailMessage();
//多个接收者

//多个接收者
foreach (var str in Tos.Split(','))
{
mailMessage.To.Add(str);
Expand All @@ -75,7 +77,7 @@ private MailMessage GetClient()
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Priority = MailPriority.High;
foreach (var item in Attachments)
foreach (var item in Attachments.AsNotNull())
{
mailMessage.Attachments.Add(item);
}
Expand Down Expand Up @@ -104,6 +106,7 @@ private MailMessage GetClient()
public void SendAsync(Action<string> completedCallback)
{
if (MailMessage == null) return;

//发送邮件回调方法
_actionSendCompletedCallback = completedCallback;
SmtpClient.SendCompleted += SendCompletedCallback;
Expand Down Expand Up @@ -160,5 +163,6 @@ public override void Dispose(bool disposing)
Attachments.ForEach(a => a.Dispose());
}
}

#pragma warning restore 1591
}
}
6 changes: 3 additions & 3 deletions Masuit.Tools.Abstractions/Reflection/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public static string SetProperty<T>(this T obj, string name, object value) where
var parameter = Expression.Parameter(typeof(T), "e");
var property = Expression.PropertyOrField(parameter, name);
var before = Expression.Lambda(property, parameter).Compile().DynamicInvoke(obj);
if (value.Equals(before))
if (value == before)
{
return value.ToString();
return value?.ToString();
}

if (property.Type.IsGenericType && property.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
Expand All @@ -101,7 +101,7 @@ public static string SetProperty<T>(this T obj, string name, object value) where
}
else
{
var valueExpression = Expression.Parameter(value.GetType(), "v");
var valueExpression = Expression.Parameter(property.Type, "v");
var assign = Expression.Assign(property, valueExpression);
Expression.Lambda(assign, parameter, valueExpression).Compile().DynamicInvoke(obj, value);
}
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools.AspNetCore/Masuit.Tools.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Product>Masuit.Tools.AspNetCore</Product>
<PackageId>Masuit.Tools.AspNetCore</PackageId>
<LangVersion>latest</LangVersion>
<Version>1.1.9.2</Version>
<Version>1.1.9.3</Version>
<RepositoryType></RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<FileVersion>1.1.9</FileVersion>
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools.Core/Masuit.Tools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
官网教程:https://ldqk.org/55
github:https://github.com/ldqk/Masuit.Tools
</Description>
<Version>2.5.9.2</Version>
<Version>2.5.9.3</Version>
<Copyright>Copyright © 懒得勤快</Copyright>
<PackageProjectUrl>https://github.com/ldqk/Masuit.Tools</PackageProjectUrl>
<PackageTags>Masuit.Tools,工具库,Utility,Crypt,Extensions</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools.Net45/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>Masuit.Tools.Net45</id>
<version>2.5.9.2</version>
<version>2.5.9.3</version>
<title>Masuit.Tools</title>
<authors>懒得勤快</authors>
<owners>masuit.com</owners>
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools/Masuit.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<Version>1.0.0-beta14</Version>
</PackageReference>
<PackageReference Include="StackExchange.Redis">
<Version>2.6.90</Version>
<Version>2.6.96</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>Masuit.Tools.Net</id>
<version>2.5.9.2</version>
<version>2.5.9.3</version>
<title>Masuit.Tools</title>
<authors>懒得勤快</authors>
<owners>masuit.com</owners>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 3 additions & 3 deletions Test/Masuit.Tools.Core.Test/Masuit.Tools.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 7533bb1

Please sign in to comment.