增加string的IsNullOrEmpty和IsNotNullOrEmpty

This commit is contained in:
falcon 2019-12-27 16:07:40 +08:00
parent 520f22b063
commit 50eed23d1c
5 changed files with 115 additions and 0 deletions

31
Faclon.Extend.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faclon.Extend", "Faclon.Extend\Faclon.Extend.csproj", "{F77EDE31-EBB5-42E9-85C3-1501D2B0CA81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faclon.ExtendTests", "Faclon.ExtendTests\Faclon.ExtendTests.csproj", "{3C7A5D31-3FB4-4DDA-8283-5CB81BE63150}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F77EDE31-EBB5-42E9-85C3-1501D2B0CA81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F77EDE31-EBB5-42E9-85C3-1501D2B0CA81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F77EDE31-EBB5-42E9-85C3-1501D2B0CA81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F77EDE31-EBB5-42E9-85C3-1501D2B0CA81}.Release|Any CPU.Build.0 = Release|Any CPU
{3C7A5D31-3FB4-4DDA-8283-5CB81BE63150}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C7A5D31-3FB4-4DDA-8283-5CB81BE63150}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C7A5D31-3FB4-4DDA-8283-5CB81BE63150}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C7A5D31-3FB4-4DDA-8283-5CB81BE63150}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FF964C7D-2826-4608-A52B-06BB952F1DC8}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0</Version>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<PackageProjectUrl>http://39.105.71.191/Falcon/Falcon.Extend</PackageProjectUrl>
<RepositoryUrl>http://39.105.71.191/Falcon/Falcon.Extend</RepositoryUrl>
<Description>.NET 基础类型方法扩展</Description>
<Authors>Falcon</Authors>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,26 @@
namespace Faclon.Extend
{
/// <summary>
/// 字符串处理扩展
/// </summary>
public static class StringExtend
{
/// <summary>
/// 是否为Null或Empty
/// </summary>
/// <param name="str">要判断的字符串</param>
/// <returns>如果为Null或Empty返回True否则False</returns>
public static bool IsNullOrEmpty(this string str) {
return str == null ? true : string.IsNullOrEmpty(str);
}
/// <summary>
/// 是否为Null或Empty
/// </summary>
/// <param name="str">要判断的字符串</param>
/// <returns>如果为Null或Empty返回True否则False</returns>
public static bool IsNotNullOrEmpty(this string str) {
return !str.IsNullOrEmpty();
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Faclon.Extend\Faclon.Extend.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,24 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Faclon.Extend.Tests
{
[TestClass()]
public class StringExtendTests
{
[TestMethod()]
public void IsNullOrEmptyTest() {
string str = null;
Assert.IsTrue(str.IsNullOrEmpty());
Assert.IsFalse(str.IsNotNullOrEmpty());
str = "";
Assert.IsTrue(str.IsNullOrEmpty());
Assert.IsFalse(str.IsNotNullOrEmpty());
str = string.Empty;
Assert.IsTrue(str.IsNullOrEmpty());
Assert.IsFalse(str.IsNotNullOrEmpty());
str = "abc";
Assert.IsFalse(str.IsNullOrEmpty());
Assert.IsTrue(str.IsNotNullOrEmpty());
}
}
}