mirror of
https://github.com/claunia/Claunia.Encoding.git
synced 2025-12-16 19:24:43 +00:00
Added GetEncoding() override.
This commit is contained in:
@@ -52,5 +52,19 @@ namespace Claunia.Encoding.Tests
|
||||
Console.WriteLine("{0,-8} {1,-8} ", e.IsSingleByte, e.IsReadOnly);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
// Well basically this is taken from MSDN's documentation :p
|
||||
public void GetInternalEncoding()
|
||||
{
|
||||
System.Text.Encoding e = Encoding.GetEncoding("lisa");
|
||||
}
|
||||
|
||||
[Test]
|
||||
// Well basically this is taken from MSDN's documentation :p
|
||||
public void GetExternalEncoding()
|
||||
{
|
||||
System.Text.Encoding e = Encoding.GetEncoding("shift_jis");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,24 @@ namespace Claunia.Encoding
|
||||
return encodings.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the encoding associated with the specified code page name.
|
||||
/// </summary>
|
||||
/// <returns>The encoding associated with the specified code page.</returns>
|
||||
/// <param name="name">The code page name of the preferred encoding. Any value returned by the WebName property is valid. Possible values are listed in the Name column of the table that appears in the Encoding class topic.</param>
|
||||
public static System.Text.Encoding GetEncoding(string name)
|
||||
{
|
||||
foreach(Type type in Assembly.GetExecutingAssembly().GetTypes()) {
|
||||
if(type.IsSubclassOf(typeof(Encoding))) {
|
||||
Encoding encoding = (Encoding)type.GetConstructor(new Type[] { }).Invoke(new object[] { });
|
||||
if(encoding.BodyName == name.ToLowerInvariant())
|
||||
return encoding;
|
||||
}
|
||||
}
|
||||
|
||||
return System.Text.Encoding.GetEncoding(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current encoding can be used by browser clients for displaying content.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user