[API Proposal]: Add indexer to record
Mr0N opened this issue · comments
Mr0N commented
Background and motivation
I suggest adding an indexer to the record for all fields so that the runtime can automatically generate code for it, similar to how it is done for ToString
API Proposal
public record JsonSaveModel
{
public object this[string obj]
{
set {
if (obj == nameof(index))
index = value;
throw new Exception();
}
get {
if (obj == nameof(index))
return index;
throw new Exception();
}
}
public string index { get; set; }
}
API Usage
class Q
{
public Q()
{
var res = new JsonSaveModel();
res["index"] = "90239023";
}
}
Alternative Designs
No response
Risks
No response
Steve commented
This should be a language proposal instead of an API proposal.