Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# Pin
OriginalGriff5-Apr-19 4:39
mveOriginalGriff5-Apr-19 4:39 
QuestionRe: c# Pin
ZurdoDev5-Apr-19 4:49
professionalZurdoDev5-Apr-19 4:49 
AnswerRe: c# Pin
Dave Kreskowiak5-Apr-19 13:03
mveDave Kreskowiak5-Apr-19 13:03 
QuestionHow to convert emoji's unicode strings Pin
Vimalsoft(Pty) Ltd4-Apr-19 20:57
professionalVimalsoft(Pty) Ltd4-Apr-19 20:57 
AnswerRe: How to convert emoji's unicode strings Pin
OriginalGriff4-Apr-19 21:35
mveOriginalGriff4-Apr-19 21:35 
GeneralRe: How to convert emoji's unicode strings Pin
Vimalsoft(Pty) Ltd5-Apr-19 2:13
professionalVimalsoft(Pty) Ltd5-Apr-19 2:13 
QuestionHow do I set a breakpoint in an attached process in visual studio? Pin
Xarzu4-Apr-19 8:43
Xarzu4-Apr-19 8:43 
AnswerRe: How do I set a breakpoint in an attached process in visual studio? Pin
ZurdoDev4-Apr-19 9:20
professionalZurdoDev4-Apr-19 9:20 
GeneralRe: How do I set a breakpoint in an attached process in visual studio? Pin
Xarzu5-Apr-19 4:22
Xarzu5-Apr-19 4:22 
AnswerRe: How do I set a breakpoint in an attached process in visual studio? Pin
Dave Kreskowiak4-Apr-19 9:24
mveDave Kreskowiak4-Apr-19 9:24 
GeneralRe: How do I set a breakpoint in an attached process in visual studio? Pin
Xarzu5-Apr-19 4:22
Xarzu5-Apr-19 4:22 
QuestionSimplify usage of a complex generic class for convenience Pin
Failwyn4-Apr-19 5:02
Failwyn4-Apr-19 5:02 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
Gerry Schmitz4-Apr-19 5:10
mveGerry Schmitz4-Apr-19 5:10 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 21:00
professionalBillWoodruff5-Apr-19 21:00 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
Richard Deeming4-Apr-19 9:28
mveRichard Deeming4-Apr-19 9:28 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 4:03
professionalBillWoodruff5-Apr-19 4:03 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
Richard Deeming5-Apr-19 5:34
mveRichard Deeming5-Apr-19 5:34 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 16:37
professionalBillWoodruff5-Apr-19 16:37 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
Richard Deeming15-Apr-19 8:15
mveRichard Deeming15-Apr-19 8:15 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff15-Apr-19 19:06
professionalBillWoodruff15-Apr-19 19:06 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
Richard Deeming16-Apr-19 7:32
mveRichard Deeming16-Apr-19 7:32 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 20:12
professionalBillWoodruff5-Apr-19 20:12 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
Gerry Schmitz6-Apr-19 11:03
mveGerry Schmitz6-Apr-19 11:03 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff6-Apr-19 11:20
professionalBillWoodruff6-Apr-19 11:20 
Gerry Schmitz wrote:
One knows how many parameters are passed based the count
Not in this case; the indexing in the call to 'base is executed immediately during instantiation.

You could do it this way:
public class MyClass<T1, T2, T3, T4>
{
    public T1 Value1 { get; set; }
    public T2 Value2 { get; set; }
    public T3 Value3 { get; set; }
    public T4 Value4 { get; set; }

    public MyClass(T1 value1, T2 value2, T3 value3, T4 value4)
    {
        Value1 = value1;
        Value2 = value2;
        Value3 = value3;
        Value4 = value4;
    }

    protected MyClass()
    {
    }
}

public class MyClass<T1> : MyClass<T1, T1, T1, T1>
{
    public MyClass(params T1[] values)
    {
        if(values.Length != 4) throw new ArgumentException("requires 4 parameters");

        Value1 = values[0];
        Value2 = values[1];
        Value3 = values[2];
        Value4 = values[3];
    }
}
But, look what happens: the Value properties in the base class now require a setter, and thw base class requirea a parameterless ctor.

imho, all of these implementations are hacks, and writing straightforward individual methods for each group of Types is better practice.

To me the attempt here to make these generic methods more "generalized" just leads to semantic confusion. It's not that much work to write a bunch of specific methods that can provide strict control over parameter validation, and can be unit tested efficiently.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot


modified 6-Apr-19 18:55pm.

GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff6-Apr-19 15:44
professionalBillWoodruff6-Apr-19 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.