Reputation: 733
In my Xamarin.Forms application, I added a .NET standard library in which I would like to use the Properties dictionary.
However, I would like to avoid the hardcoding of the key "id".
Application.Current.Properties ["id"] = someClass.ID;
What is the best way to go about it?
Upvotes: 0
Views: 190
Reputation: 3492
I would create a static class for this, something along the lines of
public static class Constants
{
public const string Id = "id";
// etc...
}
Then update your code to
Application.Current.Properties [Constants.Id] = someClass.ID;
Upvotes: 2
Reputation: 1869
There is probably no best way, but one way is to use the nameof syntax, because if you rename a Property, this will be changed, too:
// I added ToLowerInvariant, because you wrote "id".
Application.Current.Properties[nameof(someClass.ID).ToLowerInvariant()] = someClass.ID;
Upvotes: 1