Added some methods

- `ToInt` mathod
- `FromInt` method
- `ToPath` method
This commit is contained in:
Stone-Red-Code
2021-05-04 15:08:40 +02:00
parent 5dfaaa2078
commit a4232e98f2
30 changed files with 247 additions and 32 deletions
Binary file not shown.
+66 -1
View File
@@ -137,8 +137,47 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
False
False
```
* ToInt
* Description: Converts bool to int.
* Parameters: `this bool bol`
* Example usage:
```cs
bool bol1 = false;
bool bol2 = true;
int i = bol1.ToInt();
int j = bol2.ToInt();
Console.WriteLine(i);
Console.WriteLine(j);
```
* Output:
```
0
1
```
* FromInt
* Description: Converts int to bool.
* Parameters: `this ref bool bol`, `int input`
* Example usage:
```cs
bool bol1;
bool bol2;
bol1.FromInt(0);
bol2.FromInt(1);
Console.WriteLine(bol1);
Console.WriteLine(bol2);
```
* Output:
```
false
true
```
### Stone_Red_Utilities.StringExtentions
#### Methods:
#### Methods
* EqualsIgnoreCase
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case.
* Parameters: `this string str`, `string value`
@@ -187,6 +226,32 @@ https://www.nuget.org/packages/Stone_Red-C-Sharp-Utilities
```
True
```
* ToFileName
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces.
* Parameters: `this string str`, `string value`
* Example usage:
```cs
string str = "*n*/ /äme";
string fileName = str.ToFileName();
Console.WriteLine(fileName);
```
* Output:
```
name
```
* ToPath
* Description: Determines whether this instance and another specified string object have the same value regardless of upper and lower case and spaces.
* Parameters: `this string str`, `string value`
* Example usage:
```cs
string str = "C://goöd /päth";
string fileName = str.ToPath();
Console.WriteLine(fileName);
```
* Output:
```
C://good/path
```
### Stone_Red_Utilities.Logging
#### Constructor:
* Logger
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
namespace Stone_Red_Utilities.ArrListExtentions
{
@@ -26,5 +26,25 @@
if (bol == true && !input)
bol = false;
}
/// <summary>
/// Converts bool to int.
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static int ToInt(this bool input)
{
return input ? 1 : 0;
}
/// <summary>
/// Converts int to bool.
/// </summary>
/// <param name="bol"></param>
/// <param name="input"></param>
public static void FromInt(this ref bool bol, int input)
{
bol = input == 1;
}
}
}
@@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Stone_Red_C_Sharp_Utilities</RootNamespace>
<Authors>Stone_Red</Authors>
<PackageTags>Console, Table, Print</PackageTags>
<PackageTags>ExtensionMethods, Methods, Extention, Console, Table, Print, C#</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>Adds useful methods</Description>
<PackageProjectUrl></PackageProjectUrl>
@@ -12,9 +12,9 @@
<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.0.1.1</AssemblyVersion>
<FileVersion>1.0.1.1</FileVersion>
<Version>1.0.1.1</Version>
<AssemblyVersion>1.0.1.2</AssemblyVersion>
<FileVersion>1.0.1.2</FileVersion>
<Version>1.0.1.2</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -77,6 +77,20 @@
<param name="bol"></param>
<param name="input"></param>
</member>
<member name="M:Stone_Red_Utilities.BoolExtentions.BoolExt.ToInt(System.Boolean)">
<summary>
Converts bool to int.
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.BoolExtentions.BoolExt.FromInt(System.Boolean@,System.Int32)">
<summary>
Converts bool to int.
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt">
<summary>
Console Extentions
@@ -245,7 +259,15 @@
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.ToFileName(System.String,System.Boolean)">
<summary>
Removes all invalid chars from file name
Removes all invalid chars from the specified string
</summary>
<param name="str"></param>
<param name="allowSpaces"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.ToPath(System.String,System.Boolean)">
<summary>
Removes all invalid chars from the specified string
</summary>
<param name="str"></param>
<param name="allowSpaces"></param>
@@ -268,5 +290,12 @@
<param name="ellipsis"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.CorrectNewLine(System.String)">
<summary>
Uses the correct newline string defined for this environment.
</summary>
<param name="str"></param>
<returns></returns>
</member>
</members>
</doc>
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
namespace Stone_Red_Utilities.StringExtentions
{
@@ -47,7 +45,7 @@ namespace Stone_Red_Utilities.StringExtentions
}
/// <summary>
/// Removes all invalid chars from file name
/// Removes all invalid chars from the specified string
/// </summary>
/// <param name="str"></param>
/// <param name="allowSpaces"></param>
@@ -79,6 +77,39 @@ namespace Stone_Red_Utilities.StringExtentions
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
/// <summary>
/// Removes all invalid chars from the specified string
/// </summary>
/// <param name="str"></param>
/// <param name="allowSpaces"></param>
/// <returns></returns>
public static string ToPath(this string str, bool allowSpaces = false)
{
char[] invalidChars = Path.GetInvalidPathChars();
if (!allowSpaces)
str = str.Replace(" ", string.Empty);
foreach (var item in invalidChars)
{
str = str.Replace(item.ToString(), string.Empty);
}
var normalizedString = str.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();
foreach (var c in normalizedString)
{
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
/// <summary>
/// Truncates a string to the specified length.
/// </summary>
@@ -114,5 +145,20 @@ namespace Stone_Red_Utilities.StringExtentions
return str;
}
/// <summary>
/// Uses the correct newline string defined for this environment.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string CorrectNewLine(this string str)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
str = str.Replace("\r\n", "\n");
else
str = str.Replace("\n", "\r\n"); //Ik that this can produce wrong results
return str;
}
}
}
@@ -7,7 +7,7 @@
"targets": {
".NETStandard,Version=v2.1": {},
".NETStandard,Version=v2.1/": {
"Stone_Red-C-Sharp-Utilities/1.0.1.1": {
"Stone_Red-C-Sharp-Utilities/1.0.1.2": {
"runtime": {
"Stone_Red-C-Sharp-Utilities.dll": {}
}
@@ -15,7 +15,7 @@
}
},
"libraries": {
"Stone_Red-C-Sharp-Utilities/1.0.1.1": {
"Stone_Red-C-Sharp-Utilities/1.0.1.2": {
"type": "project",
"serviceable": false,
"sha512": ""
@@ -77,6 +77,20 @@
<param name="bol"></param>
<param name="input"></param>
</member>
<member name="M:Stone_Red_Utilities.BoolExtentions.BoolExt.ToInt(System.Boolean)">
<summary>
Converts bool to int.
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.BoolExtentions.BoolExt.FromInt(System.Boolean@,System.Int32)">
<summary>
Converts bool to int.
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Stone_Red_Utilities.ConsoleExtentions.ConsoleExt">
<summary>
Console Extentions
@@ -245,7 +259,15 @@
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.ToFileName(System.String,System.Boolean)">
<summary>
Removes all invalid chars from file name
Removes all invalid chars from the specified string
</summary>
<param name="str"></param>
<param name="allowSpaces"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.ToPath(System.String,System.Boolean)">
<summary>
Removes all invalid chars from the specified string
</summary>
<param name="str"></param>
<param name="allowSpaces"></param>
@@ -268,5 +290,12 @@
<param name="ellipsis"></param>
<returns></returns>
</member>
<member name="M:Stone_Red_Utilities.StringExtentions.StringExt.CorrectNewLine(System.String)">
<summary>
Uses the correct newline string defined for this environment.
</summary>
<param name="str"></param>
<returns></returns>
</member>
</members>
</doc>
@@ -8,7 +8,7 @@
<license type="file">LICENSE</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<description>Adds useful methods</description>
<tags>Console, Table, Print</tags>
<tags>ExtensionMethods, Methods, Extention, Console, Table, Print, C#</tags>
<repository url="https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities" />
<dependencies>
<group targetFramework=".NETStandard2.1" />
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Stone_Red-C-Sharp-Utilities</id>
<version>1.0.1.2</version>
<authors>Stone_Red</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<description>Adds useful methods</description>
<tags>ExtensionMethods, Methods, Extention, Console, Table, Print, C#</tags>
<repository url="https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities" />
<dependencies>
<group targetFramework=".NETStandard2.1" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Release\netstandard2.1\Stone_Red-C-Sharp-Utilities.dll" target="lib\netstandard2.1\Stone_Red-C-Sharp-Utilities.dll" />
<file src="C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\Stone_Red-C-Sharp-Utilities\bin\Release\netstandard2.1\Stone_Red-C-Sharp-Utilities.xml" target="lib\netstandard2.1\Stone_Red-C-Sharp-Utilities.xml" />
<file src="C:\Users\David\Google Drive\Programmieren\Stone_Red-C-Sharp-Utilities\LICENSE" target="LICENSE" />
</files>
</package>
@@ -14,11 +14,11 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Stone_Red")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("Adds useful methods")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1.1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1.1")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1.2")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1.2")]
[assembly: System.Reflection.AssemblyProductAttribute("Stone_Red-C-Sharp-Utilities")]
[assembly: System.Reflection.AssemblyTitleAttribute("Stone_Red-C-Sharp-Utilities")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1.1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1.2")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities")]
[assembly: System.Resources.NeutralResourcesLanguageAttribute("en")]
@@ -1 +1 @@
bedbe864b47b33264dd1a74cec3ab965f23ecb76
79d53500d0cda912836247a99f43baf59dc39d8e
@@ -5,7 +5,7 @@
},
"projects": {
"C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities.csproj": {
"version": "1.0.1.1",
"version": "1.0.1.2",
"restore": {
"projectUniqueName": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities.csproj",
"projectName": "Stone_Red-C-Sharp-Utilities",
@@ -14,10 +14,12 @@
"outputPath": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Microsoft\\Xamarin\\NuGet\\"
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet\\"
],
"configFilePaths": [
"C:\\Users\\David\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
@@ -58,7 +60,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.104\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.202\\RuntimeIdentifierGraph.json"
}
}
}
@@ -5,12 +5,14 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\David\.nuget\packages\;C:\Microsoft\Xamarin\NuGet\</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\David\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages;C:\Program Files (x86)\Microsoft\Xamarin\NuGet\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.8.1</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="$([MSBuild]::EnsureTrailingSlash($(NuGetPackageFolders)))" />
<SourceRoot Include="C:\Users\David\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft\Xamarin\NuGet\" />
</ItemGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
@@ -9,10 +9,11 @@
},
"packageFolders": {
"C:\\Users\\David\\.nuget\\packages\\": {},
"C:\\Microsoft\\Xamarin\\NuGet\\": {}
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {},
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet\\": {}
},
"project": {
"version": "1.0.1.1",
"version": "1.0.1.2",
"restore": {
"projectUniqueName": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities.csproj",
"projectName": "Stone_Red-C-Sharp-Utilities",
@@ -21,10 +22,12 @@
"outputPath": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Microsoft\\Xamarin\\NuGet\\"
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet\\"
],
"configFilePaths": [
"C:\\Users\\David\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
@@ -65,7 +68,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.104\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.202\\RuntimeIdentifierGraph.json"
}
}
}
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "OCorf4dA0laiwZvXM3MOab9IJ1fDO9ZjZiu5LzBWWVhaWliIFQdh1aRWHcfoxyrHUqXL1v73DMUfIxv/J9Xz1Q==",
"dgSpecHash": "W2mmaVJ9QVB/ybXqInWb/ntCpfIusOdp99Jf4Ov7013vN7WF0Qb5g4C67ENTi26kCRu7OFGJrygEmUHgRu1v0Q==",
"success": true,
"projectFilePath": "C:\\Users\\David\\Google Drive\\Programmieren\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities\\Stone_Red-C-Sharp-Utilities.csproj",
"expectedPackageFiles": [],