I have an object called CottonCandy. CottonCandy has a few properties:
- Mass
- Volume
- TotalSugar
- Colors
What would be great is if I could add something to CottonCandy so that I could retrieve properties like so:
var colors = cottonCandy["Colors"];
From reading this it looks like you can get the value with:
cottonCandy.GetType().GetProperty("Colors").GetValue(cottonCandy, null);
and you can easily wrap that in a method:
var colors = cottonCandy.GetPropertyValue("Colors");
but I'd really prefer the key/value syntax cottonCandy["Colors"]
. Is there any way to make that happen?