예제 #1
0
        public void ImmediateTypeGetMembers()
        {
            TypeClassifiedMembers classifiedMembers = TypeClassifiedMembers.GetForPublicValueTypeTestObject();

            var immediateType = new ImmediateType(typeof(PublicValueTypeTestClass), TypeAccessor.DefaultFlags | BindingFlags.NonPublic);

            CollectionAssert.AreEquivalent(
                classifiedMembers.AllMembers,
                SelectAllMemberInfos(immediateType.Members));
            CollectionAssert.AreEquivalent(
                classifiedMembers.AllMembers,
                SelectAllMemberInfos(immediateType.GetMembers()));

            #region Local function

            IEnumerable <MemberInfo> SelectAllMemberInfos(IEnumerable <ImmediateMember> members)
            {
                return(members.Select <ImmediateMember, MemberInfo>(member =>
                {
                    if (member is ImmediateField field)
                    {
                        return field.FieldInfo;
                    }
                    if (member is ImmediateProperty property)
                    {
                        return property.PropertyInfo;
                    }

                    throw new InvalidOperationException("Members contain an unexpected value");
                }));
            }

            #endregion
        }
        public void SetPropertyImmediateReflection([NotNull] object obj)
        {
            ImmediateType     accessor = ImmediateReflection.TypeAccessor.Get(obj.GetType());
            ImmediateProperty property = accessor.GetProperty(UIntArrayPropertyName);

            property?.SetValue(obj, ValueToSet);
        }
예제 #3
0
        public void TryNewParameterLess()
        {
            ConstructorTestHelpers.TryNewParameterLess(
                (out object instance, out Exception exception) =>
            {
                var immediateType = new ImmediateType(typeof(ParamsOnlyConstructor));
                return(immediateType.TryNew(out instance, out exception));
            },
                () => new ParamsOnlyConstructor());

            ConstructorTestHelpers.TryNewParameterLess(
                (out object instance, out Exception exception) =>
            {
                var immediateType = new ImmediateType(typeof(IntParamsOnlyConstructor));
                return(immediateType.TryNew(out instance, out exception));
            },
                () => new IntParamsOnlyConstructor());

            ConstructorTestHelpers.TryNewParameterLess(
                (out object instance, out Exception exception) =>
            {
                var immediateType = new ImmediateType(typeof(NullableIntParamsOnlyConstructor));
                return(immediateType.TryNew(out instance, out exception));
            },
                () => new NullableIntParamsOnlyConstructor());
        }
예제 #4
0
        public void NewParamsOnly()
        {
            ConstructorTestHelpers.NewParamsOnly(
                () =>
            {
                var immediateType = new ImmediateType(typeof(ParamsOnlyConstructor));
                return(immediateType.New());
            },
                () => new ParamsOnlyConstructor());

            ConstructorTestHelpers.NewParamsOnly(
                () =>
            {
                var immediateType = new ImmediateType(typeof(IntParamsOnlyConstructor));
                return(immediateType.New());
            },
                () => new IntParamsOnlyConstructor());

            ConstructorTestHelpers.NewParamsOnly(
                () =>
            {
                var immediateType = new ImmediateType(typeof(NullableIntParamsOnlyConstructor));
                return(immediateType.New());
            },
                () => new NullableIntParamsOnlyConstructor());
        }
예제 #5
0
        public void GetWithNonPublic()
        {
            TypeClassifiedMembers classifiedMembers = TypeClassifiedMembers.GetForPublicValueTypeTestObject();

            ImmediateType immediateType = TypeAccessor.Get <PublicValueTypeTestClass>(true);

            CheckPublicAndNonPublicInstanceMembers(immediateType);

            immediateType = TypeAccessor.Get(typeof(PublicValueTypeTestClass), true);
            CheckPublicAndNonPublicInstanceMembers(immediateType);

            #region Local functions

            void CheckPublicAndNonPublicInstanceMembers(ImmediateType type)
            {
                Assert.IsNotNull(type);
                Assert.AreEqual(typeof(PublicValueTypeTestClass), type.Type);
                // Public & Non Public instance members
                CollectionAssert.AreEquivalent(
                    classifiedMembers.AllFields,
                    immediateType.Fields.Select(field => field.FieldInfo));
                CollectionAssert.AreEquivalent(
                    classifiedMembers.PublicInstanceProperties.Concat(classifiedMembers.NonPublicInstanceProperties).Concat(classifiedMembers.StaticProperties),
                    immediateType.Properties.Select(property => property.PropertyInfo));
            }

            #endregion
        }
예제 #6
0
        public void GetWithFlags()
        {
            TypeClassifiedMembers classifiedMembers = TypeClassifiedMembers.GetForPublicValueTypeTestObject();

            const BindingFlags flags         = BindingFlags.Public | BindingFlags.Static;
            ImmediateType      immediateType = TypeAccessor.Get <PublicValueTypeTestClass>(flags);

            CheckStaticInstanceMembers(immediateType);

            immediateType = TypeAccessor.Get(typeof(PublicValueTypeTestClass), flags);
            CheckStaticInstanceMembers(immediateType);

            #region Local functions

            void CheckStaticInstanceMembers(ImmediateType type)
            {
                Assert.IsNotNull(type);
                Assert.AreEqual(typeof(PublicValueTypeTestClass), type.Type);
                // Static members
                CollectionAssert.AreEqual(
                    classifiedMembers.StaticFields.Concat(classifiedMembers.ConstFields),
                    immediateType.Fields.Select(field => field.FieldInfo));
                CollectionAssert.AreEquivalent(
                    classifiedMembers.StaticProperties,
                    immediateType.Properties.Select(property => property.PropertyInfo));
            }

            #endregion
        }
예제 #7
0
        public void NewWithParameters_Throws()
        {
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            var immediateType = new ImmediateType(typeof(NoDefaultConstructor));

            Assert.Throws <MissingMethodException>(() => immediateType.New(12, 42));

            immediateType = new ImmediateType(typeof(NotAccessibleConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New(12));

            immediateType = new ImmediateType(typeof(MultiParametersConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New(12f, 12));

            immediateType = new ImmediateType(typeof(ParamsConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New(12f, 12));

            immediateType = new ImmediateType(typeof(NoDefaultInheritedDefaultConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New(12f));

            immediateType = new ImmediateType(typeof(AbstractNoConstructor));
            Assert.Throws <MemberAccessException>(() => immediateType.New(12));

            immediateType = new ImmediateType(typeof(TemplateNoDefaultConstructor <>));
            Assert.Throws <ArgumentException>(() => immediateType.New(12));

            immediateType = new ImmediateType(typeof(NotDefaultConstructorThrows));
            Assert.Throws <TargetInvocationException>(() => immediateType.New(12));
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }
        public void ImmediateTypeNewKeyword()
        {
            var immediateType = new ImmediateType(typeof(BaseTestClass));

            Assert.AreEqual(typeof(BaseTestClass), immediateType.Type);
            Assert.AreEqual(nameof(BaseTestClass), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(BaseTestClass)}",
                immediateType.FullName);
            CollectionAssert.AreEquivalent(
                Enumerable.Empty <FieldInfo>(),
                immediateType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                new[]
            {
                BaseClassPublicGetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));

            immediateType = new ImmediateType(typeof(ChildTestClass));
            Assert.AreEqual(typeof(ChildTestClass), immediateType.Type);
            Assert.AreEqual(nameof(ChildTestClass), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(ChildTestClass)}",
                immediateType.FullName);
            CollectionAssert.AreEquivalent(
                Enumerable.Empty <FieldInfo>(),
                immediateType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                new[]
            {
                ChildClassPublicGetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));
        }
예제 #9
0
        public object GetPropertyImmediateReflection([NotNull] object obj)
        {
            ImmediateType     accessor = ImmediateReflection.TypeAccessor.Get(obj.GetType());
            ImmediateProperty property = accessor.GetProperty(UIntArrayPropertyName);

            return(property?.GetValue(obj));
        }
예제 #10
0
        public void ImmediateTypeInheritedType()
        {
            var immediateType = new ImmediateType(typeof(object));

            Assert.AreEqual(typeof(object), immediateType.Type);
            Assert.IsNull(immediateType.BaseType);
            Assert.IsNull(immediateType.DeclaringType);
            Assert.AreEqual("Object", immediateType.Name);
            Assert.AreEqual(
                $"{nameof(System)}.Object",
                immediateType.FullName);
            CollectionAssert.IsEmpty(immediateType.Fields);
            CollectionAssert.IsEmpty(immediateType.Properties);

            immediateType = new ImmediateType(typeof(ChildTestClass));
            Assert.AreEqual(typeof(ChildTestClass), immediateType.Type);
            Assert.AreEqual(typeof(BaseTestClass), immediateType.BaseType);
            Assert.IsNull(immediateType.DeclaringType);
            Assert.AreEqual(nameof(ChildTestClass), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(ChildTestClass)}",
                immediateType.FullName);
            CollectionAssert.IsEmpty(immediateType.Fields);
            CollectionAssert.AreEquivalent(
                new[]
            {
                ChildClassPublicGetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));
        }
 public void ImmediateType_Constructor()
 {
     var obj1 = (BenchmarkObject)ImmediateType.New();
     var obj2 = (BenchmarkObject2)ImmediateType2.New();
     var obj3 = (BenchmarkObject3)ImmediateType3.New();
     var obj4 = (BenchmarkObject4)ImmediateType4.New();
 }
예제 #12
0
        public void ImmediateTypeInterface()
        {
            // Base interface
            var immediateType = new ImmediateType(typeof(IBaseTestInterface));

            Assert.AreEqual(typeof(IBaseTestInterface), immediateType.Type);
            Assert.IsNull(immediateType.BaseType);
            Assert.IsNull(immediateType.DeclaringType);
            Assert.AreEqual(nameof(IBaseTestInterface), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(IBaseTestInterface)}",
                immediateType.FullName);
            CollectionAssert.IsEmpty(immediateType.Fields);
            CollectionAssert.AreEquivalent(
                new[]
            {
                BaseInterfaceGetPropertyPropertyInfo,
                BaseInterfaceSetPropertyPropertyInfo,
                BaseInterfaceGetSetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));

            // Child interface
            immediateType = new ImmediateType(typeof(IChildTestInterface));
            Assert.AreEqual(typeof(IChildTestInterface), immediateType.Type);
            Assert.IsNull(immediateType.BaseType);
            Assert.IsNull(immediateType.DeclaringType);
            Assert.AreEqual(nameof(IChildTestInterface), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(IChildTestInterface)}",
                immediateType.FullName);
            CollectionAssert.IsEmpty(immediateType.Fields);
            CollectionAssert.AreEquivalent(
                new[]
            {
                ChildInterfaceGetSetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));

            // Implementation
            immediateType = new ImmediateType(typeof(ImplementationInterfacesTestClass));
            Assert.AreEqual(typeof(ImplementationInterfacesTestClass), immediateType.Type);
            Assert.AreEqual(typeof(object), immediateType.BaseType);
            Assert.IsNull(immediateType.DeclaringType);
            Assert.AreEqual(nameof(ImplementationInterfacesTestClass), immediateType.Name);
            Assert.AreEqual(
                $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{nameof(ImplementationInterfacesTestClass)}",
                immediateType.FullName);
            CollectionAssert.IsEmpty(immediateType.Fields);
            CollectionAssert.AreEquivalent(
                new[]
            {
                ImplementationBaseInterfaceFromGetPropertyPropertyInfo,
                ImplementationBaseInterfaceFromSetPropertyPropertyInfo,
                ImplementationBaseInterfaceFromGetSetPropertyPropertyInfo,
                ImplementationChildInterfaceFromGetSetPropertyPropertyInfo
            },
                immediateType.Properties.Select(property => property.PropertyInfo));
        }
예제 #13
0
        public void ImmediateTypeEnumType()
        {
            // Simple test enum
            CheckEnumType(
                typeof(TestEnum),
                new[]
            {
                TestEnumFieldValueFieldInfo,
                TestEnumField1FieldInfo,
                TestEnumField2FieldInfo
            });

            // Test enum (inherit ulong)
            CheckEnumType(
                typeof(TestEnumULong),
                new[]
            {
                TestEnumULongFieldValueFieldInfo,
                TestEnumULongField1FieldInfo,
                TestEnumULongField2FieldInfo
            });

            // Flags test enum
            CheckEnumType(
                typeof(TestEnumFlags),
                new[]
            {
                TestEnumFlagsFieldValueFieldInfo,
                TestEnumFlagsField1FieldInfo,
                TestEnumFlagsField2FieldInfo,
                TestEnumFlagsField3FieldInfo
            });

            #region Local functions

            void CheckEnumType(Type enumType, IEnumerable <FieldInfo> enumFields)
            {
                var immediateType = new ImmediateType(enumType);

                Assert.AreEqual(enumType, immediateType.Type);
                Assert.AreEqual(typeof(Enum), immediateType.BaseType);
                Assert.IsNull(immediateType.DeclaringType);
                Assert.AreEqual(enumType.Name, immediateType.Name);
                Assert.AreEqual(
                    $"{nameof(ImmediateReflection)}.{nameof(Tests)}.{enumType.Name}",
                    immediateType.FullName);

                CollectionAssert.AreEquivalent(
                    enumFields,
                    immediateType.Fields.Select(field => field.FieldInfo));
                CollectionAssert.AreEquivalent(
                    Enumerable.Empty <PropertyInfo>(),
                    immediateType.Properties.Select(property => property.PropertyInfo));
            }

            #endregion
        }
