Share some code

This commit is contained in:
Marc Hernandez 2020-05-09 15:51:10 -07:00
parent 6e2e40dee3
commit e93c7fee4c

View File

@ -69,13 +69,7 @@ namespace lib
static public Config load( string filename ) static public Config load( string filename )
{ {
FileStream fs = new FileStream( filename, FileMode.Open, FileAccess.Read ); return load( filename, null );
XmlFormatter2 formatter = new XmlFormatter2();
Config cfg = (Config)formatter.Deserialize( fs );
return cfg;
} }
static public T load<T>( string filename ) where T : Config static public T load<T>( string filename ) where T : Config
@ -105,11 +99,11 @@ namespace lib
//types[ 0 ] = typeof( string ); //types[ 0 ] = typeof( string );
//parms[ 0 ] = filename; //parms[ 0 ] = filename;
ConstructorInfo cons = t.GetConstructor( types ); ConstructorInfo cons = t?.GetConstructor( types );
try try
{ {
cfg = (Config)cons.Invoke( parms ); cfg = (Config)cons?.Invoke( parms );
} }
catch( Exception e ) catch( Exception e )
{ {
@ -126,7 +120,7 @@ namespace lib
lib.Util.checkAndAddDirectory( dirName ); 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 ); Config.save( cfg, templateFile );
} }