I have this abstract class and a specific implementation (they are in different assemblies):
public abstract class MyAbstractClass { private static readonly int MyAbstractClassVersion = 1; public abstract int ImplementedVersion { get; } protected MyAbstractClass() { CheckVersion(); } private void CheckVersion() { var message = string.Format( "MyAbstractClass implements Version {0}, concrete is Version {1}", RepositoryVersion, ImplementedVersion); if (!MyAbstractClassVersion.Equals(ImplementedVersion)) throw new InvalidOperationException(message); } } public class ConcreteClass : MyAbstractClass { public ConcreteClass() : base() {
As you can see, I call the CheckVersion () function from the abstract constructor to get rid of the message “virtual member in the base constructor”, but I'm not sure if this is really a way to do this. Of course, this works, but that doesn’t mean that it will always work, right?
Also, I am wondering if I can get a Concrete type name from the CheckVersion () function?
I know that adding new abstract elements will still result in an error (System.TypeLoadException), and I'm not sure if I want this type of strict versioning Versioning, but I'm just wondering how it will be done correctly, the abstract class and implementation (I I know that I can do this using interfaces and / or the Factory template).
source share