Portable class libraries use a different reflection API than normal .NET libraries.
In portable class library projects Type is divided into Type and TypeInfo. We can use TypeInfo.AsType() to get Type from TypeInfo and Type.GetTypeInfo() to get TypeInfo from Type.
CSHTML5 uses the old approach. There is only one Type class that has methods from both Type and TypeInfo so I have to write different code for CSHTML5 and different for portable .NET library:
#if CSHTML5
var strategyTypes = typeof(MusicXmlParsingStrategy).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(MusicXmlParsingStrategy)) && !t.IsAbstract);
List<MusicXmlParsingStrategy> strategies = new List<MusicXmlParsingStrategy>();
foreach (var type in strategyTypes)
{
strategies.Add(Activator.CreateInstance(type) as MusicXmlParsingStrategy);
}
_strategies = strategies.ToArray();
#else
var strategyTypes = typeof(MusicXmlParsingStrategy).GetTypeInfo().Assembly.DefinedTypes.Where(t => t.IsSubclassOf(typeof(MusicXmlParsingStrategy)) && !t.IsAbstract);
List<MusicXmlParsingStrategy> strategies = new List<MusicXmlParsingStrategy>();
foreach (var type in strategyTypes)
{
strategies.Add(Activator.CreateInstance(type.AsType()) as MusicXmlParsingStrategy);
}
_strategies = strategies.ToArray();
#endif
I think it would be useful to implement TypeInfo, GetTypeInfo() and AsType() in CSHTML5 in the following way:
TypeInfo - inherits from Type and doesn't introduce any new members,
GetTypeInfo() - returns TypeInfo from Type,
AsType() - returns Type from TypeInfo.
Thanks to that I would not have to make two versions of code.