I'm wondering if there's a way to do this, and I don't quite understand why it's not working. Full disclosure, this is in Unity, so it may be something resolved in a later version of C#.
I have class Foo. Foo has a field and property:
MeshRenderer meshRenderer;
public MeshRenderer Renderer {get {return this.meshRenderer;} set {this.meshRenderer = value;}}
I have a derived class Bar. Bar has a field and property:
SkinnedMeshRenderer skinnedMeshRenderer;
public SkinnedMeshRenderer Renderer {get {return this.skinnedMeshRenderer;} set {this.skinnedMeshRenderer= value;}}
Foo has a method, Remesh() that sets:
this.Renderer.materials = SomeListOfMaterials.ToArray();
Bar, of course, inherits this method.
Both MeshRenderer and SkinnedMeshRenderer have a public materials field that takes an array of materials. When I debug into the code, a call to Bar.Remesh() falls through to the Foo.Remesh() method as expected, and this.Renderer.materials is valid as expected, and SomeListOfMaterials is a list of materials, as expected. But it comes back with a null reference exception.
If I copy the Remesh() code verbatim into Bar (with the new modifier), it works fine. When it's falling through to Foo.Remesh(), I even checked that this is actually Bar (it is).