Pregunta

  

Duplicados posibles:
   Cómo hacer referencia a un miembro de un indexador de clase en C # comentarios
   indexadores estático?


Tal como está, tengo que escribir mi código como este

internal class ReportMap {

    static internal ReportMap Instance {
        get { return reportMap; }
    }

    internal Type this[char c] {
        get { return data[c]; }
    }

    // private parts
    static Dictionary<char, Type> data =
        new Dictionary<char, Type>();

    ReportMap() {
        data.Add('S', typeof(StatusReport));
        data.Add('Q', typeof(QualityReport));
    }

    static ReportMap reportMap = new ReportMap();
}

y para acceder a un índice:

Type t = ReportMap.Instance[aChar]; // eww

¿Hay una razón específica esta capacidad se quedó fuera de la lengua? En particular, ¿se consideraría un mal diseño? Hay otra pregunta sobre este ya publicado, pero por desgracia no tienen representante suficiente para comentar.

¿Fue útil?

Solución

Eso es una buena referencia víctima allí. Específicamente, revisar la respuesta :-) indexadores estático?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top