Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Created July 26, 2010 15:21
Show Gist options
  • Save cstrahan/490693 to your computer and use it in GitHub Desktop.
Save cstrahan/490693 to your computer and use it in GitHub Desktop.
// Languages\Ruby\Ruby\Builtins\RubyEncoding.cs
public static RubyEncoding/*!*/ GetRubyEncoding(Encoding/*!*/ encoding) {
ContractUtils.RequiresNotNull(encoding, "encoding");
if (encoding == BinaryEncoding.Instance) {
return Binary;
} else if (encoding.ToString() == Encoding.UTF8.ToString()) {
return UTF8;
} else {
throw new ArgumentException(String.Format("Unknown encoding: '{0}'", encoding));
}
}
/*
There's a tiny problem there when running IronRuby in Silverlight; it fails when the encoding is an instance of KCoding:
ArgumentException: Unknown encoding: 'KCODE (UTF8)'
*/
//This...
} else if (encoding.ToString() == Encoding.UTF8.ToString()) {
// ... should be replaced with this:
} else if (encoding is KCoding || encoding == Encoding.UTF8) {
/*
The expression "Encoding.UTF8.ToString()" will always return "System.Encoding.UTF8",
so it doesn't make sense to test against that.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment