1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
9 using System.Collections;
10 using System.Collections.Generic;
11 using System.Diagnostics;
12 using System.Runtime.InteropServices;
13 using System.Runtime.CompilerServices;
14 using Internal.Runtime.CompilerServices;
16 namespace System.Runtime.InteropServices.WindowsRuntime
18 // This is a set of stub methods implementing the support for the IReadOnlyCollection<T> interface on WinRT
19 // objects that support IVectorView<T>. Used by the interop mashaling infrastructure.
21 // The methods on this class must be written VERY carefully to avoid introducing security holes.
22 // That's because they are invoked with special "this"! The "this" object
23 // for all of these methods are not VectorViewToReadOnlyCollectionAdapter objects. Rather, they are of type
24 // IVectorView<T>. No actual VectorViewToReadOnlyCollectionAdapter object is ever instantiated. Thus, you will see
25 // a lot of expressions that cast "this" to "IVectorView<T>".
26 internal sealed class VectorViewToReadOnlyCollectionAdapter
28 private VectorViewToReadOnlyCollectionAdapter()
30 Debug.Fail("This class is never instantiated");
34 internal int Count<T>()
36 IVectorView<T> _this = Unsafe.As<IVectorView<T>>(this);
37 uint size = _this.Size;
38 if (((uint)int.MaxValue) < size)
40 throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);