Ejemplo n.º 1
0
        private void GetAcceptableValues(AcceptableValueBase values)
        {
            var t        = values.GetType();
            var listProp = t.GetProperty(nameof(AcceptableValueList <bool> .AcceptableValues), BindingFlags.Instance | BindingFlags.Public);

            if (listProp != null)
            {
                AcceptableValues = ((IEnumerable)listProp.GetValue(values, null)).Cast <object>().ToArray();
            }
            else
            {
                var minProp = t.GetProperty(nameof(AcceptableValueRange <bool> .MinValue), BindingFlags.Instance | BindingFlags.Public);
                if (minProp != null)
                {
                    var maxProp = t.GetProperty(nameof(AcceptableValueRange <bool> .MaxValue), BindingFlags.Instance | BindingFlags.Public);
                    if (maxProp == null)
                    {
                        throw new ArgumentNullException(nameof(maxProp));
                    }
                    AcceptableValueRange = new KeyValuePair <object, object>(minProp.GetValue(values, null), maxProp.GetValue(values, null));
                    ShowRangeAsPercent   = (AcceptableValueRange.Key.Equals(0) || AcceptableValueRange.Key.Equals(1)) && AcceptableValueRange.Value.Equals(100) ||
                                           AcceptableValueRange.Key.Equals(0f) && AcceptableValueRange.Value.Equals(1f);
                }
            }
        }
Ejemplo n.º 2
0
        private static bool TryAcceptableValueList(
            AcceptableValueBase valueBase,
            out Type valueType,
            out object[] values)
        {
            values    = null;
            valueType = null;
            if (valueBase == null)
            {
                return(false);
            }

            var type = valueBase.GetType();

            if (type.GetGenericTypeDefinition() != typeof(AcceptableValueList <>))
            {
                return(false);
            }

            valueType = type.GetGenericArguments()[0];

            // ReSharper disable once PossibleNullReferenceException
            var helper = typeof(GeneratedOI)
                         .GetMethod(nameof(AcceptableValueListHelper), BindingFlags.Static | BindingFlags.NonPublic)
                         .MakeGenericMethod(valueType);

            values = (object[])helper.Invoke(null, new object[] { valueBase });
            return(true);
        }
Ejemplo n.º 3
0
 public AutoItemConfigAttribute(AutoItemConfigFlags flags = AutoItemConfigFlags.None, params object[] acceptableValues)
 {
     if (acceptableValues.Length > 0)
     {
         var avList = (flags & AutoItemConfigFlags.AVIsList) == AutoItemConfigFlags.AVIsList;
         if (!avList && acceptableValues.Length != 2)
         {
             throw new ArgumentException("Range mode for acceptableValues (flag AVIsList not set) requires either 0 or 2 params; received " + acceptableValues.Length + ".\nThe description provided was: \"" + desc + "\".");
         }
         var iType = acceptableValues[0].GetType();
         for (var i = 1; i < acceptableValues.Length; i++)
         {
             if (iType != acceptableValues[i].GetType())
             {
                 throw new ArgumentException("Types of all acceptableValues must match");
             }
         }
         var avbVariety = avList ? typeof(AcceptableValueList <>).MakeGenericType(iType) : typeof(AcceptableValueRange <>).MakeGenericType(iType);
         this.avb     = (AcceptableValueBase)Activator.CreateInstance(avbVariety, acceptableValues);
         this.avbType = iType;
     }
     this.flags = flags;
 }
Ejemplo n.º 4
0
 public ValueBuilder Range(float min, float max)
 {
     Assert.IsFalse(bound, "Already bound this Key");
     this.range = new AcceptableValueRange <float>(min, max);
     return(this);
 }
Ejemplo n.º 5
0
 public ValueBuilder Range(AcceptableValueBase range)
 {
     Assert.IsFalse(bound, "Already bound this Key");
     this.range = range;
     return(this);
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Create a new description.
 /// </summary>
 /// <param name="description">Text describing the function of the setting and any notes or warnings.</param>
 /// <param name="acceptableValues">
 ///     Range of values that this setting can take. The setting's value will be automatically
 ///     clamped.
 /// </param>
 /// <param name="tags">Objects that can be used by user-made classes to add functionality.</param>
 public ConfigDescription(string description, AcceptableValueBase acceptableValues = null, params object[] tags)
 {
     AcceptableValues = acceptableValues;
     Tags             = tags;
     Description      = description ?? throw new ArgumentNullException(nameof(description));
 }