Polymorphism and generics - issues that could perhaps have a solution #64602
Unanswered
Dryadwoods
asked this question in
Ideas
Replies: 1 comment 1 reply
-
This might make more sense as a discussion on https://github.com/dotnet/csharplang if what you want it a new language feature. When you say //serviceU3.XXXXX() --> has no information about the methods we need Its unclear to me what you expect to be there. Can you replace |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using .NET 6 (code bellow).
Bellow I have a code sample of something that I am trying to accomplish.
Issue 1: where we say, use
TTarget
asUser
, we also need to pass theT
ID
type.... why by passingUser
is not enought for the compiler to know theID
data type? Example:class UserService : IBaseDBOperation1<User, Guid>
why notclass UserService : IBaseDBOperation1<User>
?Issue 2: I understand that now we are allowed to have interfaces with methods with code, but why do we still need to define the variable type exactly with both data types and using
var
OR the class name is not enough? Well, we can usevar
orUserService
, but then the methods are not visible.instead of:
IBaseDBOperation1<User, Guid> serviceU1 = new UserService();
........var serviceU2 = new UserService();
...... this second variable will not see the other methods, the same applies toUserService serviceU3 = new UserService();
.Final note: Everything would be so much easier if C# would allow us to extend a class with more than one other abstract class.... (as of today we are limited to 1).
Objective: in other words.... avoid copy/paste, and somehow "inject/associate/register/define" more than one "operation class" into a service.... those "operation classes" will be reused a lot in multiple different services.... and I do want to have a "clean/pretty" way of setting this up, but at the same time, the consumer should not worry about "lower/deeper "lever inheritance generics.
Code
Services
Consumer
Beta Was this translation helpful? Give feedback.
All reactions