Changes properties to use automatic property initializers

This commit is contained in:
Kamron Batman 2018-09-14 15:23:29 -07:00
parent f0a48ad431
commit 06fa31a7bf
623 changed files with 13072 additions and 19304 deletions

View file

@ -8,40 +8,31 @@ namespace Server.Commands.Generic
public sealed class ExtensionInfo
{
private static Dictionary<string, ExtensionInfo> m_Table = new Dictionary<string, ExtensionInfo>( StringComparer.InvariantCultureIgnoreCase );
public static Dictionary<string, ExtensionInfo> Table => m_Table;
public static Dictionary<string, ExtensionInfo> Table { get; } = new Dictionary<string, ExtensionInfo>( StringComparer.InvariantCultureIgnoreCase );
public static void Register( ExtensionInfo ext )
{
m_Table[ext.m_Name] = ext;
Table[ext.Name] = ext;
}
private int m_Order;
public int Order { get; }
private string m_Name;
private int m_Size;
public string Name { get; }
private ExtensionConstructor m_Constructor;
public int Size { get; }
public int Order => m_Order;
public bool IsFixedSize => ( Size >= 0 );
public string Name => m_Name;
public int Size => m_Size;
public bool IsFixedSize => ( m_Size >= 0 );
public ExtensionConstructor Constructor => m_Constructor;
public ExtensionConstructor Constructor { get; }
public ExtensionInfo( int order, string name, int size, ExtensionConstructor constructor )
{
m_Name = name;
m_Size = size;
Name = name;
Size = size;
m_Order = order;
Order = order;
m_Constructor = constructor;
Constructor = constructor;
}
}

View file

