Skip to content

Commit

Permalink
[.Net 7] Parse to any thing with IParsable<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed May 20, 2023
1 parent f3ff8f4 commit cedb08e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;

public static class StringExtensions
{
public static T ParseTo<T>(this string s, IFormatProvider provider)
where T : IParsable<T>
{
return T.Parse(s, provider);
}

public static bool TryParseTo<T>(this string s, IFormatProvider provider, out T result)
where T : IParsable<T>
{
return T.TryParse(s, provider, out result);
}

public static string Left(this string value, int length)
{
length = Math.Abs(length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;

public static class StringExtensions
{
public static T ParseTo<T>(this string s, IFormatProvider provider)
where T : IParsable<T>
{
return T.Parse(s, provider);
}

public static bool TryParseTo<T>(this string s, IFormatProvider provider, out T result)
where T : IParsable<T>
{
return T.TryParse(s, provider, out result);
}

public static string Left(this string value, int length)
{
length = Math.Abs(length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;

public static class StringExtensions
{
public static T ParseTo<T>(this string s, IFormatProvider provider)
where T : IParsable<T>
{
return T.Parse(s, provider);
}

public static bool TryParseTo<T>(this string s, IFormatProvider provider, out T result)
where T : IParsable<T>
{
return T.TryParse(s, provider, out result);
}

public static string Left(this string value, int length)
{
length = Math.Abs(length);
Expand Down

0 comments on commit cedb08e

Please sign in to comment.