Exemplo n.º 1
0
        protected ExpressionElement WithDict(string[] values, string defaultValue)
        {
            var dictEl = new DictionaryElement {
                ValueType = typeof(string), AvailableValues = values, DefaultValue = defaultValue
            };

            return(WithElement(dictEl));
        }
Exemplo n.º 2
0
        public static EventHandlerDescription EventHandler(EventInfo eventInfo, DictionaryElement target)
        {
            if (eventInfo is null || target is null)
            {
                return(null);
            }

            return(new EventHandlerDescription(new ReflectedEventRegistrationSource <EventHandler>(eventInfo, null, target)));
        }
Exemplo n.º 3
0
    //convert the dictionary to a list of type "ElementsList"
    public ElementsList ToList()
    {
        var list = new List <DictionaryElement>();

        foreach (var item in MyDictionary)
        {
            var temp = new DictionaryElement();
            temp.Word       = item.Key;
            temp.Definition = item.Value;
            list.Add(temp);
        }

        var elementsList = new ElementsList();

        elementsList.Words = list;
        return(elementsList);
    }
Exemplo n.º 4
0
        public void can_set_property_one_deep()
        {
            var prop = FindMembers.Member <DictTarget>(x => x.Property);

            var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "foo" }, prop);

            var target = new DictTarget
            {
                Property = "baz"
            };

            var dict = new Dictionary <string, object>();

            element.Write(target, dict);

            dict["foo"].ShouldBe("baz");
        }
Exemplo n.º 5
0
        public void can_set_field_one_deep()
        {
            var field = FindMembers.Member <DictTarget>(x => x.Field);

            var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "foo" }, field);

            var target = new DictTarget
            {
                Field = "bar"
            };

            var dict = new Dictionary <string, object>();

            element.Write(target, dict);

            dict["foo"].ShouldBe("bar");
        }
        public void can_set_property_one_deep()
        {
            var prop = FindMembers.Member<DictTarget>(x => x.Property);

            var element = new DictionaryElement<DictTarget, string>(EnumStorage.AsString, new[] { "foo" }, prop);

            var target = new DictTarget
            {
                Property = "baz"
            };

            var dict = new Dictionary<string, object>();

            element.Write(target, dict);

            dict["foo"].ShouldBe("baz");
        }
        public void can_set_field_one_deep()
        {
            var field = FindMembers.Member<DictTarget>(x => x.Field);

            var element = new DictionaryElement<DictTarget, string>(EnumStorage.AsString, new []{ "foo" }, field);

            var target = new DictTarget
            {
                Field = "bar"
            };

            var dict = new Dictionary<string, object>();

            element.Write(target, dict);

            dict["foo"].ShouldBe("bar");
        }
Exemplo n.º 8
0
        public void can_set_property_three_deep_to_existing_dictionary_structure()
        {
            var prop = FindMembers.Member <DictTarget>(x => x.Property);

            var element = new DictionaryElement <DictTarget, string>(EnumStorage.AsString, new[] { "one", "two", "three" }, prop);

            var target = new DictTarget
            {
                Property = "baz"
            };

            var dict = new Dictionary <string, object>();

            dict.Add("one", new Dictionary <string, object>());

            element.Write(target, dict);

            dict["one"].ShouldBeOfType <Dictionary <string, object> >()
            ["two"].ShouldBeOfType <Dictionary <string, object> >()
            ["three"].ShouldBe("baz");
        }
        public void VisitDictionary()
        {
            Dictionary<object, object> dict = new Dictionary<object, object>();
            dict.Add("first", 1);
            dict.Add(2, "second");

            PlainTextVisitor visitor = new PlainTextVisitor(_writer);

            DictionaryElement elem = new DictionaryElement("dict", dict);
            elem.Visit(visitor);

            _stream.Seek(0, SeekOrigin.Begin);
            StreamReader reader = new StreamReader(_stream);
            string actual = reader.ReadToEnd();

            string expected = "Name: dict\r\n" +
                              "  Class: Int32, Name: first, Value: 1\r\n" +
                              "  Class: String, Name: 2, Value: second\r\n";

            Assert.AreEqual(expected, actual);
        }
        public ReflectedEventRegistrationSource(EventInfo eventInfo, Action <EventRegistration <T> > unregisterWithDexterity, DictionaryElement target)
        {
            this.eventInfo = eventInfo ?? throw new ArgumentNullException(nameof(eventInfo));
            this.unregisterWithDexterity = unregisterWithDexterity ?? UnregisterViaDictionary;

            this.target = target ?? throw new ArgumentNullException(nameof(target));

            dictionary = target.Dictionary.Extended();
        }
 public DelegatedEventRegistrationSource(Action <T> registerWithDexterity, Action <EventRegistration <T> > unregisterWithDexterity, DictionaryElement target)
 {
     this.registerWithDexterity   = registerWithDexterity ?? throw new ArgumentNullException(nameof(registerWithDexterity));
     this.unregisterWithDexterity = unregisterWithDexterity ?? UnregisterViaDictionary;
     dictionary = target?.Dictionary.Extended() ?? throw new ArgumentNullException(nameof(target));
 }
Exemplo n.º 12
0
        public void can_set_property_three_deep_to_existing_dictionary_structure()
        {
            var prop = FindMembers.Member<DictTarget>(x => x.Property);

            var element = new DictionaryElement<DictTarget, string>(EnumStorage.AsString, new[] { "one", "two", "three" }, prop);

            var target = new DictTarget
            {
                Property = "baz"
            };

            var dict = new Dictionary<string, object>();
            dict.Add("one", new Dictionary<string, object>());

            element.Write(target, dict);

            dict["one"].ShouldBeOfType<Dictionary<string, object>>()
                ["two"].ShouldBeOfType<Dictionary<string, object>>()
                ["three"].ShouldBe("baz");

        }
Exemplo n.º 13
0
 public static CancelEventHandlerDescription CancelEventHandler(Action <CancelEventHandler> registerWithDexterity, Action <EventRegistration <CancelEventHandler> > unregisterWithDexterity, DictionaryElement target)
 => new CancelEventHandlerDescription(new DelegatedEventRegistrationSource <CancelEventHandler>(registerWithDexterity, unregisterWithDexterity, target));
Exemplo n.º 14
0
        public static CancelEventHandlerDescription CancelEventHandler(EventInfo eventInfo, Action <EventRegistration <CancelEventHandler> > unregisterWithDexterity, DictionaryElement target)
        {
            if (eventInfo is null || target is null)
            {
                return(null);
            }

            return(new CancelEventHandlerDescription(new ReflectedEventRegistrationSource <CancelEventHandler>(eventInfo, unregisterWithDexterity, target)));
        }
Exemplo n.º 15
0
 public static EventHandlerDescription <T> EventHandler <T>(Action <EventHandler <T> > registerWithDexterity, Action <EventRegistration <EventHandler <T> > > unregisterWithDexterity, DictionaryElement target)
 => new EventHandlerDescription <T>(new DelegatedEventRegistrationSource <EventHandler <T> >(registerWithDexterity, unregisterWithDexterity, target));
Exemplo n.º 16
0
 public static EventHandlerDescription EventHandler(Action <EventHandler> registerWithDexterity, DictionaryElement target)
 => new EventHandlerDescription(new DelegatedEventRegistrationSource <EventHandler>(registerWithDexterity, null, target));