DataAccessAdatper.ReadHandleCatalogNameSettingFromConfig()

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 13-Jul-2006 13:18:52   

I don't like this line very much simple_smile

CatalogNameUsage catalogNameUsageSetting = (CatalogNameUsage)(int)configReader.GetValue("CatalogNameUsageSetting", typeof(int));

The problem with it is, that it would throw an (internal) exception when there is no CatalogNameUsageSetting defined which is a problem: - if you have debugger set to catch thrown exceptions - performance (not a huge one of course)

I would preffer something like this: string value = ConfigurationManager.AppSettings["CatalogNameUsageSetting"]; if (value != null) { CatalogNameUsage catalogNameUsageSetting = (CatalogNameUsage)Convert.ToInt32(value);

The only downside is that you have to include System.Configuration assembly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 13-Jul-2006 17:02:34   

2 downsides: 1) it won't work in .net 1.x (but that's of course not your problem wink ) 2) you've to link to system.configuration. This is a separate dll, which has to be deployed as well. That last thing was something I wanted to avoid as it is a cause for errors easily made and hard to track down.

Hence the 'swallow the exception' solution. Something which I find MS' problem as they mis-designed the .net 1.x appsettings reader code

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 13-Jul-2006 20:20:58   

Otis wrote:

2 downsides: 1) it won't work in .net 1.x (but that's of course not your problem wink )

Right, this is applicable only to 2005 templates.

Otis wrote:

2) you've to link to system.configuration. This is a separate dll, which has to be deployed as well. That last thing was something I wanted to avoid as it is a cause for errors easily made and hard to track down.

Isn't System.Configuration a part of .net 2 and there is no need for deployment?

Otis wrote:

Hence the 'swallow the exception' solution. Something which I find MS' problem as they mis-designed the .net 1.x appsettings reader code

Actually there is another way in .net 1.x: ConfigurationSettings.AppSettings which yields a string that can be null.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 13-Jul-2006 21:18:36   

mihies wrote:

Otis wrote:

2) you've to link to system.configuration. This is a separate dll, which has to be deployed as well. That last thing was something I wanted to avoid as it is a cause for errors easily made and hard to track down.

Isn't System.Configuration a part of .net 2 and there is no need for deployment?

Sometimes I'm so surprised of myself how I can state such obvious silly remarks. You're absolutely right flushed The referencing of the dll is however a problem, not a big one though but there.

Otis wrote:

Hence the 'swallow the exception' solution. Something which I find MS' problem as they mis-designed the .net 1.x appsettings reader code

Actually there is another way in .net 1.x: ConfigurationSettings.AppSettings which yields a string that can be null.

Hmm interesting. Will check it out.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 13-Jul-2006 22:29:15   

Sometimes I'm so surprised of myself how I can state such obvious silly remarks. You're absolutely right The referencing of the dll is however a problem, not a big one though but there.

Actually, you are omni-present. I wonder how you can answer all these posts with such knowledge and accuracy. Hey, even the best make mistakes. simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 16-Jul-2006 13:30:10   

ConfigurationSettings.AppSettings is deprecated in .net 2.0. Yay disappointed

I saw the .net runtimes used the exception swallow technique when determining the connectionstring, I've changed that. However I can't change the .net 2.0 templates, as that would give incompilable code when the code is re-generated. Will add it to the todo list for the first next version.

Frans Bouma | Lead developer LLBLGen Pro