Skip to content

Instantly share code, notes, and snippets.

@mr5z
Last active September 29, 2020 10:49
Show Gist options
  • Save mr5z/28754745d48a128472e21b5f9635bcc3 to your computer and use it in GitHub Desktop.
Save mr5z/28754745d48a128472e21b5f9635bcc3 to your computer and use it in GitHub Desktop.
Shortened or lessen the input parameter to Xamarin.Forms.BindableProperty.Create()
public static BindableProperty CreateProperty<T>(T defaultValue = default, BindingMode mode = BindingMode.TwoWay, [CallerMemberName] string propertyName = null)
{
propertyName = RemoveLastOccurrence(propertyName, "Property");
return BindableProperty.Create(propertyName, typeof(T), typeof(BindableObject), defaultValue, mode);
}
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