Last active
March 26, 2016 17:14
-
-
Save IUntyped/03d09f70c694b5481fbd to your computer and use it in GitHub Desktop.
ForceCulture class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using System.Threading; | |
namespace nPacker.@gmail.com | |
{ | |
public class ForceCulture : IDisposable | |
{ | |
/// <summary> | |
/// Constructor | |
/// </summary> | |
/// <param name="CultureInfo">CultureInfo to force</param> | |
public ForceCulture(CultureInfo culture) | |
{ | |
oldCultureInfo = Thread.CurrentThread.CurrentCulture; | |
Thread.CurrentThread.CurrentCulture = culture; | |
} | |
public ForceCulture() : this(CultureInfo.InvariantCulture) | |
{ | |
} | |
#region IDisposable | |
private CultureInfo oldCultureInfo; | |
///<summary> | |
/// Finalizer, IDisposable support | |
///</summary> | |
~ForceCulture() | |
{ | |
Dispose(false); | |
} | |
///<summary> | |
/// IDisposable support | |
///</summary> | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
///<summary> | |
/// IDisposable support | |
///</summary> | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
Thread.CurrentThread.CurrentCulture = oldCultureInfo; | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: