예제 #1
0
        public void CreatingAValueProperty_WithNullSetter_ShouldCreateAsReadOnly()
        {
            var property = new DelegateProperty <Container, int>
                           (
                name: "Value",
                getter: (ref Container c) => c.Value
                           );

            Assert.That(property.Name, Is.EqualTo("Value"));
            Assert.That(property.IsReadOnly, Is.True);
        }
예제 #2
0
    static void Main(string[] args)
    {
        string name = "Matt";
        var    prop = new DelegateProperty <string>(
            () => name,
            value => name = value);
        var test = new Test(prop);

        Console.WriteLine(test.Name);
        test.Name = "Ben";
        Console.WriteLine(name);
        Console.ReadKey();
    }
예제 #3
0
        public void SetValue_WhenPropertyIsReadOnly_ShouldThrow()
        {
            var property = new DelegateProperty <Container, int>
                           (
                name: "Value",
                getter: (ref Container c) => c.Value
                           );

            var container = new Container {
                Value = 0
            };

            Assert.Throws <InvalidOperationException>(() => { property.SetValue(ref container, 42); });
        }
예제 #4
0
        public void GetValue_StructContainerWithIntField_ShouldReturnCorrectValue()
        {
            var property = new DelegateProperty <Container, int>
                           (
                name: "Value",
                getter: (ref Container c) => c.Value
                           );

            var container = new Container {
                Value = 42
            };

            Assert.That(property.GetValue(ref container), Is.EqualTo(42));
        }
예제 #5
0
        public void SetValue_StructContainerWithIntField_ValueShouldBeSet()
        {
            var property = new DelegateProperty <Container, int>
                           (
                name: "Value",
                getter: (ref Container c) => c.Value,
                setter: (ref Container c, int v) => c.Value = v
                           );

            var container = new Container {
                Value = 0
            };

            property.SetValue(ref container, 42);

            Assert.That(container.Value, Is.EqualTo(42));
        }
예제 #6
0
        public CollectionModel(CollectionConfig config, IPreviewList stream, CollectionCommands commands)
        {
            Config     = config;
            Name.Value = config.Name;

            DelegateCommand MakeCommand(ICommand command) =>
            new DelegateCommand(() => command.CanExecute(this), () => command.Execute(this)).UpdateOn(command);

            AddCommand    = MakeCommand(commands.Add);
            SelectCommand = MakeCommand(commands.Select);
            DeleteCommand = MakeCommand(commands.Delete);

            Count = new DelegateProperty <int>(() => stream.Count)
                    .UpdateOn(stream);

            Label = new DelegateProperty <string>(() => $"{Name.Value} ({Count.Value})")
                    .UpdateOn(Name)
                    .UpdateOn(Count);
        }
예제 #7
0
        public PauseMenu(GameConnectionManager connectionManager)
        {
            _connectionManager = connectionManager;

            _backgroundOpacity = new AnimatedProperty
            {
                TargetValue    = DelegateProperty.Get(() => IsVisible ? 0.75f : 0f),
                AnimationSpeed = Property.Get(8f),
            };

            var buttonLeft = new AnimatedProperty(-Button.Width - 1)
            {
                TargetValue    = DelegateProperty.Get(() => IsVisible ? 25f : -Button.Width - 1),
                AnimationSpeed = Property.Get(16 * Button.Width),
            };

            _continueButton = new Button
            {
                Text = Property.Get("Continue"),
                Left = buttonLeft,
                Top  = Property.Get(60f),
            };

            _disconnectButton = new Button
            {
                Text = Property.Get("Disconnect"),
                Left = buttonLeft,
                Top  = Property.Get(100f),
            };

            _continueButton.Click += () =>
            {
                IsVisible = false;
            };

            _disconnectButton.Click += () =>
            {
                _connectionManager.Disconnect();
            };
        }
예제 #8
0
 set => SetValue(DelegateProperty, value);
예제 #9
0
 public Test(DelegateProperty <string> prop)
 {
     NameProperty = prop;
 }