Пример #1
0
        public bool Fits(IType type)
        {
            if (HasAncestor)
            {
                if (!type.CanBeImplicitlyConvertedTo(Ancestor))
                {
                    return(false);
                }
            }

            if (type is Primitive primitive)
            {
                if (HasDescendant)
                {
                    if (!Descedant.CanBeImplicitlyConvertedTo(primitive))
                    {
                        return(false);
                    }
                }

                if (IsComparable && !primitive.IsComparable)
                {
                    return(false);
                }
                return(true);
            }
            else if (type is Array array)
            {
                if (IsComparable)
                {
                    return(false);
                }
                if (!HasDescendant)
                {
                    return(true);
                }
                if (!(Descedant is Array descArray))
                {
                    return(false);
                }
                if (array.Element.Equals(descArray.Element))
                {
                    return(true);
                }
                if (!array.IsSolved || !descArray.IsSolved)
                {
                    return(false);
                }
            }
            else if (type is Fun fun)
            {
                if (IsComparable)
                {
                    return(false);
                }
                if (!HasDescendant)
                {
                    return(true);
                }
                if (!(Descedant is Fun descfun))
                {
                    return(false);
                }
                if (fun.Members.SequenceEqual(descfun.Members))
                {
                    return(true);
                }
                if (!fun.IsSolved || !descfun.IsSolved)
                {
                    return(false);
                }
            }
            throw new NotSupportedException();
        }