Пример #1
0
        private static void DrawFormInput(string label, ValueSetter valueSetter, ValueGetter valueGetter)
        {
            bool currentCursorVisibility = Console.CursorVisible;

            Console.Write($"{label}: ");
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.WriteLine($"<obecnie: \"{valueGetter()}\">");
            Console.ResetColor();

            Console.CursorVisible = true;
            bool writingSuccess = false;

            while (writingSuccess != true)
            {
                AddSpacing($"{label}: ".Length);
                object value = Console.ReadLine();
                try
                {
                    writingSuccess = valueSetter(value);
                }
                catch (Exception e)
                {
                    AddSpacing($"{label}: ".Length);
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                }
            }

            Console.CursorVisible = currentCursorVisibility;
        }
Пример #2
0
 public DataTable(
     Key key = null,
     List <DataColumn> columns      = null,
     int?sortColumnIndex            = 0,
     bool sortAscending             = true,
     ValueSetter <bool> onSelectAll = null,
     float dataRowHeight            = material_.kMinInteractiveDimension,
     float headingRowHeight         = 56.0f,
     float horizontalMargin         = 24.0f,
     float columnSpacing            = 56.0f,
     bool showCheckboxColumn        = true,
     float dividerThickness         = 1.0f,
     List <DataRow> rows            = null
     ) : base(key: key)
 {
     D.assert(columns != null);
     D.assert(columns.isNotEmpty);
     D.assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.Count));
     D.assert(rows != null);
     D.assert(!rows.Any((DataRow row) => row.cells.Count != columns.Count));
     D.assert(dividerThickness >= 0);
     this.columns            = columns;
     this.sortColumnIndex    = sortColumnIndex;
     this.sortAscending      = sortAscending;
     this.onSelectAll        = onSelectAll;
     this.dataRowHeight      = dataRowHeight;
     this.headingRowHeight   = headingRowHeight;
     this.horizontalMargin   = horizontalMargin;
     this.columnSpacing      = columnSpacing;
     this.showCheckboxColumn = showCheckboxColumn;
     this.dividerThickness   = dividerThickness;
     this.rows       = rows;
     _onlyTextColumn = _initOnlyTextColumn(columns);
 }
        public void Execute(MadLevelIcon icon, ValueGetter getter, ValueSetter setter)
        {
            var animations = MadAnim.FindAnimations(icon.gameObject, animationName);

            for (int i = 0; i < animations.Count; ++i)
            {
                var animation = animations[i];

                float baseValue = getter(animation);

                switch (modifierFunction)
                {
                case ModifierFunc.Custom:
                    setter(animation, customModifierFunction(icon));
                    break;

                case ModifierFunc.Predefined:
                    float firstParameter = GetFirstParameterValue(icon);
                    float rightSideValue = Compute(firstParameter, secondParameter, valueOperator);
                    float leftSideValue  = Compute(baseValue, rightSideValue, baseOperator);
                    setter(animation, leftSideValue);
                    break;

                default:
                    Debug.LogError("Uknown modifier function:" + modifierFunction);
                    setter(animation, baseValue);
                    break;
                }
            }
        }
