Skip to content

Commit

Permalink
Merge pull request #322 from Senparc/Develop
Browse files Browse the repository at this point in the history
v3.1.2 add ValidationHelper.CheckNull
  • Loading branch information
JeffreySu authored Jan 28, 2025
2 parents 2c4676d + 4959b3d commit cbb46c3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 13 deletions.
76 changes: 76 additions & 0 deletions src/Senparc.CO2NET/Helpers/Validations/ValidationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2025 Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/Senparc/Senparc.CO2NET/blob/master/LICENSE
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2025 Senparc
FileName:ValidationHelper.cs
File Function Description:Validation Helper
Creation Identifier:Senparc - 20250128
----------------------------------------------------------------*/


using Senparc.CO2NET.Exceptions;
using Senparc.CO2NET.Trace;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Senparc.CO2NET.Helpers.Validations
{
/// <summary>
/// 验证帮助类
/// </summary>
public static class ValidationHelper
{
/// <summary>
/// 检查对象是否为 null,如果是 null,则抛出异常并包含调用者信息。
/// </summary>
/// <param name="obj">要检查的对象</param>
/// <param name="memberName">调用者的成员名称(自动填充)</param>
/// <param name="filePath">调用者的文件路径(自动填充)</param>
/// <param name="lineNumber">调用者的行号(自动填充)</param>
/// <param name="throwException">是否抛出异常</param>
/// <exception cref="ArgumentNullException">当对象为 null 时抛出</exception>
public static void CheckNull(this object obj,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0, bool throwException = false)
{
if (obj == null)
{
var msg = $"Parameter '{nameof(obj)}' is null. " +
$"Called from '{memberName}' in '{filePath}' at line {lineNumber}.";
var ex = new SenparcNullReferenceException(msg);
SenparcTrace.BaseExceptionLog(ex);
if (throwException)
{
throw ex;
}
}
}
}
}
27 changes: 14 additions & 13 deletions src/Senparc.CO2NET/Senparc.CO2NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>3.1.1</Version>
<Version>3.1.2</Version>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.CO2NET</AssemblyName>
<RootNamespace>Senparc.CO2NET</RootNamespace>
Expand Down Expand Up @@ -134,18 +134,19 @@
v2.3.0 Adapt to .NET 8.0
v2.3.1 Add app.UseSenparcGlobal extension method
v2.4.0 Add SenparcDI.GetService&lt;T&gt;(), SenparcDI.GetRequiredService&lt;T&gt;(), SenparcDI.GetRequreidKeyedService() methods
v2.4.1 Add refresh parameter to SenparcDI.GetServiceProvider() method
v2.4.2 Add ReflectionHelper.HasParameterlessConstructor() method
v2.4.3 Update DateTimeHelper.GetDateTimeOffsetFromXml() method
[2024-08-23] v2.5.0 Create dependency injection registration for IBaseObjectCacheStrategy
[2024-08-23] v2.5.1 Update DateTimeHelper.GetDateTimeOffsetFromXml() method #297 Thanks @zhaoyangguang
[2024-09-11] v2.5.2 Update Cache, remove InsertToCache(), add Count(prefix)
[2024-10-24] v3.0.0-beta1 Upgrade to English version
[2024-10-24] v3.0.0-beta3 Add ApiClient and ApiClientHelper
[2024-11-28] v3.0.1-beta3 Add UseLowerCaseApiName property for SenparcSetting
[2024-12-04] v3.1.0-beta3 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run
[2025-01-05] v3.1.1 update Encoding.UTF-8 for SenparcTrace log store
</PackageReleaseNotes>
v2.4.1 Add refresh parameter to SenparcDI.GetServiceProvider() method
v2.4.2 Add ReflectionHelper.HasParameterlessConstructor() method
v2.4.3 Update DateTimeHelper.GetDateTimeOffsetFromXml() method
[2024-08-23] v2.5.0 Create dependency injection registration for IBaseObjectCacheStrategy
[2024-08-23] v2.5.1 Update DateTimeHelper.GetDateTimeOffsetFromXml() method #297 Thanks @zhaoyangguang
[2024-09-11] v2.5.2 Update Cache, remove InsertToCache(), add Count(prefix)
[2024-10-24] v3.0.0-beta1 Upgrade to English version
[2024-10-24] v3.0.0-beta3 Add ApiClient and ApiClientHelper
[2024-11-28] v3.0.1-beta3 Add UseLowerCaseApiName property for SenparcSetting
[2024-12-04] v3.1.0-beta3 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run
[2025-01-05] v3.1.1 update Encoding.UTF-8 for SenparcTrace log store
[2025-01-28] v3.1.2 add ValidationHelper.CheckNull
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/Senparc/Senparc.CO2NET</RepositoryUrl>
<Configurations>Debug;Release;Test</Configurations>
</PropertyGroup>
Expand Down

0 comments on commit cbb46c3

Please sign in to comment.