protected override Type[] FindAllItems() { return(_allAssemblyFinder .FindAll(true) .SelectMany(assembly => assembly.GetTypes()) .Where(type => TypeReflections.IsTypeDerivedFrom(type, typeof(TBaseType))) .Distinct() .ToArray()); }
public void TypeDerivedFromTypeWithEntryThreeAndBaseFourWithLongAndLongTest() { TypeReflections.IsTypeDerivedFrom(Entry3, typeof(BaseLevelFour <long, long>)).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryTwoAndInterfaceOneTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceOne)).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryTwoAndBaseTwoTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(BaseLevelTwo)).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourDefinitionTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <,>)).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryTwoAndInterfaceThreeWithStringTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceThree <string>)).ShouldBeFalse(); }
public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourWithIntAndStringTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <int, string>)).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryTwoAndInterfaceFourWithStringAndIntTest() { TypeReflections.IsTypeDerivedFrom(Entry2, typeof(IInterfaceFour <string, int>)).ShouldBeFalse(); }
public void TypeDerivedFromTypeWithAbstractOneAndInterfaceZeroTest() { TypeReflections.IsTypeDerivedFrom(typeof(AbstractLevelOne), typeof(IInterfaceZero)).ShouldBeFalse(); TypeReflections.IsTypeDerivedFrom(typeof(AbstractLevelOne), typeof(IInterfaceZero), TypeDerivedOptions.CanAbstract).ShouldBeTrue(); }
public void TypeDerivedFromTypeWithEntryOneAndAbstractOneTest() { TypeReflections.IsTypeDerivedFrom(Entry1, typeof(AbstractLevelOne)).ShouldBeTrue(); TypeReflections.IsTypeDerivedFrom(Entry1, typeof(AbstractLevelOne), TypeDerivedOptions.CanAbstract).ShouldBeTrue(); }
public static bool IsDerivedFrom <TParent>(this Type sourceType, TypeDerivedOptions derivedOptions = TypeDerivedOptions.Default) { return(TypeReflections.IsTypeDerivedFrom(sourceType, typeof(TParent), derivedOptions)); }
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); } }