public static bool Equals(ITypeInfo self, ITypeInfo other)
        {
            if (self == null && other == null)
            {
                return(true);
            }

            if (self == null || other == null)
            {
                return(false);
            }

            if (self.IsArray)
            {
                return(other.IsArray && self.GetElementType().Equals(other.GetElementType()));
            }

            if (self.IsGenericParameter)
            {
                return(other.IsGenericParameter && self.Name == other.Name);
            }

            return(self.Name == other.Name &&
                   self.Namespace == other.Namespace &&
                   self.IsGenericTypeDefinition == other.IsGenericTypeDefinition &&
                   GenericArgumentsEquals(self.GetGenericArguments(), other.GetGenericArguments()));
        }
Exemplo n.º 2
0
        public static int GetGenericArgumentsToSkip(ITypeInfo type)
        {
            if (type.IsArray)
            {
                return(1 + GetGenericArgumentsToSkip(type.GetElementType()));
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(TypeInfo.From(typeof(Nullable <>))))
            {
                return(0);
            }

            if (!type.IsGenericType)
            {
                return(type.IsValueType ? 0 : 1);
            }

            var count = 1;

            foreach (var argument in type.GetGenericArguments())
            {
                count += GetGenericArgumentsToSkip(argument);
            }

            return(count);
        }
Exemplo n.º 3
0
        private ITypeInfo GetElementType(ITypeInfo arrayType)
        {
            if (arrayType.IsArray)
            {
                return(arrayType.GetElementType() ?? throw new ArgumentNullException($"Array type's {arrayType.Name} element type is not defined"));
            }

            if (arrayType.IsGenericType && arrayType.GetGenericTypeDefinition().Equals(TypeInfo.From(typeof(List <>))))
            {
                return(arrayType.GetGenericArguments()[0]);
            }

            throw new ArgumentException("arrayType should be either Array or List<T>", nameof(arrayType));
        }
        public static int GetHashCode(ITypeInfo self)
        {
            if (self.IsArray)
            {
                return((self.IsArray, self.GetElementType()).GetHashCode());
            }

            if (self.IsGenericParameter)
            {
                return((self.IsGenericParameter, self.Name).GetHashCode());
            }

            return((self.Name, self.Namespace, self.IsGenericTypeDefinition).GetHashCode());
        }