Reputation: 3256
I am trying to setup interface method that will give version number:
var versionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
I am not sure how to implement this in an interface, so that the inheriting class can get the version number?
Upvotes: 1
Views: 57
Reputation: 393769
public interface IVersionProvider
{
string GetVersion();
}
implementation:
internal class /*or struct*/ VersionProvider : IVersionProvider
{
public string GetVersion()
{
System.Reflection.Assembly.GetExecutingAssembly()
.GetName().Version.ToString();
}
}
I made the class internal, because it doesn't need to be externally creatable:
public class Factory
{
IVersionProvider GetVersionProvider() { return new VersionProvider(); }
}
Since the interface is public, external users will be able to call 'GetVersion' on it even though the implementation is private to the assembly.
Upvotes: 1