Is it possible to have something like this in C#? I am not very sure:
class Library
{
public string Books[string title]
{
get{return this.GetBookByName(string title);}
}
public DateTime PublishingDates[string title]
{
get{return this.GetBookByName(string title).PublishingDate;}
}
}
So it could be used as such:
myLibrary.Books["V For Vendetta"]
myLibrary.PublishingDates["V For Vendetta"] = ...
So my complete member methods that I need to implement in my framework (by calling them) are:
GetCustomStringValue (key)
GetCustomIntValue (key)
GetCustomBoolValue (key)
GetCustomFloatValue (key)
SetCustomStringValue (key)
SetCustomIntValue (key)
SetCustomBoolValue (key)
SetCustomFloatValue (key)
I want to implement them cleaner in my own type.
The only way you could do this would be to have
Booksbe a property that returns a type that has its own suitable indexer. Here’s one possible approach:But you should seriously consider providing an implementation of
IDictionary<,>instead of using this approach, as it will allow other nifty stuff, like enumeration of key-value pairs, etc.