コード例 #1
0
        public static bool IsGenericTaskOf([CanBeNull] this IType taskType, [CanBeNull] IType otherType)
        {
            if (taskType == null || otherType == null)
            {
                return(false);
            }
            if (!taskType.IsGenericTask())
            {
                return(false);
            }

            var taskDeclaredType = taskType as IDeclaredType;

            if (taskDeclaredType == null)
            {
                return(false);
            }

            var substitution = taskDeclaredType.GetSubstitution();

            if (substitution.IsEmpty())
            {
                return(false);
            }
            var meaningType = substitution.Apply(substitution.Domain[0]);

            return(meaningType.IsEquals(otherType));
        }
コード例 #2
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
 public static bool IsTaskOf([CanBeNull] this IType type, [CanBeNull] IType otherType)
 {
     if (type.IsTask() && otherType.IsVoid())
     {
         return(true);
     }
     return(type.IsGenericTaskOf(otherType));
 }
コード例 #3
0
 private static bool IsEqualTypeGroup([NotNull] IType sourceType, [NotNull] IType targetType)
 {
     if (sourceType is IDeclaredType && targetType is IDeclaredType || sourceType is IArrayType && targetType is IArrayType)
     {
         return(true);
     }
     if (sourceType is IPointerType)
     {
         return(targetType is IPointerType);
     }
     return(false);
 }
コード例 #4
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static bool IsFunc([CanBeNull] this IType type)
        {
            var declaredType = type as IDeclaredType;

            if (declaredType == null)
            {
                return(false);
            }

            var clrTypeName = declaredType.GetClrName();

            return(clrTypeName.Equals(PredefinedType.FUNC_FQN) || clrTypeName.FullName.StartsWith(PredefinedType.FUNC_FQN + "`"));
        }
コード例 #5
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static bool IsGenericTaskOf([CanBeNull] this IType type, [CanBeNull] IType otherType)
        {
            if (type == null || otherType == null)
            {
                return(false);
            }
            if (!type.IsGenericTask())
            {
                return(false);
            }

            var meaningType = type.GetFirstGenericType();

            return(meaningType != null && meaningType.IsEquals(otherType));
        }
コード例 #6
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static IType GetFirstGenericType(this IType type)
        {
            var taskDeclaredType = type as IDeclaredType;

            if (taskDeclaredType == null)
            {
                return(null);
            }

            var substitution = taskDeclaredType.GetSubstitution();

            if (substitution.IsEmpty())
            {
                return(null);
            }
            return(substitution.Apply(substitution.Domain[0]));
        }
コード例 #7
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static bool IsEquals([NotNull] this IType type, [NotNull] IType otherType)
        {
            if (!type.IsOpenType && !otherType.IsOpenType)
            {
                return(Equals(type, otherType));
            }
            if (!IsEqualTypeGroup(type, otherType))
            {
                return(false);
            }
            var scalarType      = type.GetScalarType();
            var otherScalarType = otherType.GetScalarType();

            if (scalarType == null || otherScalarType == null)
            {
                return(false);
            }
            if (scalarType.Classify != otherScalarType.Classify)
            {
                return(false);
            }
            var typeElement1 = scalarType.GetTypeElement();
            var typeElement2 = otherScalarType.GetTypeElement();

            if (typeElement1 == null || typeElement2 == null)
            {
                return(false);
            }
            var typeParameter1 = typeElement1 as ITypeParameter;
            var typeParameter2 = typeElement2 as ITypeParameter;

            if (typeParameter1 != null && typeParameter2 != null)
            {
                if (typeParameter1.HasDefaultConstructor != typeParameter2.HasDefaultConstructor ||
                    typeParameter1.TypeConstraints.Count != typeParameter2.TypeConstraints.Count)
                {
                    return(false);
                }
                if (typeParameter1.TypeConstraints.Where((t, i) => !t.IsEquals(typeParameter2.TypeConstraints[i])).Any())
                {
                    return(false);
                }
            }
            return(EqualSubstitutions(typeElement1, scalarType.GetSubstitution(), typeElement2, otherScalarType.GetSubstitution()));
        }
コード例 #8
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static bool IsAsyncDelegate([NotNull] this IType type, [NotNull] IType otherType)
        {
            if (type.IsAction() && otherType.IsFunc())
            {
                var parameterDeclaredType = otherType as IDeclaredType;
                var substitution          = parameterDeclaredType?.GetSubstitution();
                if (substitution?.Domain.Count != 1)
                {
                    return(false);
                }

                var valuableType = substitution.Apply(substitution.Domain[0]);
                return(valuableType.IsTask());
            }
            if (type.IsFunc() && otherType.IsFunc())
            {
                var parameterDeclaredType         = otherType as IDeclaredType;
                var originalParameterDeclaredType = type as IDeclaredType;
                var substitution         = parameterDeclaredType?.GetSubstitution();
                var originalSubstitution = originalParameterDeclaredType?.GetSubstitution();
                if (substitution == null || substitution.Domain.Count != originalSubstitution?.Domain.Count)
                {
                    return(false);
                }

                var i = 0;
                for (; i < substitution.Domain.Count - 1; i++)
                {
                    var genericType         = substitution.Apply(substitution.Domain[i]);
                    var originalGenericType = originalSubstitution.Apply(originalSubstitution.Domain[i]);
                    if (!genericType.Equals(originalGenericType))
                    {
                        return(false);
                    }
                }
                var returnType         = substitution.Apply(substitution.Domain[i]);
                var originalReturnType = originalSubstitution.Apply(originalSubstitution.Domain[i]);
                return(returnType.IsGenericTaskOf(originalReturnType));
            }
            return(false);
        }
コード例 #9
0
ファイル: TypeHelper.cs プロジェクト: ristogod/AsyncConverter
        public static bool IsGenericIQueryable([CanBeNull] this IType type)
        {
            var declaredType = type as IDeclaredType;

            return(declaredType != null && IsPredefinedTypeElement(declaredType.GetTypeElement(), PredefinedType.GENERIC_IQUERYABLE_FQN));
        }
コード例 #10
0
 public static bool IsGenericIQueryable([CanBeNull] this IType type)
 {
     return(TypesUtil.IsPredefinedTypeFromAssembly(type, PredefinedType.GENERIC_IQUERYABLE_FQN, assembly => assembly.IsMscorlib));
 }