GetPropertyInfo() public static method

public static GetPropertyInfo ( Mobile from, object &obj, string propertyName, PropertyAccess access, string &failReason ) : PropertyInfo
from Mobile
obj object
propertyName string
access PropertyAccess
failReason string
return System.Reflection.PropertyInfo
        public bool CheckCondition(object obj)
        {
            bool ret;

            string       failReason = null;
            PropertyInfo endProp    = Properties.GetPropertyInfo(ref obj, m_PropertyInfoChain, ref failReason);

            if (endProp == null)
            {
                return(false);
            }

            object current = endProp.GetValue(obj, null);

            switch (m_Operator)
            {
            case ConditionOperator.Equality:
                ret = Equality(current); break;

            case ConditionOperator.Inequality:
                ret = !Equality(current); break;

            case ConditionOperator.Greater:
                ret = (CompareWith(current) > 0); break;

            case ConditionOperator.GreaterEqual:
                ret = (CompareWith(current) >= 0); break;

            case ConditionOperator.Lesser:
                ret = (CompareWith(current) < 0); break;

            case ConditionOperator.LesserEqual:
                ret = (CompareWith(current) <= 0); break;

            case ConditionOperator.EqualityInsensitive:
                ret = (Insensitive.Equals(AsString(current), AsString(m_Argument))); break;

            case ConditionOperator.InequalityInsensitive:
                ret = (!Insensitive.Equals(AsString(current), AsString(m_Argument))); break;

            case ConditionOperator.StartsWith:
                ret = (AsString(current).StartsWith(AsString(m_Argument))); break;

            case ConditionOperator.StartsWithInsensitive:
                ret = (Insensitive.StartsWith(AsString(current), AsString(m_Argument))); break;

            case ConditionOperator.EndsWith:
                ret = (AsString(current).EndsWith(AsString(m_Argument))); break;

            case ConditionOperator.EndsWithInsensitive:
                ret = (Insensitive.EndsWith(AsString(current), AsString(m_Argument))); break;

            case ConditionOperator.Contains:
                ret = (AsString(current).IndexOf(AsString(m_Argument)) >= 0); break;

            case ConditionOperator.ContainsInsensitive:
                ret = (Insensitive.Contains(AsString(current), AsString(m_Argument))); break;

            default: return(false);
            }

            if (m_LogicalNot)
            {
                ret = !ret;
            }

            return(ret);
        }
Example #2
0
        public override void ExecuteList(CommandEventArgs e, ArrayList list)
        {
            if (list.Count == 0)
            {
                LogFailure("Nothing was found to use this command on.");
                return;
            }

            try
            {
                BaseCommand[]      commands  = new BaseCommand[BatchCommands.Count];
                CommandEventArgs[] eventArgs = new CommandEventArgs[BatchCommands.Count];

                for (int i = 0; i < BatchCommands.Count; ++i)
                {
                    BatchCommand bc = (BatchCommand)BatchCommands[i];

                    string   commandString, argString;
                    string[] args;

                    bc.GetDetails(out commandString, out argString, out args);

                    BaseCommand command = Scope.Commands[commandString];

                    commands[i]  = command;
                    eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args);

                    if (command == null)
                    {
                        e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier: {0}.", commandString);
                        return;
                    }
                    else if (e.Mobile.AccessLevel < command.AccessLevel)
                    {
                        e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString);
                        return;
                    }
                    else if (!command.ValidateArgs(Scope, eventArgs[i]))
                    {
                        return;
                    }
                }

                for (int i = 0; i < commands.Length; ++i)
                {
                    BaseCommand  command = commands[i];
                    BatchCommand bc      = (BatchCommand)BatchCommands[i];

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }

                    ArrayList usedList;

                    if (Utility.InsensitiveCompare(bc.Object, "Current") == 0)
                    {
                        usedList = list;
                    }
                    else
                    {
                        Hashtable propertyChains = new Hashtable();

                        usedList = new ArrayList(list.Count);

                        for (int j = 0; j < list.Count; ++j)
                        {
                            object obj = list[j];

                            if (obj == null)
                            {
                                continue;
                            }

                            Type type = obj.GetType();

                            PropertyInfo[] chain = (PropertyInfo[])propertyChains[type];

                            string failReason = "";

                            if (chain == null && !propertyChains.Contains(type))
                            {
                                propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason);
                            }

                            if (chain == null)
                            {
                                continue;
                            }

                            PropertyInfo endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason);

                            if (endProp == null)
                            {
                                continue;
                            }

                            try
                            {
                                obj = endProp.GetValue(obj, null);

                                if (obj != null)
                                {
                                    usedList.Add(obj);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    command.ExecuteList(eventArgs[i], usedList);

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = true;
                    }

                    command.Flush(e.Mobile, list.Count > 20);
                }
            }
            catch (Exception ex)
            {
                e.Mobile.SendMessage(ex.Message);
            }
        }
Example #3
0
        public override void ExecuteList(CommandEventArgs e, List <object> list)
        {
            if (list.Count == 0)
            {
                LogFailure("Nothing was found to use this command on.");
                return;
            }

            try
            {
                var commands  = new BaseCommand[BatchCommands.Count];
                var eventArgs = new CommandEventArgs[BatchCommands.Count];

                for (var i = 0; i < BatchCommands.Count; ++i)
                {
                    var bc = BatchCommands[i];

                    bc.GetDetails(out var commandString, out var argString, out var args);

                    var command = Scope.Commands[commandString];

                    commands[i]  = command;
                    eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args);

                    if (command == null)
                    {
                        e.Mobile.SendMessage(
                            "That is either an invalid command name or one that does not support this modifier: {0}.",
                            commandString
                            );
                        return;
                    }

                    if (e.Mobile.AccessLevel < command.AccessLevel)
                    {
                        e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString);
                        return;
                    }

                    if (!command.ValidateArgs(Scope, eventArgs[i]))
                    {
                        return;
                    }
                }

                for (var i = 0; i < commands.Length; ++i)
                {
                    var command = commands[i];
                    var bc      = BatchCommands[i];

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = false;
                    }

                    List <object> usedList;

                    if (Utility.InsensitiveCompare(bc.Object, "Current") == 0)
                    {
                        usedList = list;
                    }
                    else
                    {
                        var propertyChains = new Dictionary <Type, PropertyInfo[]>();

                        usedList = new List <object>(list.Count);

                        for (var j = 0; j < list.Count; ++j)
                        {
                            var obj = list[j];

                            if (obj == null)
                            {
                                continue;
                            }

                            var type       = obj.GetType();
                            var failReason = "";

                            if (!propertyChains.TryGetValue(type, out var chain))
                            {
                                propertyChains[type] = chain = Properties.GetPropertyInfoChain(
                                    e.Mobile,
                                    type,
                                    bc.Object,
                                    PropertyAccess.Read,
                                    ref failReason
                                    );
                            }

                            if (chain == null)
                            {
                                continue;
                            }

                            var endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason);

                            if (endProp == null)
                            {
                                continue;
                            }

                            try
                            {
                                obj = endProp.GetValue(obj, null);

                                if (obj != null)
                                {
                                    usedList.Add(obj);
                                }
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }

                    command.ExecuteList(eventArgs[i], usedList);

                    if (list.Count > 20)
                    {
                        CommandLogging.Enabled = true;
                    }

                    command.Flush(e.Mobile, list.Count > 20);
                }
            }
            catch (Exception ex)
            {
                e.Mobile.SendMessage(ex.Message);
            }
        }