c# - Creating interface with generic methods -


I'm trying to design an interface, so that's a common type of ID and a common method, just like Return of the class to apply this interface to the example:

  Public Interface IERTIT & lt; IDTIP, Method Return Type & gt; {IDType ID {Receive; Set;} Get the type of return method (); } Public Square Model: IEentity & lt; int, model & gt; {int ID {get; Set; } Get the Model () {// Something}}   

My question is, it seems silly to insert the second type of IERTI model into the model, because I I am already in the class of the model, how to find out how it should be some intelligence method (though it is necessary to set it before compiling time to use the common type).

Is this any other solution that can help me get rid of this? The type of model during maintaining the gate method definition in the interface?

In this context, there are two common ways to go about designing your classes and interfaces < / P>

Which of these options really depends on how you want to use your classes and interfaces.

Option 1

Make your interface generic, so that members of the interface have the exact type of knowledge.

  Public Interface IERTTAT & lt; TDescription & gt; {TDescription Get (); } Public class MyModel: IEentity & lt; MyDescription & gt; {MyDescription Get () {...}} Public Segment MyDescription {...}   

This means that when you use your interface IEentity & lt; TDescription & gt; is the need to know the TDescription at the time of use is that you are checking more compile time types.

Option 2

Do not normalize your interface and instead use your interface's member interface.

  get the public interface IERTTI {IDscription ()); } Public Interface IDescription {...} Public Category MyModel: IEntity {MyDescription Get () {...} IDescription IEntity.Get () {return.Get (); }} Public class MyDescription: IDescription {...}   

It is more flexible, but it means less compile-time type inquiry.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -