.NET: Unable to cast object to interface it implements

I hat the same problems with a library of mine providing “plugin”-functionality… I got it finally working… Here was my problem: I had one main assembly using plugins, one assembly with the plugin (Plugin.dll) AND (important) another assembly providing the plugin-functionality (Library.dll). The Plugin.dll referenced the main assembly (in order to be able to extend … Read more

How to hide an inherited property in a class without modifying the inherited class (base class)?

I smell a code smell here. It is my opinion that you should only inherit a base class if you’re implementing all of the functionality of that base class. What you’re doing doesn’t really represent object oriented principles properly. Thus, if you want to inherit from your base, you should be implementing Name, otherwise you’ve … Read more

Cast base class to derived class python (or more pythonic way of extending classes)

If you are just adding behavior, and not depending on additional instance values, you can assign to the object’s __class__: from math import pi class Circle(object): def __init__(self, radius): self.radius = radius def area(self): return pi * self.radius**2 class CirclePlus(Circle): def diameter(self): return self.radius*2 def circumference(self): return self.radius*2*pi c = Circle(10) print c.radius print c.area() … Read more