To reproduce:
public abstract class ContainsProtectedType
{
protected abstract Section Create();
protected readonly struct Section { }
}
var expectations = Rock.Create<ContainsProtectedType>();
This causes errors like this:
Error - Id: CS0122, Description: Rocks\Rocks.RockCreateGenerator\ContainsProtectedType_Rock_Create.g.cs(125,130): error CS0122: 'ContainsProtectedType.Section' is inaccessible due to its protection level
The problem is the extension methods to set expectations, because they will return the Section type, but at that level, the extension methods can't "see" that type.
I think the only way to handle this is to look at all members of a given member (e.g. parameter and return types for methods, properties/indexers, etc.). If any of them are inaccessible:
- If that member must be mocked (e.g. it's
abstract or it's a member on an interface without a DIM), then that typed can't be mocked.
- If that member is optional (e.g. it's
virtual or it's a member on an interface with a DIM), we don't include it in the mockable member list.
This was discovered on System.Reflection.PortableExecutable.ManagedPEBuilder.
To reproduce:
This causes errors like this:
The problem is the extension methods to set expectations, because they will return the
Sectiontype, but at that level, the extension methods can't "see" that type.I think the only way to handle this is to look at all members of a given member (e.g. parameter and return types for methods, properties/indexers, etc.). If any of them are inaccessible:
abstractor it's a member on an interface without a DIM), then that typed can't be mocked.virtualor it's a member on an interface with a DIM), we don't include it in the mockable member list.This was discovered on
System.Reflection.PortableExecutable.ManagedPEBuilder.