Skip to content

Commit

Permalink
version 1.0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
nameofSEOKWONHONG committed Nov 14, 2023
1 parent 9f3a7f3 commit 1dacf04
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 93 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ This is a project that creates many useful methods based on null safe.

Refer to the test code for how to use it.

## Support
net7, net8

## Version
* 1.0.0.6
* add - static string xDistinct(this IEnumerable<string> items)
* support net8

### Acknowledgements

[JetBrains](https://www.jetbrains.com/?from=eXtensionSharp) kindly provides `eXtensionSharp` with a free open-source
Expand Down
26 changes: 26 additions & 0 deletions src/XGeoExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace eXtensionSharp;

public static class XGeoExtensions
{
public static bool xValidateLatitude(this double latitude)
{
if (latitude.xIsEmpty()) return false;

if (latitude is < -90 or > 90)
{
return false;
}
return true;
}

public static bool xValidateLongitude(this double longitude)
{
if (longitude.xIsEmpty()) return false;

if (longitude is < -180 or > 180)
{
return false;
}
return true;
}
}
71 changes: 17 additions & 54 deletions src/XStringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO.Compression;
using System.Linq.Expressions;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -206,12 +207,26 @@ public static string xDistinct(this string str)
}
});

return string.Join("", hash);
return hash.xJoin();
}

public static string xDistinct(this IEnumerable<string> items)
{
var hash = new HashSet<string>();
items.xForEach(item =>
{
if (!hash.Contains(item))
{
hash.Add(item);
}
});

return hash.xJoin();
}

public static string xToMySqlRLikeString(this IEnumerable<string> items)
{
return string.Join('|', items.ToArray());
return items.ToArray().xJoin("|");
}

public static Guid xToGuid(this string str) => Guid.Parse(str);
Expand Down Expand Up @@ -337,57 +352,5 @@ public static string xHiddenText(this string str, char hiddenChar, int startIdx,

return new String(arr);
}

public static Encoding xToEncoding(this string value)
{
var result = value.ToUpper() switch
{
"UTF-8" => Encoding.UTF8,
"UTF32" => Encoding.UTF32,
"Unicode" => Encoding.Unicode,
"BigEndianUnicode" => Encoding.BigEndianUnicode,
"Latin1" => Encoding.Latin1,
"ASCII" => Encoding.ASCII,
_ => Encoding.UTF8
};
return result;
}

public static bool xCheckImageFile(this string url)
{
try
{
if (!Regex.IsMatch(url, @"(http?:\/\/[^ ]*\.(?:png|jpg|jpeg))", RegexOptions.IgnoreCase) &&
!Regex.IsMatch(url, @"(https?:\/\/[^ ]*\.(?:png|jpg|jpeg))", RegexOptions.IgnoreCase))
return false;

if (Path.GetExtension(url).xIsEmpty()) return false;

if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
{
var uri = new Uri(url);
string path = uri.GetLeftPart(UriPartial.Path);
if (string.Equals(Path.GetExtension(path), ".jpg", StringComparison.OrdinalIgnoreCase).xIsFalse() &&
string.Equals(Path.GetExtension(path), ".jpeg", StringComparison.OrdinalIgnoreCase)
.xIsFalse() &&
string.Equals(Path.GetExtension(path), ".png", StringComparison.OrdinalIgnoreCase).xIsFalse())
{
return false;
}
}
else
{
return false;
}
}
catch
{
return false;
}

return true;
}


}
}
36 changes: 0 additions & 36 deletions src/XValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,5 @@ public static T xAs<T>(this object src)
// if (defaultValue.xIsNotEmpty()) return defaultValue;
// return default;
// }

public static string xToXmlString(this object obj, Type type)
{
string result = string.Empty;
XmlSerializer xmlSerialzer = new XmlSerializer(type);

using (MemoryStream ms = new MemoryStream())
{
xmlSerialzer.Serialize(ms, obj);
result = Encoding.UTF8.GetString(ms.ToArray());
}

return result;
}

public static bool xValidateLatitude(this double latitude)
{
if (latitude.xIsEmpty()) return false;

if (latitude is < -90 or > 90)
{
return false;
}
return true;
}

public static bool xValidateLongitude(this double longitude)
{
if (longitude.xIsEmpty()) return false;

if (longitude is < -180 or > 180)
{
return false;
}
return true;
}
}
}
6 changes: 3 additions & 3 deletions src/eXtensionSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Copyright>seokwon hong</Copyright>
<Product>eXtensionSharp</Product>
<Company>seokwon hong</Company>
<Version>1.0.0.5</Version>
<FileVersion>1.0.0.5</FileVersion>
<Version>1.0.0.6</Version>
<FileVersion>1.0.0.6</FileVersion>
<Title>eXtensionSharp</Title>
<Description>c# extensions</Description>
<PackageProjectUrl>https://github.com/nameofSEOKWONHONG/eXtensionSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/nameofSEOKWONHONG/eXtensionSharp</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.pkg.github.com/nameofSEOKWONHONG/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="nameofSEOKWONHONG" />
<add key="ClearTextPassword" value="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" />
</github>
</packageSourceCredentials>
</configuration>

0 comments on commit 1dacf04

Please sign in to comment.