Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generics

Status
Not open for further replies.

Badgers

Programmer
Nov 20, 2001
187
US
Hi,

I am storing a number of global params in a console app populated from a db.

I'm thnking of using a list to store variable name / variable type.

The variable can obviously vary, for eg string, int etc.

What would the syntax be on the class and what syntax would you use to type the variable type generic.

Thanks


 
what does this have to do with webforms or asp.net?

As for access the configs. I would create a class with the properties you need to expose. no generics required.
Code:
class GolbalSettings
{
   public int Number {get;set;}
   public string String {get;set;}
   public DateTime Date {get;set;}
}
if you require a fully dynamic solution with strongly typed values it might look something like this
Code:
class GolbalSettings
{
   private HashTable table = new HashTable();

   public void Set<T>(object key, T value)
   {
       table[key] = value;
   }
   public void Get<T>(object key)
   {
       return table[key];
   }
}

class Key<T>
{
     private readonly object identifier;

     public class Key(object identifier)
     {
         this.identifier = identifier;
     }

     public T PullFrom(GolbalSettings settings)
     {
         return settings.Get(identifier);
     }

     public void PutInto(GolbalSettings settings, T value)
     {
         settings.Set(identifier, value);
     }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Jason,

I have a dabbled with your explanation and can't get it running properly.

Any chance you could have a revisit....

Thanks

 
what isn't working? all the cod above was written off the top of my head.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top