@ -40,52 +40,48 @@ namespace Server.Commands.Generic
public sealed class PropertyValue
{
private Type m_Type;
private object m_Value;
private FieldInfo m_Field;
public Type Type { get; }
public Type Type => m_Type;
public object Value { get; private set; }
public object Value => m_Value;
public FieldInfo Field { get; private set; }
public FieldInfo Field => m_Field;
public bool HasField => ( m_Field != null );
public bool HasField => ( Field != null );
public PropertyValue( Type type, object value )
{
m_Type = type;
m_Value = value;
Type = type;
Value = value;
}
public void Load( MethodEmitter method )
{
if ( m_Field != null )
if ( Field != null )
{
method.LoadArgument( 0 );
method.LoadField( m_Field );
method.LoadField( Field );
}
else if ( m_Value == null )
else if ( Value == null )
{
method.LoadNull( m_Type );
method.LoadNull( Type );
}
else
{
if ( m_Value is int i )
if ( Value is int i )
method.Load( i );
else if ( m_Value is long l )
else if ( Value is long l )
method.Load( l );
else if ( m_Value is float f )
else if ( Value is float f )
method.Load( f );
else if ( m_Value is double d )
else if ( Value is double d )
method.Load( d );
else if ( m_Value is char c )
else if ( Value is char c )
method.Load( c );
else if ( m_Value is bool b )
else if ( Value is bool b )
method.Load( b );
else if ( m_Value is string s )
else if ( Value is string s )
method.Load( s );
else if ( m_Value is Enum e )
else if ( Value is Enum e )
method.Load( e );
else
throw new InvalidOperationException( "Unrecognized comparison value." );
@ -94,29 +90,29 @@ namespace Server.Commands.Generic
public void Acquire( TypeBuilder typeBuilder, ILGenerator il, string fieldName )
{
if ( m_Value is string toParse )
if ( Value is string toParse )
{
if ( !m_Type.IsValueType && toParse == "null" )
if ( !Type.IsValueType && toParse == "null" )
{
m_Value = null;
Value = null;
}
else if ( m_Type == typeof( string ) )
else if ( Type == typeof( string ) )
{
if ( toParse == @"@""null""" )
toParse = "null";
m_Value = toParse;
Value = toParse;
}
else if ( m_Type.IsEnum )
else if ( Type.IsEnum )
{
m_Value = Enum.Parse( m_Type, toParse, true );
Value = Enum.Parse( Type, toParse, true );
}
else
{
MethodInfo parseMethod = null;
object[] parseArgs = null;
MethodInfo parseNumber = m_Type.GetMethod(
MethodInfo parseNumber = Type.GetMethod(
"Parse",
BindingFlags.Public | BindingFlags.Static,
null,
@ -139,7 +135,7 @@ namespace Server.Commands.Generic
}
else
{
MethodInfo parseGeneral = m_Type.GetMethod(
MethodInfo parseGeneral = Type.GetMethod(
"Parse",
BindingFlags.Public | BindingFlags.Static,
null,
@ -153,13 +149,13 @@ namespace Server.Commands.Generic
if ( parseMethod != null )
{
m_Value = parseMethod.Invoke( null, parseArgs );
Value = parseMethod.Invoke( null, parseArgs );
if ( !m_Type.IsPrimitive )
if ( !Type.IsPrimitive )
{
m_Field = typeBuilder.DefineField(
Field = typeBuilder.DefineField(
fieldName,
m_Type,
Type,
FieldAttributes.Private | FieldAttributes.InitOnly
);
@ -171,13 +167,13 @@ namespace Server.Commands.Generic
il.Emit( OpCodes.Ldc_I4, (int) parseArgs[1] );
il.Emit( OpCodes.Call, parseMethod );
il.Emit( OpCodes.Stfld, m_Field );
il.Emit( OpCodes.Stfld, Field );
}
}
else
{
throw new InvalidOperationException(
$"Unable to convert string \"{m_Value}\" into type '{m_Type}'."
$"Unable to convert string \"{Value}\" into type '{Type}'."
);
}
}

View file

@ -7,14 +7,9 @@ namespace Server.Commands.Generic
{
public sealed class OrderInfo
{
private Property m_Property;
private int m_Order;
public Property Property
{
get => m_Property;
set => m_Property = value;
}
public Property Property { get; set; }
public bool IsAscending
{
@ -42,7 +37,7 @@ namespace Server.Commands.Generic
public OrderInfo( Property property, bool isAscending )
{
m_Property = property;
Property = property;
IsAscending = isAscending;
}

View file

@ -14,9 +14,7 @@ namespace Server.Commands.Generic
public override ExtensionInfo Info => ExtInfo;
private int m_Limit;
public int Limit => m_Limit;
public int Limit { get; private set; }
public LimitExtension()
{
@ -24,16 +22,16 @@ namespace Server.Commands.Generic
public override void Parse( Mobile from, string[] arguments, int offset, int size )
{
m_Limit = Utility.ToInt32( arguments[offset] );
Limit = Utility.ToInt32( arguments[offset] );
if ( m_Limit < 0 )
if ( Limit < 0 )
throw new Exception( "Limit cannot be less than zero." );
}
public override void Filter( ArrayList list )
{
if ( list.Count > m_Limit )
list.RemoveRange( m_Limit, list.Count - m_Limit );
if ( list.Count > Limit )
list.RemoveRange( Limit, list.Count - Limit );
}
}
}

View file

@ -13,9 +13,7 @@ namespace Server.Commands.Generic
public override ExtensionInfo Info => ExtInfo;
private ObjectConditional m_Conditional;
public ObjectConditional Conditional => m_Conditional;
public ObjectConditional Conditional { get; private set; }
public WhereExtension()
{
@ -26,7 +24,7 @@ namespace Server.Commands.Generic
if ( baseType == null )
throw new InvalidOperationException( "Insanity." );
m_Conditional.Compile( ref assembly );
Conditional.Compile( ref assembly );
}
public override void Parse( Mobile from, string[] arguments, int offset, int size )
@ -34,12 +32,12 @@ namespace Server.Commands.Generic
if ( size < 1 )
throw new Exception( "Invalid condition syntax." );
m_Conditional = ObjectConditional.ParseDirect( from, arguments, offset, size );
Conditional = ObjectConditional.ParseDirect( from, arguments, offset, size );
}
public override bool IsValid( object obj )
{
return m_Conditional.CheckCondition( obj );
return Conditional.CheckCondition( obj );
}
}
}