Al resolver la cuestiónType.GetType(), HashSet <T> y la Asamblea Calificación
me encontré con el comportamiento de Type.GetType (cadena typeName) que no entiendo.
Al conseguir el tipo de un List<int>
, es suficiente para especificar el tipo que
System.Collections.Generic.List`1 [[System.Int32]]
Sin embargo, para HashSet<int>
, debo especificar un nombre de tipo completo como éste
System.Collections.Generic.HashSet`1 [[System.Int32]], System.Core, Version = 4.0.0.0, Culture = neutr Al PublicKeyToken = b77a5c561934e089
Si dejo a cabo cualquier de la asamblea, la versión, la cultura, o símbolo de clave pública, no se resuelve el tipo.
Código para reproducir
// Returns expected type:
Type tListWorks =
Type.GetType("System.Collections.Generic.List`1[[System.Int32]]");
// Returns null:
Type tHashSetNull =
Type.GetType("System.Collections.Generic.HashSet`1[[System.Int32]]");
// Returns expected type:
Type tHashSetWorks =
Type.GetType("System.Collections.Generic.HashSet`1[[System.Int32]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
// Returns null (omitted Culture):
Type tHashSetNoCultureFails =
Type.GetType("System.Collections.Generic.HashSet`1[[System.Int32]], System.Core, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089");
Preguntas
- ¿Por qué debo calificar totalmente
HashSet<T>
pero noList<T>
? - Dado que se debe especificar la calificación de Versión, ¿qué pasa si el .NET Runtime es 3.5 (el primero que tenía
HashSet<T>
) o uno posterior como .NET 4.5? ¿Qué pasa si el tiempo de ejecución es algo completamente diferente a Silverlight o Mono?
Esto también debería funcionar (aunque no lo he probado): 'System.Collections.Generic.HashSet'1 [[System.Int32]], System.Core' –
@Andrey: Esa era mi expectativa demasiado , Pero eso no funciona. –
esto podría ser relevante: http://stackoverflow.com/a/2367674/39068 –