Files
Dec2017-Script-Dump/mscorlib/System/Resources/ResourceSet.cs
T
2026-06-04 11:42:34 +02:00

291 lines
12 KiB
C#

using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
namespace System.Resources
{
/// <summary>Stores all the resources localized for one particular culture, ignoring all other cultures, including any fallback rules.</summary>
// Token: 0x0200027D RID: 637
[ComVisible(true)]
[Serializable]
public class ResourceSet : IEnumerable, IDisposable
{
/// <summary>Initializes a new instance of the <see cref="T:System.Resources.ResourceSet" /> class with default properties.</summary>
// Token: 0x06002074 RID: 8308 RVA: 0x00076A78 File Offset: 0x00074C78
protected ResourceSet()
{
this.Table = new Hashtable();
this.resources_read = true;
}
/// <summary>Creates a new instance of the <see cref="T:System.Resources.ResourceSet" /> class using the specified resource reader.</summary>
/// <param name="reader">The reader that will be used. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="reader" /> parameter is null. </exception>
// Token: 0x06002075 RID: 8309 RVA: 0x00076A94 File Offset: 0x00074C94
public ResourceSet(IResourceReader reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
this.Table = new Hashtable();
this.Reader = reader;
}
/// <summary>Creates a new instance of the <see cref="T:System.Resources.ResourceSet" /> class using the system default <see cref="T:System.Resources.ResourceReader" /> that reads resources from the given stream.</summary>
/// <param name="stream">The <see cref="T:System.IO.Stream" /> of resources to be read. The stream should refer to an existing resources file. </param>
/// <exception cref="T:System.ArgumentException">The <paramref name="stream" /> is not readable. </exception>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="stream" /> parameter is null. </exception>
// Token: 0x06002076 RID: 8310 RVA: 0x00076AC0 File Offset: 0x00074CC0
public ResourceSet(Stream stream)
{
this.Table = new Hashtable();
this.Reader = new ResourceReader(stream);
}
// Token: 0x06002077 RID: 8311 RVA: 0x00076AE0 File Offset: 0x00074CE0
internal ResourceSet(UnmanagedMemoryStream stream)
{
this.Table = new Hashtable();
this.Reader = new ResourceReader(stream);
}
/// <summary>Creates a new instance of the <see cref="T:System.Resources.ResourceSet" /> class using the system default <see cref="T:System.Resources.ResourceReader" /> that opens and reads resources from the given file.</summary>
/// <param name="fileName">Resource file to read. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="fileName" /> parameter is null. </exception>
// Token: 0x06002078 RID: 8312 RVA: 0x00076B00 File Offset: 0x00074D00
public ResourceSet(string fileName)
{
this.Table = new Hashtable();
this.Reader = new ResourceReader(fileName);
}
/// <summary>Returns an <see cref="T:System.Collections.IEnumerator" /> object to avoid a race condition with Dispose. This member is not intended to be used directly from your code.</summary>
/// <returns>An <see cref="T:System.Collections.IDictionaryEnumerator" /> for the current <see cref="T:System.Resources.ResourceSet" /> object.</returns>
// Token: 0x06002079 RID: 8313 RVA: 0x00076B20 File Offset: 0x00074D20
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
/// <summary>Closes and releases any resources used by this <see cref="T:System.Resources.ResourceSet" />.</summary>
// Token: 0x0600207A RID: 8314 RVA: 0x00076B28 File Offset: 0x00074D28
public virtual void Close()
{
this.Dispose();
}
/// <summary>Disposes of the resources (other than memory) used by the current instance of <see cref="T:System.Resources.ResourceSet" />.</summary>
// Token: 0x0600207B RID: 8315 RVA: 0x00076B30 File Offset: 0x00074D30
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>Releases resources (other than memory) associated with the current instance, closing internal managed objects if requested.</summary>
/// <param name="disposing">Indicates whether the objects contained in the current instance should be explicitly closed. </param>
// Token: 0x0600207C RID: 8316 RVA: 0x00076B40 File Offset: 0x00074D40
protected virtual void Dispose(bool disposing)
{
if (disposing && this.Reader != null)
{
this.Reader.Close();
}
this.Reader = null;
this.Table = null;
this.disposed = true;
}
/// <summary>Returns the preferred resource reader class for this kind of <see cref="T:System.Resources.ResourceSet" />.</summary>
/// <returns>Returns the <see cref="T:System.Type" /> for the preferred resource reader for this kind of <see cref="T:System.Resources.ResourceSet" />.</returns>
// Token: 0x0600207D RID: 8317 RVA: 0x00076B74 File Offset: 0x00074D74
public virtual Type GetDefaultReader()
{
return typeof(ResourceReader);
}
/// <summary>Returns the preferred resource writer class for this kind of <see cref="T:System.Resources.ResourceSet" />.</summary>
/// <returns>Returns the <see cref="T:System.Type" /> for the preferred resource writer for this kind of <see cref="T:System.Resources.ResourceSet" />.</returns>
// Token: 0x0600207E RID: 8318 RVA: 0x00076B80 File Offset: 0x00074D80
public virtual Type GetDefaultWriter()
{
return typeof(ResourceWriter);
}
/// <summary>Returns an <see cref="T:System.Collections.IDictionaryEnumerator" /> that can iterate through the <see cref="T:System.Resources.ResourceSet" />.</summary>
/// <returns>An <see cref="T:System.Collections.IDictionaryEnumerator" /> for this <see cref="T:System.Resources.ResourceSet" />.</returns>
/// <exception cref="T:System.ObjectDisposedException">The resource set has been closed or disposed. </exception>
// Token: 0x0600207F RID: 8319 RVA: 0x00076B8C File Offset: 0x00074D8C
[ComVisible(false)]
public virtual IDictionaryEnumerator GetEnumerator()
{
if (this.disposed)
{
throw new ObjectDisposedException("ResourceSet is closed.");
}
this.ReadResources();
return this.Table.GetEnumerator();
}
// Token: 0x06002080 RID: 8320 RVA: 0x00076BB8 File Offset: 0x00074DB8
private object GetObjectInternal(string name, bool ignoreCase)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (this.disposed)
{
throw new ObjectDisposedException("ResourceSet is closed.");
}
this.ReadResources();
object obj = this.Table[name];
if (obj != null)
{
return obj;
}
if (ignoreCase)
{
foreach (object obj2 in this.Table)
{
DictionaryEntry dictionaryEntry = (DictionaryEntry)obj2;
string text = (string)dictionaryEntry.Key;
if (string.Compare(text, name, true, CultureInfo.InvariantCulture) == 0)
{
return dictionaryEntry.Value;
}
}
}
return null;
}
/// <summary>Searches for a resource object with the specified name.</summary>
/// <returns>The requested resource.</returns>
/// <param name="name">Case-sensitive name of the resource to search for. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
/// <exception cref="T:System.ObjectDisposedException">The object has been closed or disposed.</exception>
// Token: 0x06002081 RID: 8321 RVA: 0x00076C9C File Offset: 0x00074E9C
public virtual object GetObject(string name)
{
return this.GetObjectInternal(name, false);
}
/// <summary>Searches for a resource object with the specified name in a case-insensitive manner, if requested.</summary>
/// <returns>The requested resource.</returns>
/// <param name="name">Name of the resource to search for. </param>
/// <param name="ignoreCase">Indicates whether the case of the specified name should be ignored. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
/// <exception cref="T:System.ObjectDisposedException">The object has been closed or disposed.</exception>
// Token: 0x06002082 RID: 8322 RVA: 0x00076CA8 File Offset: 0x00074EA8
public virtual object GetObject(string name, bool ignoreCase)
{
return this.GetObjectInternal(name, ignoreCase);
}
// Token: 0x06002083 RID: 8323 RVA: 0x00076CB4 File Offset: 0x00074EB4
private string GetStringInternal(string name, bool ignoreCase)
{
object @object = this.GetObject(name, ignoreCase);
if (@object == null)
{
return null;
}
string text = @object as string;
if (text == null)
{
throw new InvalidOperationException(string.Format("Resource '{0}' is not a String. Use GetObject instead.", name));
}
return text;
}
/// <summary>Searches for a <see cref="T:System.String" /> resource with the specified name.</summary>
/// <returns>The value of a resource, if the value is a <see cref="T:System.String" />.</returns>
/// <param name="name">Name of the resource to search for. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
/// <exception cref="T:System.ObjectDisposedException">The object has been closed or disposed.</exception>
// Token: 0x06002084 RID: 8324 RVA: 0x00076CF4 File Offset: 0x00074EF4
public virtual string GetString(string name)
{
return this.GetStringInternal(name, false);
}
/// <summary>Searches for a <see cref="T:System.String" /> resource with the specified name in a case-insensitive manner, if requested.</summary>
/// <returns>The value of a resource, if the value is a <see cref="T:System.String" />.</returns>
/// <param name="name">Name of the resource to search for. </param>
/// <param name="ignoreCase">Indicates whether the case of the case of the specified name should be ignored. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
/// <exception cref="T:System.ObjectDisposedException">The object has been closed or disposed.</exception>
// Token: 0x06002085 RID: 8325 RVA: 0x00076D00 File Offset: 0x00074F00
public virtual string GetString(string name, bool ignoreCase)
{
return this.GetStringInternal(name, ignoreCase);
}
/// <summary>Reads all the resources and stores them in a <see cref="T:System.Collections.Hashtable" /> indicated in the <see cref="F:System.Resources.ResourceSet.Table" /> property.</summary>
// Token: 0x06002086 RID: 8326 RVA: 0x00076D0C File Offset: 0x00074F0C
protected virtual void ReadResources()
{
if (this.resources_read)
{
return;
}
if (this.Reader == null)
{
throw new ObjectDisposedException("ResourceSet is closed.");
}
Hashtable table = this.Table;
lock (table)
{
if (!this.resources_read)
{
IDictionaryEnumerator enumerator = this.Reader.GetEnumerator();
enumerator.Reset();
while (enumerator.MoveNext())
{
this.Table.Add(enumerator.Key, enumerator.Value);
}
this.resources_read = true;
}
}
}
// Token: 0x06002087 RID: 8327 RVA: 0x00076DC0 File Offset: 0x00074FC0
internal UnmanagedMemoryStream GetStream(string name, bool ignoreCase)
{
if (this.Reader == null)
{
throw new ObjectDisposedException("ResourceSet is closed.");
}
IDictionaryEnumerator enumerator = this.Reader.GetEnumerator();
enumerator.Reset();
while (enumerator.MoveNext())
{
if (string.Compare(name, (string)enumerator.Key, ignoreCase) == 0)
{
return ((ResourceReader.ResourceEnumerator)enumerator).ValueAsStream;
}
}
return null;
}
/// <summary>Indicates the <see cref="T:System.Resources.IResourceReader" /> used to read the resources.</summary>
// Token: 0x04000B7F RID: 2943
[NonSerialized]
protected IResourceReader Reader;
/// <summary>The <see cref="T:System.Collections.Hashtable" /> in which the resources are stored.</summary>
// Token: 0x04000B80 RID: 2944
protected Hashtable Table;
// Token: 0x04000B81 RID: 2945
private bool resources_read;
// Token: 0x04000B82 RID: 2946
[NonSerialized]
private bool disposed;
}
}