// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetByteCount(String chars)
+ public override int GetByteCount(String chars)
{
- // Validate input
- if (chars==null)
- throw new ArgumentNullException("chars");
- Contract.EndContractBlock();
-
- fixed (char* pChars = chars)
- return GetByteCount(pChars, chars.Length, null);
+ // NOTE: If chars is null, this will throw an ArgumentNullException
+ // with the parameter name "s" rather than "chars"
+ return EncodingForwarder.GetByteCount(this, chars);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
if (count == 0)
return 0;
- // Just call the pointer version
+ // Just call the (internal) pointer version
fixed (char* pChars = chars)
- return encoding.GetByteCount(pChars + index, count, null);
+ return encoding.GetByteCount(pChars + index, count, encoder: null);
+ }
+
+ public unsafe static int GetByteCount(Encoding encoding, string s)
+ {
+ if (s == null)
+ {
+ throw new ArgumentNullException("s");
+ }
+ Contract.EndContractBlock();
+
+ // NOTE: The behavior of fixed *is* defined by
+ // the spec for empty strings, although not for
+ // null strings/empty char arrays. See
+ // http://stackoverflow.com/q/37757751/4077294
+ // Regardless, we may still want to check
+ // for if (chars.Length == 0) in the future
+ // and short-circuit as an optimization (TODO).
+
+ fixed (char* pChars = s)
+ return encoding.GetByteCount(pChars, s.Length, encoder: null);
}
}
}
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
// parent method is safe
[System.Security.SecuritySafeCritical] // overrides public transparent member
- public override unsafe int GetByteCount(String s)
+ public override int GetByteCount(String s)
{
- // Validate input
- if (s==null)
- throw new ArgumentNullException("s");
- Contract.EndContractBlock();
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
+ return EncodingForwarder.GetByteCount(this, s);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetByteCount(String s)
+ public override int GetByteCount(String s)
{
- // Validate input
- if (s==null)
- throw new ArgumentNullException("s");
- Contract.EndContractBlock();
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
+ return EncodingForwarder.GetByteCount(this, s);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
[System.Security.SecuritySafeCritical] // auto-generated
[System.Runtime.InteropServices.ComVisible(false)]
- public override unsafe int GetByteCount(String s)
+ public override int GetByteCount(String s)
{
- // Validate input
- if (s==null)
- throw new ArgumentNullException("s");
- Contract.EndContractBlock();
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
+ return EncodingForwarder.GetByteCount(this, s);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetByteCount(String chars)
+ public override int GetByteCount(String chars)
{
- // Validate input
- if (chars==null)
- throw new ArgumentNullException("s");
- Contract.EndContractBlock();
-
- fixed (char* pChars = chars)
- return GetByteCount(pChars, chars.Length, null);
+ // NOTE: If chars is null, this will throw an ArgumentNullException
+ // with the parameter name "s" rather than "chars"
+ return EncodingForwarder.GetByteCount(this, chars);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// parent method is safe
[System.Security.SecuritySafeCritical] // auto-generated
- public override unsafe int GetByteCount(String s)
+ public override int GetByteCount(String s)
{
- // Validate input
- if (s==null)
- throw new ArgumentNullException("s");
- Contract.EndContractBlock();
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
+ return EncodingForwarder.GetByteCount(this, s);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)