Пример #4
0
 public void AddFieldValidated <T>(ValueGetter <T> getter, ValueSetter <T> setter, bool isNullable = false)
 {
     _fields.Add(new ReplicatedField
     {
         Setter = raw => ValidateValue(raw, isNullable, out T value) && setter(value),
         Getter = () => getter()
     });
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetterSetter{TOwner, TValue}"/> class.
        /// </summary>
        /// <param name="memberInfo">The field member to represent.</param>
        /// <param name="isReadOnly">if set to <c>true</c> [is readonly].</param>
        public GetterSetter(MemberInfo memberInfo, bool isReadOnly)
        {
            if (memberInfo == null)
            {
                throw new ArgumentNullException("memberInfo");
            }

            if (memberInfo.IsStatic())
            {
                this.staticGetter = GetCachedStaticGetter(memberInfo);

                if (!isReadOnly)
                {
                    this.staticSetter = GetCachedStaticSetter(memberInfo);
                }
            }
            else
            {
                this.getter = GetCachedGetter(memberInfo);

                if (!isReadOnly)
                {
                    this.setter = GetCachedSetter(memberInfo);
                }
            }
        }
Пример #6
0
        public MultipleVector3Capture(ValueGetter <TObject, Vector3> getter, ValueSetter <TObject, Vector3> setter, IList objects)
        {
            this.getter = getter;
            this.setter = setter;

            Update(objects);
        }
Пример #7
0
        public void NullableEnumWhenNotNull()
        {
            ReadWriteEnums target = new ReadWriteEnums();

            ValueSetter.SetFormattedValue(target, "NullableEnumField", "Bar");
            Assert.That(target.NullableEnumField, Is.EqualTo(TestEnum.Bar));
        }
Пример #8
0
        public void EnumMethod()
        {
            ReadWriteEnums target = new ReadWriteEnums();

            ValueSetter.SetFormattedValue(target, "EnumMethod", "Bar");
            Assert.That(target.EnumProperty, Is.EqualTo(TestEnum.Bar));
        }
Пример #9
0
        public void IEnumerableOfIntField()
        {
            ReadWriteLists target = new ReadWriteLists();

            ValueSetter.SetFormattedValue(target, "IEnumerableOfInt", "123, 456");
            Assert.That(target.IEnumerableOfInt, Is.EquivalentTo(new int[] { 123, 456 }));
        }
Пример #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 /// <param name="getter"></param>
 /// <param name="setter"></param>
 public HpProperty(string name, string description, ValueGetter getter, ValueSetter setter)
 {
     Type        = typeof(TProperty);
     DisplayName = name;
     Description = description;
     _getter     = getter;
     _setter     = setter;
 }
Пример #11
0
        public void SettingFormattedValueOfNullOnIntFieldSetsItTo0()
        {
            ReadWriteInts target = new ReadWriteInts();

            target.IntField = 123;
            ValueSetter.SetFormattedValue(target, "IntField", null);
            Assert.That(target.IntField, Is.EqualTo(0));
        }
Пример #12
0
        public void SettingFormatedValueOfNullOnStringFieldSetsItToNull()
        {
            ReadWriteStrings target = new ReadWriteStrings();

            target.StringField = "xxx";
            ValueSetter.SetFormattedValue(target, "StringField", null);
            Assert.That(target.StringField, Is.Null);
        }
Пример #13
0
        protected override void OnValueEntryChanged(IValueEntry old)
        {
            valueGetter = ValueEntry != null?CreateValueGetter(ValueEntry) : null;

            valueSetter = ValueEntry != null?CreateValueSetter(ValueEntry) : null;

            base.OnValueEntryChanged(old);
        }
Пример #14
0
        public void SettingFormatedValueOnDateTimeFieldUsesDateTimeParser()
        {
            ReadWriteDateTimes target = new ReadWriteDateTimes();

            target.DateTimeField = DateTime.MinValue;
            ValueSetter.SetFormattedValue(target, "DateTimeField", "Now");
            DateTimeParserTests.AssertThatDateTimeIsCloseEnoughToNow(target.DateTimeField);
        }
Пример #15
0
        private void TestStructMember <ContainerT, T>(T val, ValueSetter <ContainerT> setter, Func <ContainerT, T> getter)
            where ContainerT : struct
        {
            var result = SerializeDeserializeStruct(setter);

            Assert.IsType <ContainerT>(result);
            Assert.Equal(getter((ContainerT)result), val);
        }
Пример #16
0
        public void IntFieldWithWrongCase()
        {
            ReadWriteInts target = new ReadWriteInts();

            Assert.That(ValueSetter.CanSetValue(target, "iNTfIELD"), Is.True);
            ValueSetter.SetValue(target, "iNTfIELD", 123);
            Assert.That(target.IntField, Is.EqualTo(123));
        }
Пример #17
0
        public void IntMethod()
        {
            ReadWriteInts target = new ReadWriteInts();

            Assert.That(ValueSetter.CanSetValue(target, "IntMethod"), Is.True);
            ValueSetter.SetValue(target, "IntMethod", 123);
            Assert.That(target.IntMethod(), Is.EqualTo(123));
        }
Пример #18
0
 public ParamDelegates([NotNull] ValueGetter getter, [NotNull] ValueSetter setter,
                       [CanBeNull] ValueValidator validator = null, [CanBeNull] StateUpdater updater = null)
 {
     Getter    = getter ?? throw new ArgumentNullException(nameof(getter));
     Setter    = setter ?? throw new ArgumentNullException(nameof(setter));
     Validator = validator;
     Updater   = updater;
 }
Пример #19
0
        public void SettingFormatedValueOnInt32FieldUsesInt32Parser()
        {
            ReadWriteInts target = new ReadWriteInts();

            target.IntField = int.MinValue;
            ValueSetter.SetFormattedValue(target, "IntField", "123rd");
            Assert.That(target.IntField, Is.EqualTo(123));
        }
Пример #20
0
 public static bool SetValue(ItemModelBase <TItem> model, TValue value, string propertyPath, string propertyName)
 {
     if (!ValueSetter <TValue> ._setters.TryGetValue(propertyName, out Func <ItemModelBase <TItem>, TValue, bool>?setter))
     {
         ValueSetter <TValue> ._setters.Add(propertyName, setter = ValueSetter <TValue> .CreateSetter(propertyPath, propertyName));
     }
     return(setter(model, value));
 }
Пример #21
0
 public static PlayingCard RebuildCard(string input)
 {
     return(new PlayingCard()
     {
         Suit = (Suit)ValueSetter <Suit> .DisplayValue(input[1].ToString()),
         Rank = (Rank)ValueSetter <Rank> .DisplayValue(input[0].ToString())
     });
 }
Пример #22
0
        public Tweener(IInterpolator <T> interpolator, bool animatePhysics, ValueSetter <T> setter)
        {
            Debug.AssertFormat(setter != null, "[Tweener<{0}>] Attempt to create tweener with null setter", typeof(T));
            Debug.AssertFormat(interpolator != null, "[Tweener<{0}>] Attempt to create tweener with null interpolator", typeof(T));

            m_Setter         = setter;
            m_Interpolator   = interpolator;
            m_AnimatePhysics = animatePhysics ? 1f : 0f;
        }
Пример #23
0
        public void IntField()
        {
            ReadWriteInts target = new ReadWriteInts();

            Assert.That(ValueSetter.GetValueType(target, "IntField"), Is.SameAs(typeof(int)));
            Assert.That(ValueSetter.CanSetValue(target, "IntField"), Is.True);
            ValueSetter.SetValue(target, "IntField", 123);
            Assert.That(target.IntField, Is.EqualTo(123));
        }
Пример #24
0
        public void Invalid()
        {
            Assert.That(ValueSetter.CanSetValue(this, "x"), Is.False);
            ValueSetter setter = ValueSetter.GetValueSetter(this, "x");

            Assert.That(setter.CanSetValue(), Is.False);
            Assert.Throws(typeof(InvalidOperationException), delegate { setter.GetValueType(); });
            Assert.Throws(typeof(InvalidOperationException), delegate { setter.SetValue(null); });
        }
Пример #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetterSetter{TOwner, TValue}"/> class.
        /// </summary>
        /// <param name="getter">The getter.</param>
        /// <param name="setter">The setter.</param>
        /// <exception cref="ArgumentNullException">getter</exception>
        public GetterSetter(ValueGetter <TOwner, TValue> getter, ValueSetter <TOwner, TValue> setter)
        {
            if (getter == null)
            {
                throw new ArgumentNullException("getter");
            }

            this.getter = getter;
            this.setter = setter;
        }
Пример #26
0
 public virtual void SetValue(object instance, object value, IValueContext valueContext)
 {
     if (ValueSetter.IsStatic)
     {
         ValueSetter.Invoke(null, new[] { instance, value });
     }
     else
     {
         member.Setter.Invoke(instance, new[] { value });
     }
 }
Пример #27
0
 private void SetValueIndependent(object instance, object value)
 {
     if (ValueSetter.IsStatic)
     {
         ValueSetter.Invoke(null, new[] { instance, value });
     }
     else
     {
         xamlMember.Setter.Invoke(instance, new[] { value });
     }
 }
Пример #28
0
        public PropertySetterTest()
        {
            _yueluo       = Yueluo.Create();
            _nameProperty = typeof(Yueluo).GetProperty(nameof(Yueluo.Name)) !;
            _ageProperty  = typeof(Yueluo).GetProperty(nameof(Yueluo.Age)) !;
            _nameFunc     = ValueSetter <Yueluo, string, string> .GetSetter(_nameProperty);

            ValueSetter <Yueluo, int, int> .GetSetter(_ageProperty).Invoke(_yueluo, 16);

            ValueSetter <Yueluo> .GetSetter(_nameProperty).Invoke(_yueluo, "dalao");
        }
Пример #29
0
 /// <summary>
 /// Initializes the <see cref="UnityDecoratorAttributeDrawer{TDrawer, TAttribute}"/> class.
 /// </summary>
 static UnityDecoratorAttributeDrawer()
 {
     if (InternalAttributeFieldInfo == null)
     {
         Debug.LogError("Could not find the internal Unity field 'DecoratorDrawer.m_Attribute'; UnityDecoratorDrawer alias '" + typeof(UnityDecoratorAttributeDrawer <TDrawer, TAttribute, TAttributeConstraint>).GetNiceName() + "' has been disabled.");
     }
     else
     {
         SetAttribute = EmitUtilities.CreateInstanceFieldSetter <TDrawer, Attribute>(InternalAttributeFieldInfo);
     }
 }
 static UnityPropertyDrawer()
 {
     if (InternalFieldInfoFieldInfo == null)
     {
         Debug.LogError("Could not find the internal Unity field 'PropertyDrawer.m_FieldInfo'; UnityPropertyDrawer alias '" + typeof(UnityPropertyDrawer <TDrawer, TDrawnType>).GetNiceName() + "' has been disabled.");
     }
     else
     {
         SetFieldInfo = EmitUtilities.CreateInstanceFieldSetter <TDrawer, FieldInfo>(InternalFieldInfoFieldInfo);
     }
 }
        //private ILabel _displayText;

        //private event EventHandler _valueChanged;

        ///<summary>
        /// The Constructor for the <see cref="DateTimePickerManager"/>
        ///</summary>
        ///<param name="controlFactory"></param>
        ///<param name="dateTimePicker"></param>
        ///<param name="valueGetter"></param>
        ///<param name="valueSetter"></param>
        ///<exception cref="ArgumentNullException"></exception>
        public DateTimePickerManager(IControlFactory controlFactory, IDateTimePicker dateTimePicker,
                                     ValueGetter<DateTime> valueGetter, ValueSetter<DateTime> valueSetter)
        {
            if (valueGetter == null) throw new ArgumentNullException("valueGetter");
            if (valueSetter == null) throw new ArgumentNullException("valueSetter");
            _controlFactory = controlFactory;
            _dateTimePicker = dateTimePicker;
            _valueGetter = valueGetter;
            _valueSetter = valueSetter;
            SetupNullDisplayBox();
            ApplyBlankFormat();
        }
Пример #32
0
    public void SetData(Hashtable ht)
    {
        this.apply = true;
        if(ht.ContainsKey("stopchange")) this.stopChange = true;

        this.simpleOperator = (SimpleOperator)System.Enum.Parse(
                typeof(SimpleOperator), (string)ht["operator"]);
        this.value = int.Parse((string)ht["value"]);
        this.setter = (ValueSetter)System.Enum.Parse(
                typeof(ValueSetter), (string)ht["setter"]);
        this.execution = (StatusConditionExecution)System.Enum.Parse(
                typeof(StatusConditionExecution), (string)ht["execution"]);
        this.time = int.Parse((string)ht["time"]);
    }
Пример #33
0
 public void SetData(Hashtable ht)
 {
     this.statusNeeded = (StatusNeeded)System.Enum.Parse(typeof(StatusNeeded), (string)ht["statusneeded"]);
     this.comparison = (ValueCheck)System.Enum.Parse(typeof(ValueCheck), (string)ht["comparison"]);
     this.setter = (ValueSetter)System.Enum.Parse(typeof(ValueSetter), (string)ht["setter"]);
     this.statID = int.Parse((string)ht["statid"]);
     this.value = int.Parse((string)ht["value"]);
     if(ht.ContainsKey("classlevel")) this.classLevel = true;
 }
Пример #34
0
        public void Execute(MadLevelIcon icon, ValueGetter getter, ValueSetter setter) {
            var animations = MadAnim.FindAnimations(icon.gameObject, animationName);
            for (int i = 0; i < animations.Count; ++i) {
                var animation = animations[i];

                float baseValue = getter(animation);

                switch (modifierFunction) {
                    case ModifierFunc.Custom:
                        setter(animation, customModifierFunction(icon));
                        break;

                    case ModifierFunc.Predefined:
                        float firstParameter = GetFirstParameterValue(icon);
                        float rightSideValue = Compute(firstParameter, secondParameter, valueOperator);
                        float leftSideValue = Compute(baseValue, rightSideValue, baseOperator);
                        setter(animation, leftSideValue);
                        break;

                    default:
                        Debug.LogError("Uknown modifier function:" + modifierFunction);
                        setter(animation, baseValue);
                        break;
                }
            }
        }
Пример #35
0
        public CustomProperty( string sCategory, string sName, string sDescription, int identifier, ValueGetter g, ValueSetter s, bool bReadOnly, bool bVisible )
        {
            this.sCategory = sCategory;
            this.sDescription = sDescription;
            this.sName = sName;
            this.bReadOnly = bReadOnly;
            this.bVisible = bVisible;
            this.identifier = identifier;
            this.getter = g;
            this.setter = s;
            valueType = g( identifier ).GetType();

            readOnlyTester = delegate() { return bReadOnly; };
            visibleTester = delegate() { return bVisible; };
        }
Пример #36
0
        public CustomProperty( object parent, FieldInfo field, object[] displayAttributes )
        {
            this.parent = parent;
            this.parentType = parent.GetType();
            this.identifier = 0;
            m_field = field;
            valueType = field.FieldType;
            getter = id => { return m_field.GetValue( parent ); };
            setter = ( id, v ) => { m_field.SetValue( parent, v ); };

            ApplyAttributes( displayAttributes );
        }
Пример #37
0
    public bool CompareTo(int checkValue, ValueCheck comparison, ValueSetter setter, Combatant c)
    {
        bool check = false;

        int value = this.currentValue;
        if(ValueSetter.PERCENT.Equals(setter))
        {
            float v = value;
            float mv = this.maxValue;
            if(this.IsConsumable())
            {
                mv = c.status[this.maxStatus].currentValue;
            }
            v /= (mv/100.0f);
            value = (int)v;
        }

        if((ValueCheck.EQUALS.Equals(comparison) && value == checkValue) ||
            (ValueCheck.LESS.Equals(comparison) && value < checkValue) ||
            (ValueCheck.GREATER.Equals(comparison) && value > checkValue))
        {
            check = true;
        }

        return check;
    }