18 private class PrecannedResource
20 internal string TypeName;
24 internal PrecannedResource(
string typeName,
byte[] data)
31 private class StreamWrapper
35 internal bool m_closeAfterWrite;
37 internal StreamWrapper(
Stream s,
bool closeAfterWrite)
40 m_closeAfterWrite = closeAfterWrite;
44 private Func<Type, string> typeConverter;
46 private const int _ExpectedNumberOfResources = 1000;
48 private const int AverageNameSize = 40;
50 private const int AverageValueSize = 40;
60 private const int _DefaultBufferSize = 4096;
72 typeConverter = value;
122 if (_resourceList ==
null)
126 _caseInsensitiveDups.
Add(name,
null);
127 _resourceList.
Add(name, value);
143 if (_resourceList ==
null)
147 if (value !=
null && value is
Stream)
149 AddResourceInternal(name, (
Stream)value, closeAfterWrite:
false);
152 _caseInsensitiveDups.
Add(name,
null);
153 _resourceList.
Add(name, value);
170 if (_resourceList ==
null)
174 AddResourceInternal(name, value, closeAfterWrite:
false);
193 if (_resourceList ==
null)
197 AddResourceInternal(name, value, closeAfterWrite);
200 private void AddResourceInternal(
string name,
Stream value,
bool closeAfterWrite)
204 _caseInsensitiveDups.
Add(name,
null);
205 _resourceList.
Add(name, value);
212 _caseInsensitiveDups.
Add(name,
null);
213 _resourceList.
Add(name,
new StreamWrapper(value, closeAfterWrite));
229 if (_resourceList ==
null)
233 _caseInsensitiveDups.
Add(name,
null);
234 _resourceList.
Add(name, value);
252 if (typeName ==
null)
256 if (serializedData ==
null)
260 if (_resourceList ==
null)
264 _caseInsensitiveDups.
Add(name,
null);
265 if (_preserializedData ==
null)
269 _preserializedData.
Add(name,
new PrecannedResource(typeName, serializedData));
280 private void Dispose(
bool disposing)
284 if (_resourceList !=
null)
294 _caseInsensitiveDups =
null;
309 [SecuritySafeCritical]
312 if (_resourceList ==
null)
322 binaryWriter2.
Write(MultitargetingHelpers.GetAssemblyQualifiedName(typeof(
ResourceReader), typeConverter));
324 binaryWriter2.
Flush();
327 binaryWriter.
Write(2);
328 int num = _resourceList.
Count;
329 if (_preserializedData !=
null)
331 num += _preserializedData.
Count;
333 binaryWriter.
Write(num);
334 int[] array =
new int[num];
335 int[] array2 =
new int[num];
368 if (_preserializedData !=
null)
372 sortedList.
Add(preserializedDatum.
Key, preserializedDatum.
Value);
378 array[num2] = FastResourceComparer.HashFunction((
string)enumerator2.
Key);
380 binaryWriter3.
Write((
string)enumerator2.
Key);
382 object value = enumerator2.
Value;
383 ResourceTypeCode resourceTypeCode = FindTypeCode(value, list);
384 Write7BitEncodedInt(binaryWriter4, (
int)resourceTypeCode);
385 PrecannedResource precannedResource = value as PrecannedResource;
386 if (precannedResource !=
null)
388 binaryWriter4.
Write(precannedResource.Data);
392 WriteValue(resourceTypeCode, value, binaryWriter4, objFormatter);
395 binaryWriter.
Write(list.Count);
396 for (
int i = 0; i < list.Count; i++)
398 binaryWriter.
Write(list[i]);
401 binaryWriter.
Flush();
405 for (
int j = 0; j < 8 - num4; j++)
407 binaryWriter.
Write(
"PAD"[j % 3]);
410 int[] array3 = array;
411 foreach (
int value2
in array3)
413 binaryWriter.
Write(value2);
415 int[] array4 = array2;
416 foreach (
int value3
in array4)
418 binaryWriter.
Write(value3);
420 binaryWriter.
Flush();
421 binaryWriter3.
Flush();
422 binaryWriter4.Flush();
425 binaryWriter.
Write(num5);
427 binaryWriter3.
Close();
430 binaryWriter4.Close();
432 binaryWriter.
Flush();
433 _resourceList =
null;
436 private ResourceTypeCode FindTypeCode(
object value,
List<string> types)
440 return ResourceTypeCode.Null;
442 Type type = value.GetType();
443 if (type == typeof(
string))
445 return ResourceTypeCode.String;
447 if (type == typeof(
int))
449 return ResourceTypeCode.Int32;
451 if (type == typeof(
bool))
453 return ResourceTypeCode.Boolean;
455 if (type == typeof(
char))
457 return ResourceTypeCode.Char;
459 if (type == typeof(
byte))
461 return ResourceTypeCode.Byte;
463 if (type == typeof(sbyte))
465 return ResourceTypeCode.SByte;
467 if (type == typeof(
short))
469 return ResourceTypeCode.Int16;
471 if (type == typeof(
long))
473 return ResourceTypeCode.Int64;
475 if (type == typeof(ushort))
477 return ResourceTypeCode.UInt16;
479 if (type == typeof(uint))
481 return ResourceTypeCode.UInt32;
483 if (type == typeof(ulong))
485 return ResourceTypeCode.UInt64;
487 if (type == typeof(
float))
489 return ResourceTypeCode.Single;
491 if (type == typeof(
double))
493 return ResourceTypeCode.Double;
495 if (type == typeof(decimal))
497 return ResourceTypeCode.Decimal;
499 if (type == typeof(DateTime))
501 return ResourceTypeCode.DateTime;
503 if (type == typeof(TimeSpan))
505 return ResourceTypeCode.TimeSpan;
507 if (type == typeof(
byte[]))
509 return ResourceTypeCode.ByteArray;
511 if (type == typeof(StreamWrapper))
513 return ResourceTypeCode.Stream;
516 if (type == typeof(PrecannedResource))
518 text = ((PrecannedResource)value).TypeName;
521 text = text.Substring(17);
522 return (ResourceTypeCode)
Enum.Parse(typeof(ResourceTypeCode), text);
527 text = MultitargetingHelpers.GetAssemblyQualifiedName(type, typeConverter);
535 return (ResourceTypeCode)(num + 64);
538 private void WriteValue(ResourceTypeCode typeCode,
object value,
BinaryWriter writer,
IFormatter objFormatter)
542 case ResourceTypeCode.Null:
544 case ResourceTypeCode.String:
545 writer.
Write((
string)value);
547 case ResourceTypeCode.Boolean:
548 writer.
Write((
bool)value);
550 case ResourceTypeCode.Char:
551 writer.
Write((ushort)(
char)value);
553 case ResourceTypeCode.Byte:
554 writer.
Write((
byte)value);
556 case ResourceTypeCode.SByte:
557 writer.
Write((sbyte)value);
559 case ResourceTypeCode.Int16:
560 writer.
Write((
short)value);
562 case ResourceTypeCode.UInt16:
563 writer.
Write((ushort)value);
565 case ResourceTypeCode.Int32:
566 writer.
Write((
int)value);
568 case ResourceTypeCode.UInt32:
569 writer.
Write((uint)value);
571 case ResourceTypeCode.Int64:
572 writer.
Write((
long)value);
574 case ResourceTypeCode.UInt64:
575 writer.
Write((ulong)value);
577 case ResourceTypeCode.Single:
578 writer.
Write((
float)value);
580 case ResourceTypeCode.Double:
581 writer.
Write((
double)value);
583 case ResourceTypeCode.Decimal:
584 writer.
Write((decimal)value);
586 case ResourceTypeCode.DateTime:
588 long value2 = ((
DateTime)value).ToBinary();
589 writer.
Write(value2);
592 case ResourceTypeCode.TimeSpan:
593 writer.
Write(((TimeSpan)value).Ticks);
595 case ResourceTypeCode.ByteArray:
597 byte[] array2 = (
byte[])value;
598 writer.
Write(array2.Length);
599 writer.
Write(array2, 0, array2.Length);
602 case ResourceTypeCode.Stream:
604 StreamWrapper streamWrapper = (StreamWrapper)value;
605 if (streamWrapper.m_stream.GetType() == typeof(
MemoryStream))
608 if (memoryStream.
Length >
int.MaxValue)
610 throw new ArgumentException(Environment.GetResourceString(
"ArgumentOutOfRange_StreamLength"));
612 memoryStream.InternalGetOriginAndLength(out
int origin, out
int length);
613 byte[] buffer = memoryStream.InternalGetBuffer();
614 writer.
Write(length);
615 writer.
Write(buffer, origin, length);
618 Stream stream = streamWrapper.m_stream;
619 if (stream.
Length >
int.MaxValue)
621 throw new ArgumentException(Environment.GetResourceString(
"ArgumentOutOfRange_StreamLength"));
625 byte[] array =
new byte[4096];
627 while ((num = stream.
Read(array, 0, array.Length)) != 0)
629 writer.
Write(array, 0, num);
631 if (streamWrapper.m_closeAfterWrite)
643 private static void Write7BitEncodedInt(
BinaryWriter store,
int value)
646 for (num = (uint)value; num >= 128; num >>= 7)
648 store.
Write((
byte)(num | 0x80));
650 store.
Write((
byte)num);
Represents a character encoding.To browse the .NET Framework source code for this type,...
virtual void Close()
Closes the current T:System.IO.BinaryWriter and the underlying stream.
virtual Stream BaseStream
Gets the underlying stream of the T:System.IO.BinaryWriter.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static void SetAttributes(string path, FileAttributes fileAttributes)
Sets the specified T:System.IO.FileAttributes of the file on the specified path.
void AddResource(string name, Stream value, bool closeAfterWrite)
Adds a named resource specified as a stream to the list of resources to be written,...
override long Length
Gets the length of the stream in bytes.
abstract int Read([In] [Out] byte[] buffer, int offset, int count)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
TValue Value
Gets the value in the key/value pair.
Provides the base functionality for writing resources to an output file or stream.
bool MoveNext()
Advances the enumerator to the next element of the collection.
FileOptions
Represents advanced options for creating a T:System.IO.FileStream object.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.List`1.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
virtual void Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlyin...
object Key
Gets the key of the current dictionary entry.
FileMode
Specifies how the operating system should open a file.
static Encoding Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
FileAttributes
Provides attributes for files and directories.
abstract bool CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writi...
void AddResource(string name, byte[] value)
Adds a named resource specified as a byte array to the list of resources to be written.
void AddResource(string name, object value)
Adds a named resource specified as an object to the list of resources to be written.
void Dispose()
Allows users to close the resource file or stream, explicitly releasing resources.
static string GetTempFileName()
Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Represents a resource manager that provides convenient access to culture-specific resources at run ti...
A type representing a date and time value.
ResourceWriter(Stream stream)
Initializes a new instance of the T:System.Resources.ResourceWriter class that writes the resources t...
virtual void Add(object key, object value)
Adds an element with the specified key and value to a T:System.Collections.SortedList object.
IPermission AddPermission(IPermission perm)
Adds a specified permission to the T:System.Security.PermissionSet.
SeekOrigin
Specifies the position in a stream to use for seeking.
virtual long Seek(int offset, SeekOrigin origin)
Sets the position within the current stream.
virtual byte [] GetBuffer()
Returns the array of unsigned bytes from which this stream was created.
Defines a key/value pair that can be set or retrieved.
void Generate()
Saves all resources to the output stream in the system default format.
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
TKey Key
Gets the key in the key/value pair.
Provides information about, and means to manipulate, the current environment and platform....
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
ResourceWriter(string fileName)
Initializes a new instance of the T:System.Resources.ResourceWriter class that writes the resources t...
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
static void Sort(Array array)
Sorts the elements in an entire one-dimensional T:System.Array using the T:System....
Represents a collection that can contain many different types of permissions.
void Close()
Saves the resources to the output stream and then closes it.
int Count
Gets the number of key/value pairs contained in the T:System.Collections.Generic.Dictionary`2.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
void AddResource(string name, Stream value)
Adds a named resource specified as a stream to the list of resources to be written.
static readonly int HeaderVersionNumber
Specifies the version of resource file headers that the current implementation of T:System....
void AddResourceData(string name, string typeName, byte[] serializedData)
Adds a unit of data as a resource to the list of resources to be written.
The exception that is thrown when an I/O error occurs.
void CopyTo(Stream destination)
Reads the bytes from the current stream and writes them to another stream.
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and ...
Func< Type, string > TypeNameConverter
Gets or sets a delegate that enables resource assemblies to be written that target versions of the ....
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents type declarations: class types, interface types, array types, value types,...
void AddResource(string name, string value)
Adds a string resource to the list of resources to be written.
virtual void Write(bool value)
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing t...
Enumerates the resources in a binary resources (.resources) file by reading sequential resource name/...
The exception that is thrown when one of the arguments provided to a method is not valid.
abstract long Length
When overridden in a derived class, gets the length in bytes of the stream.
Writes resources in the system-default format to an output file or an output stream....
Attribute can be applied to an enumeration.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
FileAccess
Defines constants for read, write, or read/write access to a file.
object Value
Gets the value of the current dictionary entry.
int IndexOf(T item)
Searches for the specified object and returns the zero-based index of the first occurrence within the...
static readonly int MagicNumber
Holds the number used to identify resource files.
abstract long Position
When overridden in a derived class, gets or sets the position within the current stream.
Enumerates the elements of a nongeneric dictionary.
static Encoding UTF8
Gets an encoding for the UTF-8 format.
static StringComparer OrdinalIgnoreCase
Gets a T:System.StringComparer object that performs a case-insensitive ordinal string comparison.
The exception that is thrown when a method call is invalid for the object's current state.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
void Add(TKey key, TValue value)
Adds the specified key and value to the dictionary.
Controls access to system and user environment variables. This class cannot be inherited.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
The exception that is thrown when the operating system denies access because of an I/O error or a spe...
StreamingContextStates
Defines a set of flags that specifies the source or destination context for the stream during seriali...
Controls the ability to access files and folders. This class cannot be inherited.
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
Writes primitive types in binary to a stream and supports writing strings in a specific encoding.
Performs operations on T:System.String instances that contain file or directory path information....
Represents a string comparison operation that uses specific case and culture-based or ordinal compari...
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....