<Compile Include="$(BclSourcesRoot)\System\IAppDomainPauseManager.cs" />
<Compile Include="$(BclSourcesRoot)\System\AppDomainAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\AppDomainUnloadedException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\ArgumentOutOfRangeException.cs" />
<Compile Include="$(BclSourcesRoot)\System\ArgIterator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Attribute.cs" />
- <Compile Include="$(BclSourcesRoot)\System\BadImageFormatException.cs" />
<Compile Include="$(BclSourcesRoot)\System\BitConverter.cs" />
<Compile Include="$(BclSourcesRoot)\System\Boolean.cs" />
<Compile Include="$(BclSourcesRoot)\System\Buffer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\IResourceGroveler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\LooselyLinkedResourceReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\ManifestBasedResourceGroveler.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Resources\ResourceFallbackManager.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\ResourceManager.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\ResourceReader.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Resources\ResourceSet.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Resources\RuntimeResourceSet.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Nullable.cs" />
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\SafeFindHandle.cs" />
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\SafeWaitHandle.cs" />
- <Compile Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\Win32SafeHandles.cs" />
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ // Class of safe handle which uses only -1 as an invalid handle.
+ public abstract class SafeHandleMinusOneIsInvalid : SafeHandle
+ {
+ protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle)
+ {
+ }
+
+ public override bool IsInvalid => handle == new IntPtr(-1);
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ // Class of safe handle which uses 0 or -1 as an invalid handle.
+ public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
+ {
+ protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
+ {
+ }
+
+ public override bool IsInvalid => handle == IntPtr.Zero || handle == new IntPtr(-1);
+ }
+}
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleMinusOneIsInvalid.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleZeroOrMinusOneIsInvalid.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeHandleMinusOneIsInvalid.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeHandleZeroOrMinusOneIsInvalid.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Action.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ApplicationException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ArgumentException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ArgumentNullException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\ArgumentOutOfRangeException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ArithmeticException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ArrayTypeMismatchException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\AssemblyLoadEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\AsyncCallback.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\AttributeTargets.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\AttributeUsageAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\BadImageFormatException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ArrayPool.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ConfigurableArrayPool.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\TlsOverPerCoreLockedStacksArrayPool.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingManifestResourceException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingSatelliteAssemblyException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\NeutralResourcesLanguageAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceFallbackManager.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceSet.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceTypeCode.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Resources\RuntimeResourceSet.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\SatelliteContractVersionAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\UltimateResourceFallbackLocation.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AccessedThroughPropertyAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FormattableStringFactory.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IAsyncStateMachine.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IndexerNameAttribute.cs"/>
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\INotifyCompletion.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsConst.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IteratorStateMachineAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingProvider.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\Normalization.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeEncoding.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF32Encoding.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF8Encoding.cs"/>
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeEncoding.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ThreadAttributes.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\AbandonedMutexException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ApartmentState.cs"/>
**
=============================================================================*/
-
-using System;
-using System.Runtime.Remoting;
-using System.Runtime.Serialization;
using System.Globalization;
-using System.Diagnostics.Contracts;
+using System.Runtime.Serialization;
namespace System
{
// The ArgumentOutOfRangeException is thrown when an argument
// is outside the legal range for that argument.
[Serializable]
- public class ArgumentOutOfRangeException : ArgumentException, ISerializable
+ public class ArgumentOutOfRangeException : ArgumentException
{
- private static volatile String _rangeMessage;
- private Object m_actualValue;
-
- private static String RangeMessage
- {
- get
- {
- if (_rangeMessage == null)
- _rangeMessage = SR.Arg_ArgumentOutOfRangeException;
- return _rangeMessage;
- }
- }
+ private Object _actualValue;
// Creates a new ArgumentOutOfRangeException with its message
// string set to a default message explaining an argument was out of range.
public ArgumentOutOfRangeException()
- : base(RangeMessage)
+ : base(SR.Arg_ArgumentOutOfRangeException)
{
HResult = __HResults.COR_E_ARGUMENTOUTOFRANGE;
}
public ArgumentOutOfRangeException(String paramName)
- : base(RangeMessage, paramName)
+ : base(SR.Arg_ArgumentOutOfRangeException, paramName)
{
HResult = __HResults.COR_E_ARGUMENTOUTOFRANGE;
}
public ArgumentOutOfRangeException(String paramName, Object actualValue, String message)
: base(message, paramName)
{
- m_actualValue = actualValue;
+ _actualValue = actualValue;
HResult = __HResults.COR_E_ARGUMENTOUTOFRANGE;
}
+ protected ArgumentOutOfRangeException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ _actualValue = info.GetValue("ActualValue", typeof(Object));
+ }
+
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+ info.AddValue("ActualValue", _actualValue, typeof(Object));
+ }
+
public override String Message
{
get
{
String s = base.Message;
- if (m_actualValue != null)
+ if (_actualValue != null)
{
- String valueMessage = SR.Format(SR.ArgumentOutOfRange_ActualValue, m_actualValue.ToString());
+ String valueMessage = SR.Format(SR.ArgumentOutOfRange_ActualValue, _actualValue.ToString());
if (s == null)
return valueMessage;
return s + Environment.NewLine + valueMessage;
// want to avoid sticking printf's in their code.
public virtual Object ActualValue
{
- get { return m_actualValue; }
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- Contract.EndContractBlock();
- base.GetObjectData(info, context);
- info.AddValue("ActualValue", m_actualValue, typeof(Object));
- }
-
- protected ArgumentOutOfRangeException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- m_actualValue = info.GetValue("ActualValue", typeof(Object));
+ get { return _actualValue; }
}
}
}
**
===========================================================*/
+using System.Globalization;
+using System.IO;
+using System.Runtime.Serialization;
+
namespace System
{
- using System;
- using System.Runtime.Serialization;
- using FileLoadException = System.IO.FileLoadException;
- using SecurityException = System.Security.SecurityException;
- using System.Globalization;
-
[Serializable]
public class BadImageFormatException : SystemException
{
_fileName = fileName;
}
+ protected BadImageFormatException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ _fileName = info.GetString("BadImageFormat_FileName");
+ _fusionLog = info.GetString("BadImageFormat_FusionLog");
+ }
+
+ public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ base.GetObjectData(info, context);
+
+ info.AddValue("BadImageFormat_FileName", _fileName, typeof(String));
+ info.AddValue("BadImageFormat_FusionLog", _fusionLog, typeof(String));
+ }
+
public override String Message
{
get
if (_message == null)
{
if ((_fileName == null) &&
- (HResult == System.__HResults.COR_E_EXCEPTION))
+ (HResult == __HResults.COR_E_EXCEPTION))
_message = SR.Arg_BadImageFormatException;
else
public override String ToString()
{
- String s = GetType().FullName + ": " + Message;
+ String s = GetType().ToString() + ": " + Message;
if (_fileName != null && _fileName.Length != 0)
s += Environment.NewLine + SR.Format(SR.IO_FileName_Name, _fileName);
if (StackTrace != null)
s += Environment.NewLine + StackTrace;
- try
- {
- if (FusionLog != null)
- {
- if (s == null)
- s = " ";
- s += Environment.NewLine;
- s += Environment.NewLine;
- s += FusionLog;
- }
- }
- catch (SecurityException)
- {
- }
- return s;
- }
- protected BadImageFormatException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- // Base class constructor will check info != null.
-
- _fileName = info.GetString("BadImageFormat_FileName");
- try
+ if (_fusionLog != null)
{
- _fusionLog = info.GetString("BadImageFormat_FusionLog");
+ if (s == null)
+ s = " ";
+ s += Environment.NewLine;
+ s += Environment.NewLine;
+ s += _fusionLog;
}
- catch
- {
- _fusionLog = null;
- }
- }
- private BadImageFormatException(String fileName, String fusionLog, int hResult)
- : base(null)
- {
- HResult = hResult;
- _fileName = fileName;
- _fusionLog = fusionLog;
- SetMessageField();
+ return s;
}
public String FusionLog
{
-#pragma warning disable CS0618 // Type or member is obsolete
-#pragma warning restore CS0618 // Type or member is obsolete
get { return _fusionLog; }
}
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- // Serialize data for our base classes. base will verify info != null.
- base.GetObjectData(info, context);
-
- // Serialize data for this class
- info.AddValue("BadImageFormat_FileName", _fileName, typeof(String));
- try
- {
- info.AddValue("BadImageFormat_FusionLog", FusionLog, typeof(String));
- }
- catch (SecurityException)
- {
- }
- }
}
}
private CultureInfo m_neutralResourcesCulture;
private bool m_useParents;
- // This is a cache of the thread, process, user, and OS-preferred fallback cultures.
- // However, each thread may have a different value, and these may change during the
- // lifetime of the process. So this cache must be verified each time we use it.
- // Hence, we'll keep an array of strings for culture names & check it each time,
- // but we'll really cache an array of CultureInfo's. Using thread-local statics
- // as well to avoid differences across threads.
- [ThreadStatic]
- private static CultureInfo[] cachedOsFallbackArray;
-
internal ResourceFallbackManager(CultureInfo startingCulture, CultureInfo neutralResourcesCulture, bool useParents)
{
if (startingCulture != null)
**
===========================================================*/
+using System;
+using System.Collections;
+using System.IO;
+using System.Globalization;
+using System.Runtime.InteropServices;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Versioning;
+using System.Diagnostics.Contracts;
+using System.Collections.Generic;
+
namespace System.Resources
{
- using System;
- using System.Collections;
- using System.IO;
- using System.Globalization;
- using System.Runtime.InteropServices;
- using System.Reflection;
- using System.Runtime.Serialization;
- using System.Runtime.Versioning;
- using System.Diagnostics.Contracts;
-
// A ResourceSet stores all the resources defined in one particular CultureInfo.
//
// The method used to load resources is straightforward - this class
// enumerates over an IResourceReader, loading every name and value, and
// stores them in a hash table. Custom IResourceReaders can be used.
- //
+ //
[Serializable]
public class ResourceSet : IDisposable, IEnumerable
{
- [NonSerialized] protected IResourceReader Reader;
- internal Hashtable Table;
+ [NonSerialized]
+ protected IResourceReader Reader;
- private Hashtable _caseInsensitiveTable; // For case-insensitive lookups.
-
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- [OptionalField]
- private Assembly _assembly; // For LooselyLinkedResourceReferences
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
+ private Dictionary<object, object> _table;
+ private Dictionary<object, object> _caseInsensitiveTable; // For case-insensitive lookups.
protected ResourceSet()
{
ReadResources();
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- public ResourceSet(String fileName, Assembly assembly)
- {
- Reader = new ResourceReader(fileName);
- CommonInit();
- _assembly = assembly;
- ReadResources();
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
// Creates a ResourceSet using the system default ResourceReader
// implementation. Use this constructor to read from an open stream
// of data.
ReadResources();
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- public ResourceSet(Stream stream, Assembly assembly)
- {
- Reader = new ResourceReader(stream);
- CommonInit();
- _assembly = assembly;
- ReadResources();
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
public ResourceSet(IResourceReader reader)
{
if (reader == null)
ReadResources();
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- public ResourceSet(IResourceReader reader, Assembly assembly)
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
- Contract.EndContractBlock();
- Reader = reader;
- CommonInit();
- _assembly = assembly;
- ReadResources();
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
private void CommonInit()
{
- Table = new Hashtable();
+ _table = new Dictionary<object, object>();
}
// Closes and releases any resources used by this ResourceSet, if any.
}
Reader = null;
_caseInsensitiveTable = null;
- Table = null;
+ _table = null;
}
public void Dispose()
Dispose(true);
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- // Optional - used for resolving assembly manifest resource references.
- // This can safely be null.
- public Assembly Assembly {
- get { return _assembly; }
- /*protected*/ set { _assembly = value; }
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
// Returns the preferred IResourceReader class for this kind of ResourceSet.
// Subclasses of ResourceSet using their own Readers &; should override
// GetDefaultReader and GetDefaultWriter.
// GetDefaultReader and GetDefaultWriter.
public virtual Type GetDefaultWriter()
{
- return Type.GetType("System.Resources.ResourceWriter, System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=" + AssemblyRef.MicrosoftPublicKeyToken, throwOnError: true);
+ Assembly resourceWriterAssembly = Assembly.Load("System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
+ return resourceWriterAssembly.GetType("System.Resources.ResourceWriter", true);
}
public virtual IDictionaryEnumerator GetEnumerator()
private IDictionaryEnumerator GetEnumeratorHelper()
{
- Hashtable copyOfTable = Table; // Avoid a race with Dispose
+ Dictionary<object, object> copyOfTable = _table; // Avoid a race with Dispose
if (copyOfTable == null)
throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
return copyOfTable.GetEnumerator();
while (en.MoveNext())
{
Object value = en.Value;
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- if (Assembly != null && value is LooselyLinkedResourceReference) {
- LooselyLinkedResourceReference assRef = (LooselyLinkedResourceReference) value;
- value = assRef.Resolve(Assembly);
- }
-#endif //LOOSELYLINKEDRESOURCEREFERENCE
- Table.Add(en.Key, value);
+ _table.Add(en.Key, value);
}
// While technically possible to close the Reader here, don't close it
// to help with some WinRes lifetime issues.
private Object GetObjectInternal(String name)
{
if (name == null)
- throw new ArgumentNullException(nameof(name));
+ throw new ArgumentNullException("name");
Contract.EndContractBlock();
- Hashtable copyOfTable = Table; // Avoid a race with Dispose
+ Dictionary<object, object> copyOfTable = _table; // Avoid a race with Dispose
if (copyOfTable == null)
throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
private Object GetCaseInsensitiveObjectInternal(String name)
{
- Hashtable copyOfTable = Table; // Avoid a race with Dispose
+ Dictionary<object, object> copyOfTable = _table; // Avoid a race with Dispose
if (copyOfTable == null)
throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
- Hashtable caseTable = _caseInsensitiveTable; // Avoid a race condition with Close
+ Dictionary<object, object> caseTable = _caseInsensitiveTable; // Avoid a race condition with Close
if (caseTable == null)
{
- caseTable = new Hashtable(StringComparer.OrdinalIgnoreCase);
-#if _DEBUG
- //Console.WriteLine("ResourceSet::GetObject loading up case-insensitive data");
- BCLDebug.Perf(false, "Using case-insensitive lookups is bad perf-wise. Consider capitalizing " + name + " correctly in your source");
-#endif
+ caseTable = new Dictionary<object, object>(CaseInsensitiveStringObjectComparer.Instance);
IDictionaryEnumerator en = copyOfTable.GetEnumerator();
while (en.MoveNext())
return caseTable[name];
}
+
+ /// <summary>
+ /// Adapter for StringComparer.OrdinalIgnoreCase to allow it to be used with Dictionary
+ /// </summary>
+ private class CaseInsensitiveStringObjectComparer : IEqualityComparer<object>
+ {
+ public static CaseInsensitiveStringObjectComparer Instance { get; } = new CaseInsensitiveStringObjectComparer();
+
+ private CaseInsensitiveStringObjectComparer() { }
+
+ public new bool Equals(object x, object y)
+ {
+ return ((IEqualityComparer)StringComparer.OrdinalIgnoreCase).Equals(x, y);
+ }
+
+ public int GetHashCode(object obj)
+ {
+ return ((IEqualityComparer)StringComparer.OrdinalIgnoreCase).GetHashCode(obj);
+ }
+ }
}
}
**
===========================================================*/
+using System;
+using System.IO;
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Reflection;
+using System.Runtime.Versioning;
+using System.Diagnostics;
+using System.Diagnostics.Contracts;
+
namespace System.Resources
{
- using System;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Reflection;
- using System.Runtime.Versioning;
- using System.Diagnostics;
- using System.Diagnostics.Contracts;
-
// A RuntimeResourceSet stores all the resources defined in one
// particular CultureInfo, with some loading optimizations.
//
internal RuntimeResourceSet(String fileName) : base(false)
{
- BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(String)");
_resCache = new Dictionary<String, ResourceLocator>(FastResourceComparer.Default);
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
_defaultReader = new ResourceReader(stream, _resCache);
Reader = _defaultReader;
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- internal RuntimeResourceSet(Stream stream, Assembly assembly) : base(false)
- {
- BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(Stream)");
- _resCache = new Dictionary<String, ResourceLocator>(FastResourceComparer.Default);
- _defaultReader = new ResourceReader(stream, _resCache);
- Reader = _defaultReader;
- Assembly = assembly;
- }
-#else
internal RuntimeResourceSet(Stream stream) : base(false)
{
- BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(Stream)");
_resCache = new Dictionary<String, ResourceLocator>(FastResourceComparer.Default);
_defaultReader = new ResourceReader(stream, _resCache);
Reader = _defaultReader;
}
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
protected override void Dispose(bool disposing)
{
if (_defaultReader != null)
{
- BCLDebug.Log("RESMGRFILEFORMAT", "Going down fast path in RuntimeResourceSet::GetObject");
-
// Find the offset within the data section
int dataPos = -1;
if (_resCache.TryGetValue(key, out resLocation))
if (value != null || !ignoreCase)
{
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- if (Assembly != null && (value is LooselyLinkedResourceReference)) {
- LooselyLinkedResourceReference assRef = (LooselyLinkedResourceReference) value;
- value = assRef.Resolve(Assembly);
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
-
return value; // may be null
}
} // if (_defaultReader != null)
{
_caseInsensitiveTable = new Dictionary<String, ResourceLocator>(StringComparer.OrdinalIgnoreCase);
}
-#if _DEBUG
- BCLDebug.Perf(!ignoreCase, "Using case-insensitive lookups is bad perf-wise. Consider capitalizing " + key + " correctly in your source");
-#endif
if (_defaultReader == null)
{
copyOfCache[key] = resLocation;
}
}
-#if LOOSELY_LINKED_RESOURCE_REFERENCE
- if (Assembly != null && value is LooselyLinkedResourceReference) {
- LooselyLinkedResourceReference assRef = (LooselyLinkedResourceReference) value;
- value = assRef.Resolve(Assembly);
- }
-#endif // LOOSELY_LINKED_RESOURCE_REFERENCE
return value;
}
}
-}
+}
\ No newline at end of file
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-//
-// Abstract derivations of SafeHandle designed to provide the common
-// functionality supporting Win32 handles. More specifically, they describe how
-// an invalid handle looks (for instance, some handles use -1 as an invalid
-// handle value, others use 0).
-//
-// Further derivations of these classes can specialise this even further (e.g.
-// file or registry handles).
-//
-//
-
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-
-namespace Microsoft.Win32.SafeHandles
-{
- // Class of safe handle which uses 0 or -1 as an invalid handle.
- public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
- {
- protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
- {
- }
-
- // A default constructor is needed to satisfy CoreCLR inheritence rules. It should not be called at runtime
- protected SafeHandleZeroOrMinusOneIsInvalid()
- {
- throw new NotImplementedException();
- }
-
- public override bool IsInvalid
- {
- get { return handle.IsNull() || handle == new IntPtr(-1); }
- }
- }
-
- // Class of safe handle which uses only -1 as an invalid handle.
- public abstract class SafeHandleMinusOneIsInvalid : SafeHandle
- {
- protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle)
- {
- }
-
- // A default constructor is needed to satisfy CoreCLR inheritence rules. It should not be called at runtime
- protected SafeHandleMinusOneIsInvalid()
- {
- throw new NotImplementedException();
- }
-
- public override bool IsInvalid
- {
- get { return handle == new IntPtr(-1); }
- }
- }
-}