Exemplo n.º 1
0
        public void ImmediateTypeGetMember()
        {
            var    immediateType = new ImmediateType(typeof(PublicValueTypeTestClass));
            string memberName    = nameof(PublicValueTypeTestClass._publicField);

            Assert.AreEqual(immediateType.Fields[memberName], immediateType.GetMember(memberName));
            Assert.AreEqual(immediateType.Fields[memberName], immediateType[memberName]);

            memberName = nameof(PublicValueTypeTestClass.PublicPropertyGet);
            Assert.AreEqual(immediateType.Properties[memberName], immediateType.GetMember(memberName));
            Assert.AreEqual(immediateType.Properties[memberName], immediateType[memberName]);

            memberName = "NotExists";
            Assert.IsNull(immediateType.GetMember(memberName));
            Assert.IsNull(immediateType[memberName]);

            // ReSharper disable AssignNullToNotNullAttribute
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(() => immediateType.GetMember(null));
            // ReSharper disable once UnusedVariable
            Assert.Throws <ArgumentNullException>(() => { ImmediateMember member = immediateType[null]; });
            // ReSharper restore AssignNullToNotNullAttribute
        }
        public void ObjectWrapperGetMember()
        {
            var    testObject    = new PublicValueTypeTestClass();
            var    objectWrapper = new ObjectWrapper(testObject);
            string memberName    = nameof(PublicValueTypeTestClass._publicField);

            Assert.AreEqual(objectWrapper.Fields[memberName], objectWrapper.GetMember(memberName));
            Assert.AreEqual(objectWrapper.Fields[memberName], objectWrapper[memberName]);

            memberName = nameof(PublicValueTypeTestClass.PublicPropertyGet);
            Assert.AreEqual(objectWrapper.Properties[memberName], objectWrapper.GetMember(memberName));
            Assert.AreEqual(objectWrapper.Properties[memberName], objectWrapper[memberName]);

            memberName = "NotExists";
            Assert.IsNull(objectWrapper.GetMember(memberName));
            Assert.IsNull(objectWrapper[memberName]);

            // ReSharper disable AssignNullToNotNullAttribute
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(() => objectWrapper.GetMember(null));
            // ReSharper disable once UnusedVariable
            Assert.Throws <ArgumentNullException>(() => { ImmediateMember member = objectWrapper[null]; });
            // ReSharper restore AssignNullToNotNullAttribute
        }