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.
6 using System.Diagnostics;
7 using Internal.Runtime.CompilerServices;
9 namespace System.Runtime.InteropServices.WindowsRuntime
11 // This is a set of stub methods implementing the support for the IReadOnlyCollection<T> interface on WinRT
12 // objects that support IVectorView<T>. Used by the interop mashaling infrastructure.
14 // The methods on this class must be written VERY carefully to avoid introducing security holes.
15 // That's because they are invoked with special "this"! The "this" object
16 // for all of these methods are not VectorViewToReadOnlyCollectionAdapter objects. Rather, they are of type
17 // IVectorView<T>. No actual VectorViewToReadOnlyCollectionAdapter object is ever instantiated. Thus, you will see
18 // a lot of expressions that cast "this" to "IVectorView<T>".
19 internal sealed class VectorViewToReadOnlyCollectionAdapter
21 private VectorViewToReadOnlyCollectionAdapter()
23 Debug.Fail("This class is never instantiated");
27 internal int Count<T>()
29 IVectorView<T> _this = Unsafe.As<IVectorView<T>>(this);
30 uint size = _this.Size;
31 if (((uint)int.MaxValue) < size)
33 throw new InvalidOperationException(SR.InvalidOperation_CollectionBackingListTooLarge);