Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Objects / ELinq / ExpressionVisitorHelpers.cs
1 //---------------------------------------------------------------------
2 // <copyright file="ExpressionVisitorHelper.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 //---------------------------------------------------------------------
8
9 namespace System.Linq.Expressions.Internal
10 {
11     using System.Collections.Generic;
12     using System.Collections.ObjectModel;
13     using System.Data;
14
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.
18
19     internal static class Error
20     {
21         internal static Exception UnhandledExpressionType(ExpressionType expressionType)
22         {
23             return EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnhandledExpressionType(expressionType));
24         }
25         
26         internal static Exception UnhandledBindingType(MemberBindingType memberBindingType)
27         {
28             return EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnhandledBindingType(memberBindingType));
29         }
30     }
31
32     internal static class ReadOnlyCollectionExtensions
33     {
34         internal static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> sequence)
35         {
36             if (sequence == null)
37                 return DefaultReadOnlyCollection<T>.Empty;
38             ReadOnlyCollection<T> col = sequence as ReadOnlyCollection<T>;
39             if (col != null)
40                 return col;
41             return new ReadOnlyCollection<T>(sequence.ToArray());
42         }
43         private static class DefaultReadOnlyCollection<T>
44         {
45             private static ReadOnlyCollection<T> _defaultCollection;
46             internal static ReadOnlyCollection<T> Empty
47             {
48                 get
49                 {
50                     if (_defaultCollection == null)
51                         _defaultCollection = new ReadOnlyCollection<T>(new T[] { });
52                     return _defaultCollection;
53                 }
54             }
55         }
56     }
57 }