Skip to content

Commit

Permalink
chore: c#markup generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Oct 15, 2023
1 parent b4cad3f commit 1b96490
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Uno.Markup.Extensions;
public static class ColorExtensions
{
public static string ToRgbText(this Color color) => $"{color.R:X2}{color.G:X2}{color.B:X2}";
public static string ToRgbText(this SolidColorBrush brush) => brush.Color.ToRgbText();
public static string? ToRgbText(this SolidColorBrush brush) => brush.Color?.ToRgbText();

#if LINQPAD
public static object ToColoredBlock(this Color color)
Expand All @@ -21,5 +21,5 @@ public static string ToPrettyString(this Color color)
{
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2} (rgb: {color.R} {color.G} {color.B}, alpha: {color.A})";
}
public static string ToPrettyString(this SolidColorBrush brush) => brush.Color.ToPrettyString();
public static string? ToPrettyString(this SolidColorBrush brush) => brush.Color?.ToPrettyString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public static class FluentExtensions
{
public static T? As<T>(this object? x) where T : class => x as T;
public static TResult? Apply<T, TResult>(this T value, Func<T, TResult> selector)
public static TResult Apply<T, TResult>(this T value, Func<T, TResult> selector)
{
return value != null ? selector(value) : default;
return selector(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public static class StringExtensions
public static string Prefix(this string? value, string prefix) => prefix + value;
public static string Suffix(this string? value, string suffix) => value + suffix;
public static string RegexReplace(this string input, string pattern, string replacement) => Regex.Replace(input, pattern, replacement);
public static string RemoveOnce(this string s, string value)
public static string? RemoveOnce(this string s, string? value)
{
return value.Length > 0 && s.IndexOf(value) is var index && index != -1
return value?.Length > 0 && s.IndexOf(value) is var index && index != -1
? s.Remove(index, value.Length)
: value;
: s;
}
public static string RemoveHead(this string value, string head) => head?.Length > 0 && value.StartsWith(head) ? value[head.Length..] : value;
public static string RemoveTail(this string value, string tail) => tail?.Length > 0 && value.EndsWith(tail) ? value[..^tail.Length] : value;
public static string RemoveHead(this string value, string? head) => head?.Length > 0 && value.StartsWith(head) ? value[head.Length..] : value;
public static string RemoveTail(this string value, string? tail) => tail?.Length > 0 && value.EndsWith(tail) ? value[..^tail.Length] : value;
public static string Trim(this string value, string trimChars) => value.Trim(trimChars.ToArray());
public static string? StripPair(this string value, string pair) => TryStripPair(value, pair, out var result) ? result : value;
public static bool TryStripPair(this string value, string pair, out string? result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<PropertyGroup>
<RootNamespace>Uno.Markup</RootNamespace>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading

0 comments on commit 1b96490

Please sign in to comment.