public void RawTypeArgsFromGenericTypeWithEntryTwoAndInterfaceTwoTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry2, typeof(IInterfaceTwo));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(0);
        }
Example #2
0
        public void ClassLevelDescriptionGettingTest()
        {
            var desc1 = TypeReflections.GetDescription(EntryOne);
            var desc2 = TypeReflections.GetDescription(EntryTwo);
            var desc3 = TypeReflections.GetDescription(EntryThree);
            var desc4 = TypeReflections.GetDescription(Wrapper);
            var desc5 = TypeReflections.GetDescription(Wrapper, ReflectionOptions.Inherit);

            desc1.ShouldBe("NormalClassOne");
#if NETFRAMEWORK
            desc2.ShouldBe(EntryTwo.Name);
#else
            desc2.ShouldBe("NormalClassDisplayTwo");
#endif
            desc3.ShouldBe("NormalClassThree");
            desc4.ShouldBe(Wrapper.Name);
            desc5.ShouldBe("NormalClassOne");

            desc1 = TypeReflections.GetDescriptionOr(EntryOne, "OrMe");
            desc2 = TypeReflections.GetDescriptionOr(EntryTwo, "OrMe");
            desc3 = TypeReflections.GetDescriptionOr(EntryThree, "OrMe");
            desc4 = TypeReflections.GetDescriptionOr(Wrapper, "OrMe");
            desc5 = TypeReflections.GetDescriptionOr(Wrapper, "OrMe", ReflectionOptions.Inherit);

            desc1.ShouldBe("NormalClassOne");
#if NETFRAMEWORK
            desc2.ShouldBe("OrMe");
#else
            desc2.ShouldBe("NormalClassDisplayTwo");
#endif

            desc3.ShouldBe("NormalClassThree");
            desc4.ShouldBe("OrMe");
            desc5.ShouldBe("NormalClassOne");
        }
        public void GenericTypeGettingAttributesInheritTest()
        {
            var type = typeof(NormalWithAttrClassWrapper2);

            var val1 = TypeReflections.GetAttributes <ModelOneAttribute>(type);
            var val2 = TypeReflections.GetAttributes <ModelTwoAttribute>(type);
            var val3 = TypeReflections.GetAttributes <ModelThreeAttribute>(type);
            var val4 = TypeReflections.GetAttributes <ModelFourAttribute>(type);

            val1.ShouldBeEmpty();
            val2.ShouldBeEmpty();
            val3.ShouldBeEmpty();
            val4.ShouldNotBeEmpty();

            val4.Count().ShouldBe(1);

            val1 = TypeReflections.GetAttributes <ModelOneAttribute>(type, ReflectionOptions.Inherit);
            val2 = TypeReflections.GetAttributes <ModelTwoAttribute>(type, ReflectionOptions.Inherit);
            val3 = TypeReflections.GetAttributes <ModelThreeAttribute>(type, ReflectionOptions.Inherit);
            val4 = TypeReflections.GetAttributes <ModelFourAttribute>(type, ReflectionOptions.Inherit);

            val1.ShouldNotBeEmpty();
            val2.ShouldBeEmpty();
            val3.ShouldNotBeEmpty();
            val4.ShouldNotBeEmpty();

            val1.Count().ShouldBe(2);
            val3.Count().ShouldBe(1);
            val4.Count().ShouldBe(1);
        }
        public void RawTypeArgsFromGenericTypeWithEntryOneAndAbstractOneTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry1, typeof(AbstractLevelOne));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(0);
        }
        public void DirectTypeGettingAttributesInheritTest()
        {
            var type  = typeof(NormalWithAttrClassWrapper2);
            var one   = typeof(ModelOneAttribute);
            var two   = typeof(ModelTwoAttribute);
            var three = typeof(ModelThreeAttribute);
            var four  = typeof(ModelFourAttribute);

            var val1 = TypeReflections.GetAttributes(type, one);
            var val2 = TypeReflections.GetAttributes(type, two);
            var val3 = TypeReflections.GetAttributes(type, three);
            var val4 = TypeReflections.GetAttributes(type, four);

            val1.ShouldBeEmpty();
            val2.ShouldBeEmpty();
            val3.ShouldBeEmpty();
            val4.ShouldNotBeEmpty();

            val4.Count().ShouldBe(1);

            val1 = TypeReflections.GetAttributes(type, one, ReflectionOptions.Inherit);
            val2 = TypeReflections.GetAttributes(type, two, ReflectionOptions.Inherit);
            val3 = TypeReflections.GetAttributes(type, three, ReflectionOptions.Inherit);
            val4 = TypeReflections.GetAttributes(type, four, ReflectionOptions.Inherit);

            val1.ShouldNotBeEmpty();
            val2.ShouldBeEmpty();
            val3.ShouldNotBeEmpty();
            val4.ShouldNotBeEmpty();

            val1.Count().ShouldBe(2);
            val3.Count().ShouldBe(1);
            val4.Count().ShouldBe(1);
        }
        public void DirectTypeGettingRequiredAttributesInheritTest()
        {
            var type  = typeof(NormalWithAttrClassWrapper2);
            var one   = typeof(ModelOneAttribute);
            var two   = typeof(ModelTwoAttribute);
            var three = typeof(ModelThreeAttribute);
            var four  = typeof(ModelFourAttribute);

            var val1 = TypeReflections.GetAttributesRequired(type, four);

            val1.ShouldNotBeEmpty();
            val1.Count().ShouldBe(1);

            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, one));
            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, two));
            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, three));

            var val2 = TypeReflections.GetAttributesRequired(type, one, ReflectionOptions.Inherit);
            var val3 = TypeReflections.GetAttributesRequired(type, three, ReflectionOptions.Inherit);

            val2.ShouldNotBeEmpty();
            val3.ShouldNotBeEmpty();

            val2.Count().ShouldBe(2);
            val3.Count().ShouldBe(1);

            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributesRequired(type, two, ReflectionOptions.Inherit));
        }
        public void ClassLevelDescriptionGettingTest()
        {
            var desc1 = TypeReflections.GetDisplayName(EntryOne);
            var desc2 = TypeReflections.GetDisplayName(EntryTwo);
            var desc3 = TypeReflections.GetDisplayName(EntryThree);
            var desc4 = TypeReflections.GetDisplayName(Wrapper);
            var desc5 = TypeReflections.GetDisplayName(Wrapper, ReflectionOptions.Inherit);

            desc1.ShouldBe("NormalClassDisplayNameOne");
            desc2.ShouldBe("NormalClassDisplayNameTwo");
            desc3.ShouldBe(EntryThree.Name);
            desc4.ShouldBe(Wrapper.Name);
            desc5.ShouldBe("NormalClassDisplayNameOne");

            desc1 = TypeReflections.GetDisplayNameOr(EntryOne, "OrMe");
            desc2 = TypeReflections.GetDisplayNameOr(EntryTwo, "OrMe");
            desc3 = TypeReflections.GetDisplayNameOr(EntryThree, "OrMe");
            desc4 = TypeReflections.GetDisplayNameOr(Wrapper, "OrMe");
            desc5 = TypeReflections.GetDisplayNameOr(Wrapper, "OrMe", ReflectionOptions.Inherit);

            desc1.ShouldBe("NormalClassDisplayNameOne");
            desc2.ShouldBe("NormalClassDisplayNameTwo");
            desc3.ShouldBe("OrMe");
            desc4.ShouldBe("OrMe");
            desc5.ShouldBe("NormalClassDisplayNameOne");
        }
        public void ObjectDerivedFromTypeWithEntryOneAndAbstractOneTest()
        {
            var model1 = new EntryClassOne();

            TypeReflections.IsObjectDerivedFrom(model1, typeof(AbstractLevelOne)).ShouldBeTrue();
            TypeReflections.IsObjectDerivedFrom(model1, typeof(AbstractLevelOne)).ShouldBeTrue();
        }
        /// <summary>
        /// 获取枚举定义列表
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>返回枚举列表元组(名称、值、显示名、描述)</returns>
        public static IEnumerable <(string Name, int Value, string DisplayName, string Description)> GetEnumDefinitionList(this Type type)
        {
            var list     = new List <(string Name, int Value, string DisplayName, string Description)>();
            var attrType = type;

            if (!attrType.IsEnum)
            {
                return(null);
            }
            var names  = Enum.GetNames(attrType);
            var values = Enum.GetValues(attrType);
            var index  = 0;

            foreach (var value in values)
            {
                var name        = names[index];
                var field       = values.GetType().GetField(value.ToString());
                var displayName = TypeReflections.GetDisplayName(field);
                var des         = TypeReflections.GetDescription(field);
                (string Name, int Value, string DisplayName, string Description)item = new(
                    name,
                    Convert.ToInt32(value),
                    displayName.IsNullOrWhiteSpace() ? null : displayName,
                    des.IsNullOrWhiteSpace() ? null : des
                    );
                list.Add(item);
                index++;
            }

            return(list);
        }
        /// <summary>
        /// Create for repository, and return an instance of runtime repository metadata object.
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <typeparam name="TImplement"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public static RepositoryReflector Create <TService, TImplement>()
            where TService : IRepository
            where TImplement : class, TService
        {
            var typeOfService   = typeof(TService);
            var typeOfImplement = typeof(TImplement);

            if (typeOfImplement.IsInterface || typeOfImplement.IsAbstract)
            {
                throw new ArgumentException($"The implement type {typeOfImplement} cannot be created an instance.");
            }

            if (typeOfService.IsInterface)
            {
                var attribute = TypeReflections.GetAttribute <RepositoryAttribute>(typeOfService);
                return(CreateCore(typeOfService, typeOfImplement, MappingType.InterfaceToClass, GetName(typeOfImplement, attribute)));
            }

            if (typeOfService.IsClass && typeOfService.IsAbstract)
            {
                var attribute = TypeReflections.GetAttribute <RepositoryAttribute>(typeOfService);
                return(CreateCore(typeOfService, typeOfImplement, MappingType.AbstractToClass, GetName(typeOfImplement, attribute)));
            }

            if (typeOfService.IsClass)
            {
                var attribute = TypeReflections.GetAttribute <RepositoryAttribute>(typeOfService);
                return(CreateCore(typeOfService, typeOfImplement, MappingType.ClassToClass, GetName(typeOfImplement, attribute)));
            }

            throw new InvalidOperationException("Unknown service type.");
        }
        public void ReflectionEnumTest()
        {
            Func <MemberInfo, bool> filter = member => member.MemberType == MemberTypes.TypeInfo ||
                                             member.MemberType == MemberTypes.Field ||
                                             member.MemberType == MemberTypes.Property;
            var t          = typeof(NormalValueTypeClass);
            var m0         = (MemberInfo)t;
            var allMembers = t.GetMembers().Where(filter).ToList();

            allMembers.ShouldNotBeNull();
            allMembers.ShouldNotBeEmpty();
            var m1 = allMembers.Single(x => x.Name == nameof(NormalValueTypeClass.Int99V1));
            var m2 = allMembers.Single(x => x.Name == nameof(NormalValueTypeClass.Int99V2));
            var m3 = allMembers.Single(x => x.Name == nameof(NormalValueTypeClass.Int99V3));
            var m4 = allMembers.Single(x => x.Name == nameof(NormalValueTypeClass.Int99V4));
            var m5 = allMembers.Single(x => x.Name == nameof(NormalValueTypeClass.Str));

            m1.MemberType.ShouldBe(MemberTypes.Property);
            m2.MemberType.ShouldBe(MemberTypes.Field);
            m3.MemberType.ShouldBe(MemberTypes.Property);
            m4.MemberType.ShouldBe(MemberTypes.Field);
            m5.MemberType.ShouldBe(MemberTypes.Property);

            TypeReflections.IsEnum(m0).ShouldBeFalse();
            TypeReflections.IsEnum(m1).ShouldBeTrue();
            TypeReflections.IsEnum(m2).ShouldBeTrue();
            TypeReflections.IsEnum(m3).ShouldBeFalse();
            TypeReflections.IsEnum(m4).ShouldBeFalse();
            TypeReflections.IsEnum(m3, TypeIsOptions.IgnoreNullable).ShouldBeTrue();
            TypeReflections.IsEnum(m4, TypeIsOptions.IgnoreNullable).ShouldBeTrue();
            TypeReflections.IsEnum(m5).ShouldBeFalse();
        }
        public void RawTypeArgsFromGenericTypeWithEntryTwoAndBaseOneTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry2, typeof(BaseLevelOne));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(0);
        }
        public void DirectTypeAttributeDefinedTest()
        {
            TypeReflections.IsAttributeDefined(ModelWithAttr, AttributeOne).ShouldBeTrue();
            TypeReflections.IsAttributeDefined(ModelWithAttr, AttributeTwo).ShouldBeFalse();

            TypeReflections.IsAttributeDefined(PropertyForModelWithAttr, AttributeOne).ShouldBeTrue();
            TypeReflections.IsAttributeDefined(PropertyForModelWithAttr, AttributeTwo).ShouldBeTrue();

            TypeReflections.IsAttributeDefined(FieldForModelWithAttr, AttributeOne).ShouldBeTrue();
            TypeReflections.IsAttributeDefined(FieldForModelWithAttr, AttributeTwo).ShouldBeTrue();

            TypeReflections.IsAttributeDefined(MethodForModelWithAttr, AttributeOne).ShouldBeTrue();
            TypeReflections.IsAttributeDefined(MethodForModelWithAttr, AttributeTwo).ShouldBeTrue();

            TypeReflections.IsAttributeDefined(ConstructorForModelWithAttrWithoutParam, AttributeOne).ShouldBeTrue();
            TypeReflections.IsAttributeDefined(ConstructorForModelWithAttrWithoutParam, AttributeTwo).ShouldBeTrue();

            TypeReflections.IsAttributeDefined(ConstructorForModelWithAttrWithOneParam, AttributeOne).ShouldBeFalse();
            TypeReflections.IsAttributeDefined(ConstructorForModelWithAttrWithOneParam, AttributeTwo).ShouldBeFalse();

            TypeReflections.IsAttributeDefined(ParameterOfConstructorForModelWithAttrWithOneParam, AttributeOne).ShouldBeFalse();
            TypeReflections.IsAttributeDefined(ParameterOfConstructorForModelWithAttrWithOneParam, AttributeTwo).ShouldBeTrue();

            Types.IsAttributeDefined(ModelWithAttr, AttributeOne).ShouldBeTrue();
            Types.IsAttributeDefined(ModelWithAttr, AttributeTwo).ShouldBeFalse();
        }
        public void GenericTypeAttributeNotDefinedTest()
        {
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ModelWithoutAttr).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ModelWithoutAttr).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(PropertyForModelWithoutAttr).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(PropertyForModelWithoutAttr).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(FieldForModelWithoutAttr).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(FieldForModelWithoutAttr).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(MethodForModelWithoutAttr).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(MethodForModelWithoutAttr).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWithoutAttrWithoutParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWithoutAttrWithoutParam).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWithoutAttrWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWithoutAttrWithOneParam).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ParameterOfConstructorForModelWithoutAttrWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ParameterOfConstructorForModelWithoutAttrWithOneParam).ShouldBeFalse();

            Types.IsAttributeDefined <ModelOneAttribute>(ModelWithoutAttr).ShouldBeFalse();
            Types.IsAttributeDefined <ModelTwoAttribute>(ModelWithoutAttr).ShouldBeFalse();

            Types.IsAttributeDefined <NormalWithoutAttrClass, ModelOneAttribute>().ShouldBeFalse();
            Types.IsAttributeDefined <NormalWithoutAttrClass, ModelTwoAttribute>().ShouldBeFalse();
        }
        /// <summary>
        /// Get English name<br />
        /// 获取英文名称
        /// </summary>
        /// <param name="chineseSolarTerms"></param>
        /// <returns></returns>
        public static string GetEnglishName(this ChineseSolarTerms chineseSolarTerms)
        {
            var fieldName = EnumsNET.Enums.GetName(chineseSolarTerms);
            var typeInfo  = typeof(ChineseSolarTerms).GetTypeInfo();
            var fieldInfo = typeInfo.GetField(fieldName !);

            return(TypeReflections.GetDescriptionOrDisplayName(fieldInfo));
        }
        public void GenericTypeGettingRequiredAttributeTest()
        {
            var type = typeof(NormalWithAttrClass);

            TypeReflections.GetAttributeRequired <ModelOneAttribute>(type).ShouldNotBeNull();
            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributeRequired <ModelTwoAttribute>(type));
            TypeReflections.GetAttributeRequired <ModelThreeAttribute>(type).ShouldNotBeNull();
        }
        public void RawTypeArgsFromGenericTypeWithEntryThreeAndBaseThreeWithLongTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry3, typeof(BaseLevelThree <long>));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(1);
            val[0].ShouldBe(typeof(long));
        }
        public void RawTypeArgsFromGenericTypeWithEntryTwoAndInterfaceThreeDefinitionTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry2, typeof(IInterfaceThree <>));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(1);
            val[0].ShouldBe(typeof(int));
        }
        public void AllAttributeGettingTest()
        {
            var val = TypeReflections.GetAttributes(typeof(NormalWithAttrClass));

            val.ShouldNotBeNull();
            val.ShouldNotBeEmpty();
            val.Count().ShouldBe(3);
        }
        public void GenericTypeGettingAttributeTest()
        {
            var type = typeof(NormalWithAttrClass);

            TypeReflections.GetAttribute <ModelOneAttribute>(type).ShouldNotBeNull();
            TypeReflections.GetAttribute <ModelTwoAttribute>(type).ShouldBeNull();
            TypeReflections.GetAttribute <ModelThreeAttribute>(type).ShouldNotBeNull();
        }
Example #21
0
 protected override Type[] FindAllItems()
 {
     return(_allAssemblyFinder
            .FindAll(true)
            .SelectMany(assembly => assembly.GetTypes())
            .Where(type => TypeReflections.IsTypeDerivedFrom(type, typeof(TBaseType)))
            .Distinct()
            .ToArray());
 }
        public void RawTypeArgsFromGenericTypeWithEntryTwoAndInterfaceFourWithIntAndStringTest()
        {
            var val = TypeReflections.GetRawTypeArgsFromGenericType(Entry2, typeof(IInterfaceFour <int, string>));

            val.ShouldNotBeNull();
            val.Count.ShouldBe(2);
            val[0].ShouldBe(typeof(int));
            val[1].ShouldBe(typeof(string));
        }
Example #23
0
        public void ParameterLevelDescriptionOrDisplayNameGettingTest()
        {
            var desc1 = TypeReflections.GetDescriptionOrDisplayName(ParameterOne);
            var desc2 = TypeReflections.GetDescriptionOrDisplayName(ParameterTwo);
            var desc3 = TypeReflections.GetDescriptionOrDisplayName(ParameterThree);

            desc1.ShouldBe("ArgOne");
            desc2.ShouldBe("ParamDesc");
            desc3.ShouldBe("ArgThree");
        }
