Changes properties to use automatic property initializers
This commit is contained in:
parent
f0a48ad431
commit
06fa31a7bf
623 changed files with 13072 additions and 19304 deletions
|
|
@ -14,55 +14,19 @@ namespace Server.Commands.Generic
|
|||
|
||||
public abstract class BaseCommand
|
||||
{
|
||||
private string[] m_Commands;
|
||||
private AccessLevel m_AccessLevel;
|
||||
private CommandSupport m_Implementors;
|
||||
private ObjectTypes m_ObjectTypes;
|
||||
private bool m_ListOptimized;
|
||||
private string m_Usage;
|
||||
private string m_Description;
|
||||
public bool ListOptimized { get; set; }
|
||||
|
||||
public bool ListOptimized
|
||||
{
|
||||
get => m_ListOptimized;
|
||||
set => m_ListOptimized = value;
|
||||
}
|
||||
public string[] Commands { get; set; }
|
||||
|
||||
public string[] Commands
|
||||
{
|
||||
get => m_Commands;
|
||||
set => m_Commands = value;
|
||||
}
|
||||
public string Usage { get; set; }
|
||||
|
||||
public string Usage
|
||||
{
|
||||
get => m_Usage;
|
||||
set => m_Usage = value;
|
||||
}
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => m_Description;
|
||||
set => m_Description = value;
|
||||
}
|
||||
public AccessLevel AccessLevel { get; set; }
|
||||
|
||||
public AccessLevel AccessLevel
|
||||
{
|
||||
get => m_AccessLevel;
|
||||
set => m_AccessLevel = value;
|
||||
}
|
||||
public ObjectTypes ObjectTypes { get; set; }
|
||||
|
||||
public ObjectTypes ObjectTypes
|
||||
{
|
||||
get => m_ObjectTypes;
|
||||
set => m_ObjectTypes = value;
|
||||
}
|
||||
|
||||
public CommandSupport Supports
|
||||
{
|
||||
get => m_Implementors;
|
||||
set => m_Implementors = value;
|
||||
}
|
||||
public CommandSupport Supports { get; set; }
|
||||
|
||||
public BaseCommand()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,13 +58,11 @@ namespace Server.Commands.Generic
|
|||
Register( new TraceLockdownCommand() );
|
||||
}
|
||||
|
||||
private static List<BaseCommand> m_AllCommands = new List<BaseCommand>();
|
||||
|
||||
public static List<BaseCommand> AllCommands => m_AllCommands;
|
||||
public static List<BaseCommand> AllCommands { get; } = new List<BaseCommand>();
|
||||
|
||||
public static void Register( BaseCommand command )
|
||||
{
|
||||
m_AllCommands.Add( command );
|
||||
AllCommands.Add( command );
|
||||
|
||||
List<BaseCommandImplementor> impls = BaseCommandImplementor.Implementors;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}'."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ namespace Server.Commands.Generic
|
|||
{
|
||||
public class AreaCommandImplementor : BaseCommandImplementor
|
||||
{
|
||||
private static AreaCommandImplementor m_Instance;
|
||||
|
||||
public static AreaCommandImplementor Instance => m_Instance;
|
||||
public static AreaCommandImplementor Instance { get; private set; }
|
||||
|
||||
public AreaCommandImplementor()
|
||||
{
|
||||
|
|
@ -18,7 +16,7 @@ namespace Server.Commands.Generic
|
|||
Usage = "Area <command> [condition]";
|
||||
Description = "Invokes the command on all appropriate objects in a targeted area. Optional condition arguments can further restrict the set of objects.";
|
||||
|
||||
m_Instance = this;
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void Process( Mobile from, BaseCommand command, string[] args )
|
||||
|
|
|
|||
|
|
@ -47,55 +47,23 @@ namespace Server.Commands.Generic
|
|||
Register( new FacetCommandImplementor() );
|
||||
}
|
||||
|
||||
private string[] m_Accessors;
|
||||
private AccessLevel m_AccessLevel;
|
||||
private CommandSupport m_SupportRequirement;
|
||||
private Dictionary<string, BaseCommand> m_Commands;
|
||||
private string m_Usage;
|
||||
private string m_Description;
|
||||
private bool m_SupportsConditionals;
|
||||
public bool SupportsConditionals { get; set; }
|
||||
|
||||
public bool SupportsConditionals
|
||||
{
|
||||
get => m_SupportsConditionals;
|
||||
set => m_SupportsConditionals = value;
|
||||
}
|
||||
public string[] Accessors { get; set; }
|
||||
|
||||
public string[] Accessors
|
||||
{
|
||||
get => m_Accessors;
|
||||
set => m_Accessors = value;
|
||||
}
|
||||
public string Usage { get; set; }
|
||||
|
||||
public string Usage
|
||||
{
|
||||
get => m_Usage;
|
||||
set => m_Usage = value;
|
||||
}
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => m_Description;
|
||||
set => m_Description = value;
|
||||
}
|
||||
public AccessLevel AccessLevel { get; set; }
|
||||
|
||||
public AccessLevel AccessLevel
|
||||
{
|
||||
get => m_AccessLevel;
|
||||
set => m_AccessLevel = value;
|
||||
}
|
||||
public CommandSupport SupportRequirement { get; set; }
|
||||
|
||||
public CommandSupport SupportRequirement
|
||||
{
|
||||
get => m_SupportRequirement;
|
||||
set => m_SupportRequirement = value;
|
||||
}
|
||||
|
||||
public Dictionary<string, BaseCommand> Commands => m_Commands;
|
||||
public Dictionary<string, BaseCommand> Commands { get; }
|
||||
|
||||
public BaseCommandImplementor()
|
||||
{
|
||||
m_Commands = new Dictionary<string, BaseCommand>( StringComparer.OrdinalIgnoreCase );
|
||||
Commands = new Dictionary<string, BaseCommand>( StringComparer.OrdinalIgnoreCase );
|
||||
}
|
||||
|
||||
public virtual void Compile( Mobile from, BaseCommand command, ref string[] args, ref object obj )
|
||||
|
|
@ -106,7 +74,7 @@ namespace Server.Commands.Generic
|
|||
public virtual void Register( BaseCommand command )
|
||||
{
|
||||
for ( int i = 0; i < command.Commands.Length; ++i )
|
||||
m_Commands[command.Commands[i]] = command;
|
||||
Commands[command.Commands[i]] = command;
|
||||
}
|
||||
|
||||
public bool CheckObjectTypes( Mobile from, BaseCommand command, Extensions ext, out bool items, out bool mobiles )
|
||||
|
|
@ -274,7 +242,7 @@ namespace Server.Commands.Generic
|
|||
{
|
||||
if ( e.Length >= 1 )
|
||||
{
|
||||
m_Commands.TryGetValue( e.GetString( 0 ), out BaseCommand command );
|
||||
Commands.TryGetValue( e.GetString( 0 ), out BaseCommand command );
|
||||
|
||||
if ( command == null )
|
||||
{
|
||||
|
|
@ -303,11 +271,11 @@ namespace Server.Commands.Generic
|
|||
|
||||
public void Register()
|
||||
{
|
||||
if ( m_Accessors == null )
|
||||
if ( Accessors == null )
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < m_Accessors.Length; ++i )
|
||||
CommandSystem.Register( m_Accessors[i], m_AccessLevel, Execute );
|
||||
for ( int i = 0; i < Accessors.Length; ++i )
|
||||
CommandSystem.Register( Accessors[i], AccessLevel, Execute );
|
||||
}
|
||||
|
||||
public static void Register( BaseCommandImplementor impl )
|
||||
|
|
|
|||
|
|
@ -9,17 +9,15 @@ namespace Server.Commands.Generic
|
|||
private static readonly Type typeofItem = typeof( Item );
|
||||
private static readonly Type typeofMobile = typeof( Mobile );
|
||||
|
||||
private Type m_ObjectType;
|
||||
|
||||
private ICondition[][] m_Conditions;
|
||||
|
||||
private IConditional[] m_Conditionals;
|
||||
|
||||
public Type Type => m_ObjectType;
|
||||
public Type Type { get; }
|
||||
|
||||
public bool IsItem => ( m_ObjectType == null || m_ObjectType == typeofItem || m_ObjectType.IsSubclassOf( typeofItem ) );
|
||||
public bool IsItem => ( Type == null || Type == typeofItem || Type.IsSubclassOf( typeofItem ) );
|
||||
|
||||
public bool IsMobile => ( m_ObjectType == null || m_ObjectType == typeofMobile || m_ObjectType.IsSubclassOf( typeofMobile ) );
|
||||
public bool IsMobile => ( Type == null || Type == typeofMobile || Type.IsSubclassOf( typeofMobile ) );
|
||||
|
||||
public static readonly ObjectConditional Empty = new ObjectConditional( null, null );
|
||||
|
||||
|
|
@ -33,12 +31,12 @@ namespace Server.Commands.Generic
|
|||
m_Conditionals = new IConditional[m_Conditions.Length];
|
||||
|
||||
for ( int i = 0; i < m_Conditionals.Length; ++i )
|
||||
m_Conditionals[i] = ConditionalCompiler.Compile( emitter, m_ObjectType, m_Conditions[i], i );
|
||||
m_Conditionals[i] = ConditionalCompiler.Compile( emitter, Type, m_Conditions[i], i );
|
||||
}
|
||||
|
||||
public bool CheckCondition( object obj )
|
||||
{
|
||||
if ( m_ObjectType == null )
|
||||
if ( Type == null )
|
||||
return true; // null type means no condition
|
||||
|
||||
if ( !HasCompiled )
|
||||
|
|
@ -243,7 +241,7 @@ namespace Server.Commands.Generic
|
|||
|
||||
public ObjectConditional( Type objectType, ICondition[][] conditions )
|
||||
{
|
||||
m_ObjectType = objectType;
|
||||
Type = objectType;
|
||||
m_Conditions = conditions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ namespace Server.Commands.Generic
|
|||
{
|
||||
public class RangeCommandImplementor : BaseCommandImplementor
|
||||
{
|
||||
private static RangeCommandImplementor m_Instance;
|
||||
|
||||
public static RangeCommandImplementor Instance => m_Instance;
|
||||
public static RangeCommandImplementor Instance { get; private set; }
|
||||
|
||||
public RangeCommandImplementor()
|
||||
{
|
||||
|
|
@ -15,7 +13,7 @@ namespace Server.Commands.Generic
|
|||
Usage = "Range <range> <command> [condition]";
|
||||
Description = "Invokes the command on all appropriate objects within a specified range of you. Optional condition arguments can further restrict the set of objects.";
|
||||
|
||||
m_Instance = this;
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void Execute( CommandEventArgs e )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue