Open
Description
0.1.16-dev
void M(IEnumerable<object> objectImplementingIEnumerable)
{
objectImplementingIEnumerable.GetType().GetMethod("Add");
}
REFL003 The type System.Collections.Generic.IEnumerable<object> does not have a member named Add.
The analyzer should bail if it sees a GetType() on an expression of a virtual type since it can know nothing about the expected concrete type which may be internal to an external lib.
Additionally, if it sees a GetType() on a nonvirtual type, maybe it should bail anyway because it will be reporting #169 in all these cases anyway.
Actual code, in case you wonder why you would do this:
public static IReadOnlyCollection<Assembly> GetAssemblies(this ITypeDiscoveryService typeDiscoveryService)
{
var serviceType = typeDiscoveryService.GetType();
if (serviceType.FullName == "Microsoft.VisualStudio.Design.VSTypeResolutionService") // Achieve instantaneous load, vs around a second's freeze
{
var normalEntries = (IEnumerable<object>)serviceType.GetField("_normalEntries", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(typeDiscoveryService);
// ...
Metadata
Metadata
Assignees
Labels
No labels