Example #24
0
        public void FieldLevelDescriptionOrDisplayNameGettingTest()
        {
            var desc1 = TypeReflections.GetDescriptionOrDisplayName(FieldOne);
            var desc2 = TypeReflections.GetDescriptionOrDisplayName(FieldTwo);
            var desc3 = TypeReflections.GetDescriptionOrDisplayName(FieldThree);

            desc1.ShouldBe("FieldOne");
            desc2.ShouldBe("FieldDisplayTwo");
            desc3.ShouldBe("FieldThree");
        }
Example #25
0
        public void GenericImplementationWithEntryTwoAndBaseTwoTest()
        {
            Type outType = null;

            Type[] outArguments = null;

            TypeReflections.IsImplementationOfGenericType(Entry2, typeof(BaseLevelTwo), out outType, out outArguments).ShouldBeFalse();
            outType.ShouldBeNull();
            outArguments.ShouldBeNull();
        }
Example #26
0
        public void GenericImplementationWithEntryTwoAndInterfaceFourWithStringAndIntTest()
        {
            Type outType = null;

            Type[] outArguments = null;

            TypeReflections.IsImplementationOfGenericType(Entry2, typeof(IInterfaceFour <string, int>), out outType, out outArguments).ShouldBeFalse();
            outType.ShouldBeNull();
            outArguments.ShouldBeNull();
        }
