Type Information

  • Thread starter Thread starter Paul Cavacas
  • Start date Start date
P

Paul Cavacas

I have an abstract class MasterReportColumn. I then
have several classes that inherit from this a few
examples are InvoicedCasesColumn and QuotaCasesColumn. I
then have another Column that inherits from
MasterReportColumn called MasterPercentColumn. The
constructurer for this column takes 2 string (which are
the class names of the 2 columns to use when calculating
the percentage).

What happens is a bunch of columns are added to the a
collection and when it goes to figure out the percent it
loops through the collection looking for the 2 columns in
the collection, which may or may not be there. If they
are not there the missing column(s) is added to the
collection.

So my problem is I have another column that inherits
from MasterPercentColumn called
InvoicedCasesVsQuotaColumn. Now in the new I could
manually type in the string of the other class names,
i.e. InvoicedCasesColumn and QuotaCasesColumn, but this
is prone to typos. So I'm trying to find another way to
implement this. I could create a new instance of the
InvoicedCasesColumn and do GetType.Name on that, but I
really don't want to create a new instance of these
columns just to get the name of them. Does anybody have
another idea on how this can be implemented.
 
You do not need an instance to get a type. You can use something like:
Type t = typeof(YourCustomType);
System.Console.WriteLine("typename= " + t.Name);

-Dino
 
Back
Top