C
C#7mo ago
Kiel

Concern over inheritance with static interface methods

Consider the following interface:
public interface ILuaModel
{
static abstract void SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider);
}

public interface ILuaModel<TModel> : ILuaModel
where TModel : class
{
new static void SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider)
=> provider.SetDescriptor<TModel>(new InstanceTypeUserDataDescriptor(typeof(TModel), namingPolicy: CamelCaseUserDataNamingPolicy.Instance));
static void ILuaModel.SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider) => SetUserDataDescriptor(provider);
}
public interface ILuaModel
{
static abstract void SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider);
}

public interface ILuaModel<TModel> : ILuaModel
where TModel : class
{
new static void SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider)
=> provider.SetDescriptor<TModel>(new InstanceTypeUserDataDescriptor(typeof(TModel), namingPolicy: CamelCaseUserDataNamingPolicy.Instance));
static void ILuaModel.SetUserDataDescriptor(DefaultUserDataDescriptorProvider provider) => SetUserDataDescriptor(provider);
}
I have two classes, LuaUser and LuaMember. When I implement the classes like so, I get the following error:
class LuaUser : ILuaModel<LuaUser> { }

// Interface member 'ILuaModel.SetUserDataDescriptor' doesn't have a most specific implementation. Neither 'ILuaModel<LuaMember>.SetUserDataDescriptor', nor 'ILuaModel<LuaUser>.SetUserDataDescriptor' are most specific.
class LuaMember : LuaUser, ILuaModel<LuaMember> { }
class LuaUser : ILuaModel<LuaUser> { }

// Interface member 'ILuaModel.SetUserDataDescriptor' doesn't have a most specific implementation. Neither 'ILuaModel<LuaMember>.SetUserDataDescriptor', nor 'ILuaModel<LuaUser>.SetUserDataDescriptor' are most specific.
class LuaMember : LuaUser, ILuaModel<LuaMember> { }
If I add the suggested fix for this, which is creating an implementation of the non-generic SetUserDataDescriptor...Will this cause any issues? What should this method do exactly? Currently I am utilizing reflection to get all ILuaModel implementations, to call SetUserDataDescriptor, and I just want to know what I should do here to make sure both LuaUser and LuaMember have their methods called appropriately.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server