private bool IsReadOnlyCollectionInterface() { #if NET_STANDARD return(EnumerableType.IsClosedTypeOf(typeof(IReadOnlyCollection <>))); #else return(EnumerableType.IsInterface() && (EnumerableType.Name == "IReadOnlyCollection`1") && EnumerableType.IsFromBcl()); #endif }
public bool CouldBeReadOnly() { if (_couldBeReadOnly.HasValue) { return(_couldBeReadOnly.Value); } if (EnumerableType.IsInterface()) { // If the declared Type is an interface it could have an 'Add' method // while the underlying, implementing Type is actually readonly: return((_couldBeReadOnly = true).Value); } // If the declared Type declares an 'Add' method, assume it's not readonly; // Array implements ICollection<>, but its Add method is implemented explicitly: return((_couldBeReadOnly = EnumerableType.GetPublicInstanceMethods("Add").None()).Value); }
public Type GetEmptyInstanceCreationFallbackType() { if (IsArray) { return(ListType); } if (!EnumerableType.IsInterface()) { return(EnumerableType); } if (IsDictionary) { return(typeof(Dictionary <,>).MakeGenericType(EnumerableType.GetGenericTypeArguments())); } return(HasSetInterface ? HashSetType : ListType); }
public Expression GetNewInstanceCreation() { return(IsReadOnly || EnumerableType.IsInterface() ? Expression.New(ListType) : GetEmptyInstanceCreation()); }