Beispiel #1
0
        public void TestParse(Type type, object input, object output)
        {
            IBindable bindable = (IBindable)Activator.CreateInstance(typeof(Bindable <>).MakeGenericType(type), type == typeof(string) ? "" : Activator.CreateInstance(type));

            bindable.Parse(input);
            object value = bindable.GetType().GetProperty(nameof(Bindable <object> .Value), BindingFlags.Public | BindingFlags.Instance)?.GetValue(bindable);

            Assert.That(value, Is.EqualTo(output));
        }
Beispiel #2
0
 /// <summary>
 /// When creating copies or clones of a Mod, this method will be called
 /// to copy explicitly adjusted user settings from <paramref name="target"/>.
 /// The base implementation will transfer the value via <see cref="Bindable{T}.Parse"/>
 /// or by binding and unbinding (if <paramref name="source"/> is an <see cref="IBindable"/>)
 /// and should be called unless replaced with custom logic.
 /// </summary>
 /// <param name="target">The target bindable to apply the adjustment to.</param>
 /// <param name="source">The adjustment to apply.</param>
 internal virtual void CopyAdjustedSetting(IBindable target, object source)
 {
     if (source is IBindable sourceBindable)
     {
         // copy including transfer of default values.
         target.BindTo(sourceBindable);
         target.UnbindFrom(sourceBindable);
     }
     else
     {
         target.Parse(source);
     }
 }