1 //---------------------------------------------------------------------
2 // <copyright file="ExpressionVisitorHelper.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //---------------------------------------------------------------------
9 namespace System.Linq.Expressions.Internal
11 using System.Collections.Generic;
12 using System.Collections.ObjectModel;
15 // Because we are using the source file for ExpressionVistor from System.Core
16 // we need to add code to facilitate some external calls that ExpressionVisitor makes.
17 // The classes in this file do that.
19 internal static class Error
21 internal static Exception UnhandledExpressionType(ExpressionType expressionType)
23 return EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnhandledExpressionType(expressionType));
26 internal static Exception UnhandledBindingType(MemberBindingType memberBindingType)
28 return EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnhandledBindingType(memberBindingType));
32 internal static class ReadOnlyCollectionExtensions
34 internal static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> sequence)
37 return DefaultReadOnlyCollection<T>.Empty;
38 ReadOnlyCollection<T> col = sequence as ReadOnlyCollection<T>;
41 return new ReadOnlyCollection<T>(sequence.ToArray());
43 private static class DefaultReadOnlyCollection<T>
45 private static ReadOnlyCollection<T> _defaultCollection;
46 internal static ReadOnlyCollection<T> Empty
50 if (_defaultCollection == null)
51 _defaultCollection = new ReadOnlyCollection<T>(new T[] { });
52 return _defaultCollection;