Beispiel #1
0
 protected override Type[] FindAllItems()
 {
     return(_allAssemblyFinder
            .FindAll(true)
            .SelectMany(assembly => assembly.GetTypes())
            .Where(type => TypeReflections.IsTypeDerivedFrom(type, typeof(TBaseType)))
            .Distinct()
            .ToArray());
 }
Beispiel #2
0
 public void TypeDerivedFromTypeWithEntryThreeAndBaseFourWithLongAndLongTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry3, typeof(BaseLevelFour <long, long>)).ShouldBeTrue();
 }
Beispiel #3
0
 public void TypeDerivedFromTypeWithEntryTwoAndInterfaceOneTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceOne)).ShouldBeTrue();
 }
Beispiel #4
0
 public void TypeDerivedFromTypeWithEntryTwoAndBaseTwoTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(BaseLevelTwo)).ShouldBeTrue();
 }
Beispiel #5
0
 public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourDefinitionTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <,>)).ShouldBeTrue();
 }
Beispiel #6
0
 public void TypeDerivedFromTypeWithEntryTwoAndInterfaceThreeWithStringTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceThree <string>)).ShouldBeFalse();
 }
Beispiel #7
0
 public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourWithIntAndStringTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <int, string>)).ShouldBeTrue();
 }
Beispiel #8
0
 public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourWithStringAndIntTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <string, int>)).ShouldBeFalse();
 }
Beispiel #9
0
 public void TypeDerivedFromTypeWithAbstractOneAndInterfaceZeroTest()
 {
     TypeReflections.IsTypeDerivedFrom(typeof(AbstractLevelOne), typeof(IInterfaceZero)).ShouldBeFalse();
     TypeReflections.IsTypeDerivedFrom(typeof(AbstractLevelOne), typeof(IInterfaceZero), TypeDerivedOptions.CanAbstract).ShouldBeTrue();
 }
Beispiel #10
0
 public void TypeDerivedFromTypeWithEntryOneAndAbstractOneTest()
 {
     TypeReflections.IsTypeDerivedFrom(Entry1, typeof(AbstractLevelOne)).ShouldBeTrue();
     TypeReflections.IsTypeDerivedFrom(Entry1, typeof(AbstractLevelOne), TypeDerivedOptions.CanAbstract).ShouldBeTrue();
 }
Beispiel #11
0
 public static bool IsDerivedFrom <TParent>(this Type sourceType, TypeDerivedOptions derivedOptions = TypeDerivedOptions.Default)
 {
     return(TypeReflections.IsTypeDerivedFrom(sourceType, typeof(TParent), derivedOptions));
 }
Beispiel #12
0
 public static bool IsDerivedFrom(this Type sourceType, Type parentType, TypeDerivedOptions derivedOptions = TypeDerivedOptions.Default)
 {
     return(TypeReflections.IsTypeDerivedFrom(sourceType, parentType, derivedOptions));
 }
        /// <summary>
        /// Determine whether the given string can be of the given type. <br />
        /// 判断给定的字符串是否能成为给定的类型。
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <param name="matchedCallback"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static bool Is(this string text, Type type, CastingContext context, Action <object> matchedCallback = null)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (Types.IsNullableType(type))
            {
                return(text is null || Is(text, TypeConv.GetNonNullableType(type), context, matchedCallback));
            }

            if (!__unsupportedTypeCheck(type,
                                        out var typeIsAssignableFromEncoding,
                                        out var typeCanBeChecking, out var checkingHandler))
            {
                return(false);
            }

            if (typeCanBeChecking)
            {
                return(__customChecking(checkingHandler));
            }

            return(TypeIs.__enumIs(text, type, matchedCallback, context.IgnoreCase)
                   .Or(() => TypeIs.__charIs(text, type, matchedCallback))
                   .Or(() => TypeIs.__numericIs(text, type, matchedCallback, context.NumberStyles, context.FormatProvider))
                   .Or(() => TypeIs.__booleanIs(text, type, matchedCallback))
                   .Or(() => TypeIs.__dateTimeIs(text, type, matchedCallback, context.Format, context.DateTimeStyles, context.FormatProvider))
                   .Or(() => TypeIs.__dateTimeOffsetIs(text, type, matchedCallback, context.Format, context.DateTimeStyles, context.FormatProvider))
                   .Or(() => TypeIs.__timeSpanIs(text, type, matchedCallback, context.Format, context.FormatProvider))
                   .Or(() => TypeIs.__guidIs(text, type, matchedCallback, context.Format))
                   .Or(() => TypeIs.__versionIs(text, type, matchedCallback))
                   .Or(() => TypeIs.__ipAddressIs(text, type, matchedCallback))
                   .Or(() => TypeIs.__encodingIs(text, matchedCallback, typeIsAssignableFromEncoding)));

            // ReSharper disable once InconsistentNaming
            bool __unsupportedTypeCheck(Type t, out bool encodingFlag, out bool checkingFlag, out Func <object, bool> checker)
            {
                encodingFlag = t == typeof(Encoding) || TypeReflections.IsTypeDerivedFrom(t, typeof(Encoding), TypeDerivedOptions.CanAbstract);
                checkingFlag = CustomConvertManager.TryGetChecker(TypeClass.StringClazz, t, out checker);
                return(t.IsValueType
                       .Or(encodingFlag)
                       .Or(checkingFlag)
                       .Or(() => t == typeof(Version))
                       .Or(() => t == typeof(IPAddress)));
            }

            // ReSharper disable once InconsistentNaming
            bool __customChecking(Func <object, bool> handler)
            {
                var result = handler?.Invoke(text) ?? false;

                result.IfTrue(matchedCallback, text);

                return(result);
            }
        }