The declaration:
public class MyLEvent<T,M> where T : class where M : class
{
...
}
...defines a generic type that is used to create concrete types when provided with the appropriate type parameters. You cannot use generic types directly, you can only use them to create concrete types which can then be used.
For example, the List<T>
generic type defines structure and code that can be used to create a variety of concrete types depending on the type parameter you use. List<string>
is a concrete type created from the List<T>
generic type.
In the case of your MyLEvent
generic, there are two type parameters: T
and M
. You need to specify both of those to create a concrete type that can be used.
In your MyListView
class you define the MyLEvnt
field like this:
internal MyLEvent<Type,Type> MyLEvnt { get; set; }
This defines the MyLEvnt
field as an instance of the concrete type MyLEvent<Type, Type>
. Note that Type
is a class that is used to access information about types. In this usage it is not a way to avoid supplying a type parameter, it is a type parameter.
In your third class you then do this:
MAILV.MyLEvnt = new MyLEvent<typeof(InvMail), MailManager>();
Even when we take the typeof()
out of it, this will fail because you are attempting to assign an instance of MyLEvent<InvMail, MailManager>
to a field of type MyLEvent<Type, Type>
. These are different types, just as List<string>
is different from List<int>
.
You need to read the MSDN articles on Generics. These explain the details of how generics work and give you a lot of examples of how to use them and why.