Re: Generics in .net 2.0
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 Aug 2005 11:02:27 -0400
Søren,
You should be able to use generics here, on the method level. You could
declare the method as:
// Name it GetConfigValue, not getConfigValue, since
// it is a violation of the public naming guidelines.
public T GetConfigValue<T>(string key, T defaultValue)
{
// Get the value here, it should be returned as an object.
object retVal = ...;
// Cast the return value.
return (T) retVal;
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Søren Reinke" <soren@xxxxxxxxxxxxxxxxxx> wrote in message
news:de263k$7vt$1@xxxxxxxxxxxxxxxxxxxxxxx
>
> "billr" <billr@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:373E66FC-2F88-477F-BC16-D4D75836CFC0@xxxxxxxxxxxxxxxx
>> Personally, I would create an accessor for each type I expect to get out
>> of
>> the .config file ...
>>
>> GetInt()
>> GetDouble()
>> GetBoolean()
>
> That is what i have done, just interested in knowing if it was possible to
> do in Generics.
>
>
> --
> Best regards C.T.O. Søren Reinke
> www.Xray-Mag.com/ - Your free diving magazin on the net. Download it in
> Aug-sept issue of X-RAY Magazine is ready to download:
> EGYPT Finding Yolanda Wreck, Celebrate the Seas 2005
>
>>
>> etc.
>>
>> have a look at the post "Reccomended ways of saving WinForms'
>> "viewstate"?"
>> in group "microsoft.public.dotnet.framework.windowsforms" for a sample
>> .config file reader/writer
>>
>>
>> --
>> Of all words of tongue and pen, the saddest are: "It might have been"
>>
>> Bill.Richards @ greyskin .co .uk
>> http://greyskin.co.uk
>>
>>
>> "Søren Reinke" wrote:
>>
>>> Hi there
>>>
>>> I have a problem, with key/value pairs in web.config.
>>>
>>> The value is sometimes a boolean, sometimes an integer and sometimes a
>>> string and so on.
>>>
>>> Do i need to make a method for each type ?
>>> Or can i use generics ?
>>>
>>> I would like to be able to do something like:
>>>
>>> Integer age=getConfigValue("KeyName",17); //name,default value if
>>> something
>>> fails)
>>> Boolean productionServer=getConfigValue("onProductionServer",false);
>>>
>>> And more like that.
>>>
>>>
>>> --
>>> Best regards C.T.O. Søren Reinke
>>> www.Xray-Mag.com/ - Your free diving magazin on the net. Download it in
>>> Aug-sept issue of X-RAY Magazine is ready to download:
>>> EGYPT Finding Yolanda Wreck, Celebrate the Seas 2005
>>>
>>>
>>>
>
>
.
- Follow-Ups:
- Re: Generics in .net 2.0
- From: Ted Miller
- Re: Generics in .net 2.0
- References:
- Generics in .net 2.0
- From: Søren Reinke
- RE: Generics in .net 2.0
- From: billr
- Re: Generics in .net 2.0
- From: Søren Reinke
- Generics in .net 2.0
- Prev by Date: Re: Add ValueChanged event handler AFTER control is initialized
- Next by Date: Re: Looking for a decent data access architecture to implement
- Previous by thread: Re: Generics in .net 2.0
- Next by thread: Re: Generics in .net 2.0
- Index(es):