예제 #14
0
 public void NewParameterLess([NotNull] Type type)
 {
     ConstructorTestHelpers.NewParameterLess(
         type,
         () =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.New());
     });
 }
예제 #15
0
        public void ImmediateTypeToString()
        {
            var immediateType1 = new ImmediateType(typeof(PublicValueTypeTestClass));

            Assert.AreEqual(typeof(PublicValueTypeTestClass).ToString(), immediateType1.ToString());

            var immediateType2 = new ImmediateType(typeof(InternalValueTypeTestClass));

            Assert.AreNotEqual(immediateType1.ToString(), immediateType2.ToString());
        }
예제 #16
0
        public void ImmediateTypeGetProperties()
        {
            var immediateType1 = new ImmediateType(typeof(PublicValueTypeTestClass));

            CollectionAssert.AreEquivalent(immediateType1.Properties, immediateType1.GetProperties());

            var immediateType2 = new ImmediateType(typeof(PublicReferenceTypeTestClass));

            CollectionAssert.AreNotEquivalent(immediateType1.GetProperties(), immediateType2.GetProperties());
        }
예제 #17
0
 public void Copy([NotNull] Type type, [CanBeNull] object other)
 {
     ConstructorTestHelpers.Copy(
         type,
         other,
         o =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.Copy(o));
     });
 }
예제 #18
0
 public void NewWithParameters([NotNull] Type type, [CanBeNull, ItemCanBeNull] params object[] arguments)
 {
     ConstructorTestHelpers.NewWithParameters(
         type,
         args =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.New(args));
     },
         arguments);
 }
예제 #19
0
 public void TryNewParameterLess([NotNull] Type type, bool expectFail)
 {
     ConstructorTestHelpers.TryNewParameterLess(
         type,
         expectFail,
         (out object instance, out Exception exception) =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.TryNew(out instance, out exception));
     });
 }
예제 #20
0
 public void TryNewWithParameters([NotNull] Type type, bool expectFail, [CanBeNull, ItemCanBeNull] params object[] arguments)
 {
     ConstructorTestHelpers.TryNewWithParameters(
         type,
         expectFail,
         (out object instance, out Exception exception, object[] args) =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.TryNew(out instance, out exception, args));
     },
         arguments);
 }
예제 #21
0
        public void GetCached()
        {
            ImmediateType immediateType1 = TypeAccessor.Get(typeof(PublicValueTypeTestClass));

            Assert.IsNotNull(immediateType1);

            ImmediateType immediateType2 = TypeAccessor.Get <PublicValueTypeTestClass>();

            Assert.IsNotNull(immediateType2);

            Assert.AreSame(immediateType1, immediateType2);
        }
