Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
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 
Failwyn wrote:
Ultimately, I don't want there to be anything different between the classes other than the ability to use a simplified signature.

The answer depends on what you mean by that statement.

The derived class is the only solution I can see. But the types would not be exactly the same:
C#
MyClass<Guid> a = new MyClass<Guid>();
MyClass<Guid, Guid, Guid, Guid> b = a; // Works
MyClass<Guid> c = b; // Won't compile - needs an explicit cast
And:
C#
MyClass<Guid, Guid, Guid, Guid> a = new MyClass<Guid, Guid, Guid, Guid>();
MyClass<Guid> b = (MyClass<Guid>)a; // Compiles, but fails at runtime
MyClass<Guid> c = a as MyClass<Guid>; // Compiles and runs, but result is null


Within a single file, you could use a using statement to create an alias for the type. But you can't use generic type parameters in the alias, so you'd need a different one for each set of type parameters you wanted to use:
C#
using MyClassGuid = MyClass<Guid, Guid, Guid, Guid>;
...
MyClassGuid a = new MyClassGuid();
You'd also have to repeat the alias in each file where you needed to use it.


If it's constructing the objects you're worried about, then a factory method might help:
C#
public static class MyClass
{
    public static MyClass<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
    {
        return new MyClass<T1, T2, T3, T4>(value1, value2, value3, value4);
    }
    
    public static MyClass<T1, T1, T1, T1> Create<T1>(T1 value)
    {
        return new MyClass<T1, T1, T1, T1>(value, value, value, value);
    }
}
...
MyClass<Guid, Guid, Guid, Guid> a = MyClass.Create(Guid.New());
MyClass<string, int, decimal, DateTime> b = MyClass.Create("Hello", 42, 123.45M, DateTime.Today);




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

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 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff6-Apr-19 15:44
professionalBillWoodruff6-Apr-19 15:44 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff6-Apr-19 12:57
professionalBillWoodruff6-Apr-19 12:57 
QuestionWhere are the libraries located in C#? Pin
Brian_TheLion3-Apr-19 20:15
Brian_TheLion3-Apr-19 20:15 
AnswerRe: Where are the libraries located in C#? Pin
OriginalGriff3-Apr-19 21:34
mveOriginalGriff3-Apr-19 21:34 
GeneralRe: Where are the libraries located in C#? Pin
Brian_TheLion3-Apr-19 23:20
Brian_TheLion3-Apr-19 23:20 
GeneralRe: Where are the libraries located in C#? Pin
OriginalGriff3-Apr-19 23:28
mveOriginalGriff3-Apr-19 23:28 
GeneralRe: Where are the libraries located in C#? Pin
Brian_TheLion4-Apr-19 0:06
Brian_TheLion4-Apr-19 0:06 
GeneralRe: Where are the libraries located in C#? Pin
OriginalGriff3-Apr-19 23:31
mveOriginalGriff3-Apr-19 23:31 

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.