Example #27
0
        public void PropertyLevelDescriptionOrDisplayNameGettingTest()
        {
            var desc1 = TypeReflections.GetDescriptionOrDisplayName(PropertyOne);
            var desc2 = TypeReflections.GetDescriptionOrDisplayName(PropertyTwo);
            var desc3 = TypeReflections.GetDescriptionOrDisplayName(PropertyThree);

            desc1.ShouldBe("PropertyOne");
            desc2.ShouldBe("PropertyDisplayTwo");
            desc3.ShouldBe("PropertyThree");
        }
        public void GenericTypeInheritAttributeDefinedTest()
        {
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ModelWrapper).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ModelWrapper).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelThreeAttribute>(ModelWrapper).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelThreeAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(PropertyForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(PropertyForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(PropertyForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(PropertyForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(FieldForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(FieldForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(FieldForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(FieldForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(MethodForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(MethodForModelWrapper).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(MethodForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(MethodForModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWrapperWithoutParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWrapperWithoutParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWrapperWithoutParam, ReflectionOptions.Inherit).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWrapperWithoutParam, ReflectionOptions.Inherit).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWrapperWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWrapperWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ConstructorForModelWrapperWithOneParam, ReflectionOptions.Inherit).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ConstructorForModelWrapperWithOneParam, ReflectionOptions.Inherit).ShouldBeFalse();

            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ParameterOfConstructorForModelWrapperWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ParameterOfConstructorForModelWrapperWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelThreeAttribute>(ParameterOfConstructorForModelWrapperWithOneParam).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelOneAttribute>(ParameterOfConstructorForModelWrapperWithOneParam, ReflectionOptions.Inherit).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelTwoAttribute>(ParameterOfConstructorForModelWrapperWithOneParam, ReflectionOptions.Inherit).ShouldBeFalse();
            TypeReflections.IsAttributeDefined <ModelThreeAttribute>(ParameterOfConstructorForModelWrapperWithOneParam, ReflectionOptions.Inherit).ShouldBeFalse();

            Types.IsAttributeDefined <ModelOneAttribute>(ModelWrapper).ShouldBeFalse();
            Types.IsAttributeDefined <ModelTwoAttribute>(ModelWrapper).ShouldBeFalse();
            Types.IsAttributeDefined <ModelThreeAttribute>(ModelWrapper).ShouldBeFalse();
            Types.IsAttributeDefined <ModelOneAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();
            Types.IsAttributeDefined <ModelTwoAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeFalse();
            Types.IsAttributeDefined <ModelThreeAttribute>(ModelWrapper, ReflectionOptions.Inherit).ShouldBeTrue();

            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelOneAttribute>().ShouldBeFalse();
            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelTwoAttribute>().ShouldBeFalse();
            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelThreeAttribute>().ShouldBeFalse();
            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelOneAttribute>(ReflectionOptions.Inherit).ShouldBeTrue();
            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelTwoAttribute>(ReflectionOptions.Inherit).ShouldBeFalse();
            Types.IsAttributeDefined <NormalWithAttrClassWrapper, ModelThreeAttribute>(ReflectionOptions.Inherit).ShouldBeTrue();
        }
        public void DirectTypeGettingRequiredAttributeTest()
        {
            var type  = typeof(NormalWithAttrClass);
            var one   = typeof(ModelOneAttribute);
            var two   = typeof(ModelTwoAttribute);
            var three = typeof(ModelThreeAttribute);

            TypeReflections.GetAttributeRequired(type, one).ShouldNotBeNull();
            Assert.Throws <ArgumentException>(() => TypeReflections.GetAttributeRequired(type, two).ShouldBeNull());
            TypeReflections.GetAttributeRequired(type, three).ShouldNotBeNull();
        }
        public void ObjectDerivedFromTypeWithAbstractOneAndInterfaceZeroTest()
        {
            var model1 = new EntryClassOne();
            var model2 = (AbstractLevelOne)model1;

            TypeReflections.IsObjectDerivedFrom(model2, typeof(AbstractLevelOne)).ShouldBeFalse();
            TypeReflections.IsObjectDerivedFrom(model2, typeof(AbstractLevelOne), derivedOptions: TypeDerivedOptions.CanAbstract).ShouldBeTrue();

            TypeReflections.IsObjectDerivedFrom(model2, typeof(IInterfaceZero)).ShouldBeFalse();
            TypeReflections.IsObjectDerivedFrom(model2, typeof(IInterfaceZero), derivedOptions: TypeDerivedOptions.CanAbstract).ShouldBeTrue();
        }