Ejemplo n.º 1
0
            public string HelpText()
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat(@"Usage: {0} ", System.IO.Path.GetFileName(this.GetType().Assembly.CodeBase));

                string        indent  = @"    ";
                StringBuilder details = new StringBuilder();

                foreach (FieldInfo fi in this.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
                {
                    foreach (object o in fi.GetCustomAttributes(false))
                    {
                        if (o is OptionAttribute)
                        {
                            OptionAttribute opt = o as OptionAttribute;

                            sb.AppendFormat(@"{0}-{1} {2}{3} ", opt.Required ? @"" : @"[", opt.ShortName, opt.LongName, opt.Required ? @"" : @"]");

                            details.Append(indent);
                            details.AppendLine(string.Format(@"-{0}: {2}. {3} (long form {1}, default is '{4}')", opt.ShortName, opt.LongName, opt.Required ? @"Required" : @"Optional", opt.HelpText, fi.GetValue(this)));
                            break;
                        }

                        if (o is ValueListAttribute)
                        {
                            ValueListAttribute vl = o as ValueListAttribute;
                            sb.AppendFormat(@"{0} [0..{1}] ", fi.Name, vl.MaximumElements == -1 ? @"*" : vl.MaximumElements.ToString());
                            break;
                        }
                    }
                }

                return(sb.ToString());
            }
Ejemplo n.º 2
0
 private void InitializeValueList()
 {
     _valueListAttribute = ValueListAttribute.GetAttribute(_target);
     if (IsValueListDefined)
     {
         _valueList = ValueListAttribute.GetReference(_target);
     }
 }
Ejemplo n.º 3
0
 public TargetWrapper(object target)
 {
     _target = target;
     _vla = ValueListAttribute.GetAttribute(_target);
     if (IsValueListDefined)
     {
         _valueList = ValueListAttribute.GetReference(_target);
     }
 }
        public void GetGenericListOfStringInterfaceReference()
        {
            var options = new MockOptions();

            IList <string> values = ValueListAttribute.GetReference(options);

            Assert.IsNotNull(values);
            Assert.AreEqual(typeof(List <string>), values.GetType());
        }
        public void Get_generic_list_of_string_interface_reference()
        {
            var options = new MockOptions();

            IList <string> values = ValueListAttribute.GetReference(options);

            values.Should().NotBeNull();
            values.GetType().Should().Be(typeof(List <string>));
        }
        public void Use_generic_list_of_string_interface_reference()
        {
            var options = new MockOptions();

            var values = ValueListAttribute.GetReference(options);

            values.Add("value0");
            values.Add("value1");
            values.Add("value2");

            base.ElementsShouldBeEqual(new string[] { "value0", "value1", "value2" }, options.Values);
        }
        public void UseGenericListOfStringInterfaceReference()
        {
            MockOptions options = new MockOptions();

            IList <string> values = ValueListAttribute.GetReference(options);

            values.Add("value0");
            values.Add("value1");
            values.Add("value2");

            Assert.AreEqual("value0", options.Values[0]);
            Assert.AreEqual("value1", options.Values[1]);
            Assert.AreEqual("value2", options.Values[2]);
        }
        public void UseGenericListOfStringInterfaceReference()
        {
            var options = new MockOptions();

            var values = ValueListAttribute.GetReference(options);

            values.Add("value0");
            values.Add("value1");
            values.Add("value2");

            //Assert.AreEqual("value0", options.Values[0]);
            //Assert.AreEqual("value1", options.Values[1]);
            //Assert.AreEqual("value2", options.Values[2]);
            base.AssertArrayItemEqual(new string[] { "value0", "value1", "value2" }, options.Values);
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ValueListAttribute valueList = attribute as ValueListAttribute;

        if (property.propertyType == SerializedPropertyType.Integer)
        {
            var values  = valueList.ValueList;
            var display = new List <string>();
            foreach (var v in values)
            {
                display.Add(v.ToString());
            }
            property.intValue = EditorGUI.IntPopup(position, label.text, property.intValue, display.ToArray(), values);
        }
        else
        {
            EditorGUI.LabelField(position, label.text, "Use ValueList with int.");
        }
    }
Ejemplo n.º 10
0
        private static OptionKind GetValueKind19(BaseOptionAttribute option, ValueOptionAttribute value, ValueListAttribute valueList)
        {
            switch (option)
            {
            case OptionAttribute _:
            case HelpOptionAttribute _:
                return(OptionKind.Single);

            case OptionArrayAttribute _:
                return(OptionKind.Array);

            case OptionListAttribute _:
                return(OptionKind.List);

            case VerbOptionAttribute _:
            case HelpVerbOptionAttribute _:
                return(OptionKind.Verb);

            default:
                if (value != null)
                {
                    return(OptionKind.Single);
                }
                else if (valueList != null)
                {
                    return(OptionKind.List);
                }
                else
                {
                    return(OptionKind.Unknown);
                }
            }
        }
Ejemplo n.º 11
0
 private void InitializeValueList()
 {
     this.valueListAttribute = ValueListAttribute.GetAttribute(this.target);
     if (this.IsValueListDefined)
     {
         this.valueList = ValueListAttribute.GetReference(this.target);
     }
 }
Ejemplo n.º 12
0
 private void InitializeValueList()
 {
     _valueListAttribute = ValueListAttribute.GetAttribute(_target);
     if (IsValueListDefined)
     {
         _valueList = ValueListAttribute.GetReference(_target);
     }
 }