예제 #22
0
        public static string ImmediateOperate(string ip, int port, ImmediateType type, string path, string exepara)
        {
            // 通过Socket处理
            string args = ((int)type).ToString() + "\n" + path + "\n" + exepara;
            string str  = SendToServer(ip, port, OperationType.Immediate, args);

            //if (str.StartsWith("err", StringComparison.OrdinalIgnoreCase))
            //{
            //    return str.Substring(3);
            //}
            return(str);
        }
예제 #23
0
        public void ImmediateTypeHashCode()
        {
            var immediateType1 = new ImmediateType(typeof(PublicValueTypeTestClass));
            var immediateType2 = new ImmediateType(typeof(PublicValueTypeTestClass));

            Assert.AreEqual(typeof(PublicValueTypeTestClass).GetHashCode(), immediateType1.GetHashCode());
            Assert.AreEqual(immediateType1.GetHashCode(), immediateType2.GetHashCode());

            var immediateType3 = new ImmediateType(typeof(InternalValueTypeTestClass));

            Assert.AreNotEqual(immediateType1.GetHashCode(), immediateType3.GetHashCode());
        }
예제 #24
0
 public void TryCopy([NotNull] Type type, [CanBeNull] object other, bool expectFail)
 {
     ConstructorTestHelpers.TryCopy(
         type,
         other,
         expectFail,
         (object o, out object instance, out Exception exception) =>
     {
         var immediateType = new ImmediateType(type);
         return(immediateType.TryCopy(o, out instance, out exception));
     });
 }
예제 #25
0
        public void ImmediateTypeGetProperty()
        {
            var    immediateType = new ImmediateType(typeof(PublicValueTypeTestClass));
            string propertyName  = nameof(PublicValueTypeTestClass.PublicPropertyGetSet);

            Assert.AreEqual(immediateType.Properties[propertyName], immediateType.GetProperty(propertyName));

            propertyName = "NotExists";
            Assert.IsNull(immediateType.GetProperty(propertyName));

            // ReSharper disable once AssignNullToNotNullAttribute
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(() => immediateType.GetProperty(null));
        }
예제 #26
0
        public void ImmediateTypeGetField()
        {
            var    immediateType = new ImmediateType(typeof(PublicValueTypeTestClass));
            string fieldName     = nameof(PublicValueTypeTestClass._publicField);

            Assert.AreEqual(immediateType.Fields[fieldName], immediateType.GetField(fieldName));

            fieldName = "NotExists";
            Assert.IsNull(immediateType.GetField(fieldName));

            // ReSharper disable once AssignNullToNotNullAttribute
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(() => immediateType.GetField(null));
        }
예제 #27
0
        public void ImmediateTypeEquality()
        {
            var immediateType1 = new ImmediateType(typeof(PublicValueTypeTestClass));
            var immediateType2 = new ImmediateType(typeof(PublicValueTypeTestClass));

            Assert.IsTrue(immediateType1.Equals(immediateType1));
            Assert.IsTrue(immediateType1.Equals(immediateType2));
            Assert.IsTrue(immediateType1.Equals((object)immediateType2));
            Assert.IsFalse(immediateType1.Equals(null));

            var immediateType3 = new ImmediateType(typeof(InternalValueTypeTestClass));

            Assert.IsFalse(immediateType1.Equals(immediateType3));
            Assert.IsFalse(immediateType1.Equals((object)immediateType3));
        }
예제 #28
0
파일: ABCOpInfo.cs 프로젝트: jfd16/Mariana
        private ABCOpInfo(
            ImmediateType opType    = ImmediateType.NONE,
            ControlType controlType = ControlType.NONE,
            int stackPopCount       = 0,
            int stackPushCount      = 0,
            bool pushesToScopeStack = false,
            bool popsFromScopeStack = false,
            bool localRead          = false,
            bool localWrite         = false,
            bool isDebug            = false
            )
        {
            int data = VALID_FLAG;

            data |= (int)opType;
            data |= (int)controlType << 3;

            if (stackPopCount == -1)
            {
                stackPopCount = 3;
            }
            data |= stackPopCount << 6;

            data |= stackPushCount << 8;

            if (pushesToScopeStack)
            {
                data |= SCOPE_PUSH_FLAG;
            }
            if (popsFromScopeStack)
            {
                data |= SCOPE_POP_FLAG;
            }
            if (localRead)
            {
                data |= LOCAL_READ_FLAG;
            }
            if (localWrite)
            {
                data |= LOCAL_WRITE_FLAG;
            }
            if (isDebug)
            {
                data |= DEBUG_FLAG;
            }

            m_data = (short)data;
        }
예제 #29
0
        public void NewParameterLess_Throws()
        {
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            var immediateType = new ImmediateType(typeof(NoDefaultConstructor));

            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(NotAccessibleDefaultConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(IList <int>));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(IDictionary <int, string>));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(AbstractDefaultConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(StaticClass));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(TemplateStruct <>));
            Assert.Throws <ArgumentException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(TemplateDefaultConstructor <>));
            Assert.Throws <ArgumentException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(ParamsConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(NoDefaultInheritedDefaultConstructor));
            Assert.Throws <MissingMethodException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(AmbiguousParamsOnlyConstructor));
            Assert.Throws <AmbiguousMatchException>(() => immediateType.New());

            // ReSharper disable once PossibleMistakenCallToGetType.2
            immediateType = new ImmediateType(typeof(DefaultConstructor).GetType());
            Assert.Throws <ArgumentException>(() => immediateType.New());

            immediateType = new ImmediateType(typeof(DefaultConstructorThrows));
            Assert.Throws(Is.InstanceOf <Exception>(), () => immediateType.New());

            immediateType = new ImmediateType(typeof(int[]));
            Assert.Throws <MissingMethodException>(() => immediateType.New());
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }
예제 #30
0
        public void ImmediateTypeWithFlags()
        {
            TypeClassifiedMembers classifiedMembers = TypeClassifiedMembers.GetForPublicValueTypeTestObject();

            var testType = new ImmediateType(typeof(PublicValueTypeTestClass)); // BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static

            CollectionAssert.AreEqual(
                classifiedMembers.PublicInstanceFields.Concat(classifiedMembers.StaticFields).Concat(classifiedMembers.ConstFields),
                testType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                classifiedMembers.PublicInstanceProperties.Concat(classifiedMembers.StaticProperties),
                testType.Properties.Select(property => property.PropertyInfo));

            testType = new ImmediateType(typeof(PublicValueTypeTestClass), BindingFlags.NonPublic | BindingFlags.Instance);
            CollectionAssert.AreEqual(
                classifiedMembers.NonPublicInstanceFields,
                testType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                classifiedMembers.NonPublicInstanceProperties,
                testType.Properties.Select(property => property.PropertyInfo));

            testType = new ImmediateType(typeof(PublicValueTypeTestClass), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            CollectionAssert.AreEqual(
                classifiedMembers.PublicInstanceFields.Concat(classifiedMembers.NonPublicInstanceFields),
                testType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                classifiedMembers.PublicInstanceProperties.Concat(classifiedMembers.NonPublicInstanceProperties),
                testType.Properties.Select(property => property.PropertyInfo));

            testType = new ImmediateType(typeof(PublicValueTypeTestClass), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            CollectionAssert.AreEqual(
                classifiedMembers.StaticFields.Concat(classifiedMembers.ConstFields),
                testType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEquivalent(
                classifiedMembers.StaticProperties,
                testType.Properties.Select(property => property.PropertyInfo));

            testType = new ImmediateType(typeof(PublicValueTypeTestClass), BindingFlags.IgnoreCase);
            CollectionAssert.AreEqual(
                Enumerable.Empty <FieldInfo>(),
                testType.Fields.Select(field => field.FieldInfo));
            CollectionAssert.AreEqual(
                Enumerable.Empty <PropertyInfo>(),
                testType.Properties.Select(property => property.PropertyInfo));
        }