Esempio n. 1
0
        public bool IsIgnoringType(Type type)
        {
            if (type == null)
            {
                return false;
            }

            bool isIgnoring;
            if (this.ignoredTypes.TryGetValue(type, out isIgnoring))
            {
                return isIgnoring;
            }

            if (type.IsArray ||
                type.IsImmutableList() ||
                type.IsImmutableArray() ||
                type.IsImmutableHashSet() ||
                type.IsImmutableDictionary())
            {
                this.ignoredTypes.TryAdd(type, true);
                return true;
            }

            if (!type.IsGenericType)
            {
                this.ignoredTypes.TryAdd(type, false);
                return false;
            }

            return this.IsIgnoredGeneric(type);
        }
        private static bool CheckIfIsImmutable(Type type, List<Type> checkedTypes)
        {
            bool result;
            if (ImmutableCheckedTypes.TryGetValue(type, out result))
            {
                return result;
            }

            if (type.IsNullable())
            {
                var underlyingType = Nullable.GetUnderlyingType(type);
                result = CheckIfIsImmutable(underlyingType, checkedTypes);
            }
            else if (type == typeof(bool))
            {
                result = true;
            }
            else if (type.IsEnum)
            {
                result = true;
            }
            else if (type.IsArray)
            {
                result = false;
            }
            else if (type.IsDelegate())
            {
                result = true;
            }
            else if (type.IsImmutableList() ||
                     type.IsImmutableArray() ||
                     type.IsImmutableHashSet())
            {
                var itemType = type.GetItemType();
                result = CheckIfIsImmutable(itemType, checkedTypes);
            }
            else if (type.IsKeyValuePair())
            {
                var genericArguments = type.GetGenericArguments();
                result = CheckIfIsImmutable(genericArguments[0], checkedTypes)
                         && CheckIfIsImmutable(genericArguments[1], checkedTypes);
            }
            else if (CanBeImmutable(type))
            {
                result = HasImmutableMembers(type, checkedTypes);
            }
            else
            {
                result = false;
            }

            ImmutableCheckedTypes.TryAdd(type, result);
            return result;
        }
 public void IsImmutableHashSet(Type type, bool expected)
 {
     Assert.AreEqual(expected, type.IsImmutableHashSet());
 }