Solved

Access type parameters of generic type

Posted on 2011-02-21
4
206 Views
Last Modified: 2013-12-17
Hello,

suppose I have a generic type MyCollection<TX, TY, TZ> in C# 3.5. Now, I want to use as a type parameter in another generic type which needs just one type param, e.g. OtherTYpe<TA> where TA:MyCollection. How can I refer to TA.TX, TA.TY, TA.TZ inside the template of OtherTYpe? I dislike the idea of declaring OtherType<TA, TX, TY, TZ> when TX, TY, TZ are already present in TA.

Also, is there something like the C typedef keyword, so that I can easily name MyCollection<TX, TY, TZ> as MyXYZCollection without having to create a descendant type? I.e.
typedef MyCollection<TX, TY, TZ> MyXYZCollection

Thanks in advance
0
Comment
Question by:bovlk
  • 3
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34943253
>>  Also, is there something like the C typedef keyword, so that I can easily name MyCollection<TX, TY, TZ> as MyXYZCollection
using MyCollection<TX, TY, TZ> = MyXYZCollection;

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34943262
Crap....   I have that backwards  : \
using MyXYZCollection = MyCollection<TX, TY, TZ>;

Open in new window

0
 

Author Comment

by:bovlk
ID: 34952399
Thanks, kaufmed. It's a very helpful solution. However, it's not exactly what I wanted since this is valid just inside the file in which it is declared. The C/C++ typedef is valid in any file into which I include that header. So is there any way to create a global alias valid throughout an entire ASP.NET application?
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 34956354
Not that I know of.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now