Last active
March 28, 2022 10:33
-
-
Save mr5z/5ee1c5915c55ae325dfd3ef0c0b0d1d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BindableHelper | |
{ | |
private const string KnownPropertyPattern = "Property"; | |
public static BindableProperty CreateProperty<T>( | |
T? defaultValue = default, | |
BindingMode mode = BindingMode.TwoWay, | |
BindableProperty.BindingPropertyChangedDelegate? propertyChanged = null, | |
[CallerMemberName] string? propertyName = null) | |
{ | |
propertyName = RemoveLastOccurrence(propertyName!, KnownPropertyPattern); | |
return BindableProperty.Create( | |
propertyName, | |
typeof(T), | |
typeof(BindableObject), | |
defaultValue, | |
mode, | |
propertyChanged: propertyChanged); | |
} | |
private static string RemoveLastOccurrence(string source, string toFind) | |
{ | |
var index = source.LastIndexOf(toFind); | |
return index == -1 ? source : source.Substring(0, index); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment