Initial commit
[mono.git] / mcs / class / referencesource / mscorlib / system / globalization / globalizationassembly.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6
7 namespace System.Globalization {
8     using System;
9     using System.Reflection;
10     using System.Collections;
11     using System.Collections.Generic;
12     using System.Threading;
13     using System.Security;
14     using System.Security.Principal;
15     using System.Security.Permissions;
16     using System.Runtime.CompilerServices;
17     using System.Runtime.ConstrainedExecution;
18     using System.Runtime.Versioning;
19     using System.IO;
20     using System.Diagnostics.Contracts;
21
22     
23     /*=================================GlobalizationAssembly==========================
24     **
25     ** This class provides the table loading wrapper that calls GetManifestResourceStream
26     **
27     ** It used to provide an idea for sort versioning, but that proved to not work
28     **
29     ============================================================================*/
30     internal sealed class GlobalizationAssembly
31     {
32         // ----------------------------------------------------------------------------------------------------
33         //
34         // Instance data members and instance methods.
35         //
36         // ----------------------------------------------------------------------------------------------------
37         [System.Security.SecurityCritical]  // auto-generated
38         [ResourceExposure(ResourceScope.Process)]
39         [ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
40         internal unsafe static byte* GetGlobalizationResourceBytePtr(Assembly assembly, String tableName) {
41             Contract.Assert(assembly != null, "assembly can not be null.  This should be generally the mscorlib.dll assembly.");
42             Contract.Assert(tableName != null, "table name can not be null");
43             
44             Stream stream = assembly.GetManifestResourceStream(tableName);
45             UnmanagedMemoryStream bytesStream = stream as UnmanagedMemoryStream;
46             if (bytesStream != null) {
47                 byte* bytes = bytesStream.PositionPointer;
48                 if (bytes != null) {
49                     return (bytes);
50                 }
51             }
52             
53             Contract.Assert(
54                     false, 
55                     String.Format(
56                         CultureInfo.CurrentCulture,
57                         "Didn't get the resource table {0} for System.Globalization from {1}", 
58                         tableName, 
59                         assembly));
60             
61             // We can not continue if we can't get the resource.
62             throw new InvalidOperationException();
63         }
64
65     }
66 }
67