relax ObjectCreator.Param requirement on non-renamed args

This commit is contained in:
Chris Forbes
2011-10-21 17:38:00 +13:00
parent 88bfee872f
commit 4c8e048c2c

View File

@@ -52,7 +52,10 @@ namespace OpenRA
{ {
var type = mod.First.GetType( mod.Second + "." + className, false ); var type = mod.First.GetType( mod.Second + "." + className, false );
if( type == null ) continue; if( type == null ) continue;
var ctors = type.GetConstructors( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ).Where( x => x.HasAttribute<UseCtorAttribute>() ).ToList(); var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
var ctors = type.GetConstructors( flags )
.Where( x => x.HasAttribute<UseCtorAttribute>() ).ToList();
if( ctors.Count == 0 ) if( ctors.Count == 0 )
return (T)CreateBasic( type ); return (T)CreateBasic( type );
else if( ctors.Count == 1 ) else if( ctors.Count == 1 )
@@ -75,9 +78,8 @@ namespace OpenRA
var a = new object[ p.Length ]; var a = new object[ p.Length ];
for( int i = 0 ; i < p.Length ; i++ ) for( int i = 0 ; i < p.Length ; i++ )
{ {
var attrs = p[ i ].GetCustomAttributes<ParamAttribute>(); var attr = p[ i ].GetCustomAttributes<ParamAttribute>().FirstOrDefault();
if( attrs.Length != 1 ) throw new InvalidOperationException( "ObjectCreator: argument in [UseCtor] doesn't have [Param]" ); var key = (attr != null ? attr.ParamName : null) ?? p[i].Name;
var key = attrs[ 0 ].ParamName ?? p[i].Name;
if ( !args.ContainsKey(key) ) throw new InvalidOperationException("ObjectCreator: key `{0}' not found".F(key)); if ( !args.ContainsKey(key) ) throw new InvalidOperationException("ObjectCreator: key `{0}' not found".F(key));
a[ i ] = args[ key ]; a[ i ] = args[ key ];
} }