Ejemplo n.º 1
0
        public bool TryParse(HaloOnlineCacheContext cacheContext, List <string> args, out IBlamType result, out string error)
        {
            result = null;
            var argType  = this.GetType().GenericTypeArguments[0];
            var argCount = SetFieldCommand.RangeArgCount(argType);

            if (argCount * 2 != args.Count)
            {
                error = $"{args.Count} arguments supplied; should be {argCount * 2}";
                return(false);
            }

            var min = SetFieldCommand.ParseArgs(cacheContext, argType, null, args.Take(argCount).ToList());

            if (min.Equals(false))
            {
                error = $"{min} (min) is `false`";
                return(false);
            }

            var max = SetFieldCommand.ParseArgs(cacheContext, argType, null, args.Skip(argCount).Take(argCount).ToList());

            if (max.Equals(false))
            {
                error = $"{max} (max) is `false`";
                return(false);
            }

            result = Activator.CreateInstance(this.GetType(), new object[] { min, max }) as IBlamType;
            error  = null;
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the builder to set a field with the informed value.
        /// </summary>
        public FluentBuilder <T> WithFieldValue <TField>(TField newValue) where TField : class
        {
            var fieldName = typeof(TField).Name;

            _commands[fieldName] = new SetFieldCommand(_newObject, fieldName, newValue);
            return(this);
        }
Ejemplo n.º 3
0
        public bool TryParse(GameCache cache, List <string> args, out IBounds result, out string error)
        {
            result = null;
            error  = null;

            var argType  = GetType().GenericTypeArguments[0];
            var argCount = SetFieldCommand.RangeArgCount(argType);

            if (argCount * 2 != args.Count)
            {
                error = $"{args.Count} arguments supplied; should be {argCount * 2}";
                return(false);
            }

            var min = SetFieldCommand.ParseArgs(cache, argType, null, args.Take(argCount).ToList());
            var max = SetFieldCommand.ParseArgs(cache, argType, null, args.Skip(argCount).Take(argCount).ToList());

            if (min.Equals(false) || max.Equals(false))
            {
                error = $"Invalid value parsed.";
                return(false);
            }

            result = Activator.CreateInstance(this.GetType(), new object[] { min, max }) as IBounds;
            return(true);
        }
Ejemplo n.º 4
0
        public bool TryParse(HaloOnlineCacheContext cacheContext, List <string> args, out IBlamType result, out string error)
        {
            result = null;

            if (args.Count != 2)
            {
                error = $"{args.Count} arguments supplied; should be 2";
                return(false);
            }
            else
            {
                var cacheAddressType = SetFieldCommand.ParseArgs(cacheContext, typeof(CacheResourceAddressType), null, args.Take(1).ToList());
                if (!(cacheAddressType is CacheResourceAddressType))
                {
                    error = $"Failed to parse `{args[0]}` as `CacheAddressType`";
                    return(false);
                }
                else if (!int.TryParse(args[1], out int offset))
                {
                    error = $"Failed to parse `{args[1]}` as `int` (offset).";
                    return(false);
                }
                else
                {
                    result = new CacheResourceAddress((cacheAddressType as CacheResourceAddressType?).Value, offset);
                    error  = null;
                    return(true);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Configures the builder to set a private field with the dependency informed.
        /// </summary>
        public FluentBuilder <T> WithDependency <TServiceInterface, TServiceImplementation>(TServiceImplementation serviceImplementation)
            where TServiceImplementation : TServiceInterface
        {
            var fieldName = Regex.Replace(typeof(TServiceInterface).Name, "^I", "");

            _commands[fieldName] = new SetFieldCommand(_newObject, fieldName, serviceImplementation);
            return(this);
        }
Ejemplo n.º 6
0
        public void Should_set_a_field_when_value_inherits_from_field_type()
        {
            const string fieldName = "abstractField";
            var          newValue  = new ConcreteSampleType();
            var          command   = new SetFieldCommand(_object, fieldName, newValue);

            command.Execute();

            Assert.AreEqual(newValue, _object.abstractField);
        }
Ejemplo n.º 7
0
        public void Should_set_a_private_field()
        {
            const string fieldName = "privateField";
            const int    newValue  = 1;
            var          command   = new SetFieldCommand(_object, fieldName, newValue);

            command.Execute();

            Assert.AreEqual(newValue, _object.PropertyOnlyForTestingPurpose);
        }
Ejemplo n.º 8
0
        public void Should_set_a_public_field()
        {
            const string fieldName = "field";
            const int    newValue  = 1;
            var          command   = new SetFieldCommand(_object, fieldName, newValue);

            command.Execute();

            Assert.AreEqual(newValue, _object.field);
        }