From e93c7fee4c52dabbec2bf9b54a63b35edc6b7ed0 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Sat, 9 May 2020 15:51:10 -0700 Subject: [PATCH] Share some code --- cfg/Config.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cfg/Config.cs b/cfg/Config.cs index 5dfc0f0..023ac19 100644 --- a/cfg/Config.cs +++ b/cfg/Config.cs @@ -69,13 +69,7 @@ namespace lib static public Config load( string filename ) { - FileStream fs = new FileStream( filename, FileMode.Open, FileAccess.Read ); - - XmlFormatter2 formatter = new XmlFormatter2(); - - Config cfg = (Config)formatter.Deserialize( fs ); - - return cfg; + return load( filename, null ); } static public T load( string filename ) where T : Config @@ -105,11 +99,11 @@ namespace lib //types[ 0 ] = typeof( string ); //parms[ 0 ] = filename; - ConstructorInfo cons = t.GetConstructor( types ); + ConstructorInfo cons = t?.GetConstructor( types ); try { - cfg = (Config)cons.Invoke( parms ); + cfg = (Config)cons?.Invoke( parms ); } catch( Exception e ) { @@ -126,7 +120,7 @@ namespace lib lib.Util.checkAndAddDirectory( dirName ); - lib.Log.info( $"Writing out template config of type {t.Name} in {templateFile}" ); + lib.Log.info( $"Writing out template config of type {t?.Name} in {templateFile}" ); Config.save( cfg, templateFile ); }