System.Xml.BinHexDecoder.Decode C# (CSharp) Méthode

Decode() public static méthode

public static Decode ( char chars, bool allowOddChars ) : byte[]
chars char
allowOddChars bool
Résultat byte[]
        public static unsafe byte[] Decode( char[] chars, bool allowOddChars ) {
            if ( chars == null ) {
                throw new ArgumentException( "chars" );
            }
            
            int len = chars.Length;
            if ( len == 0 ) {
                return new byte[0];
            }

            byte[] bytes = new byte[ ( len + 1 ) / 2 ];
            int bytesDecoded, charsDecoded;
            bool hasHalfByteCached = false;
            byte cachedHalfByte = 0;
            
            fixed ( char* pChars = &chars[0] ) {
                fixed ( byte* pBytes = &bytes[0] ) {
                    Decode( pChars, pChars + len, pBytes, pBytes + bytes.Length, ref hasHalfByteCached, ref cachedHalfByte, out charsDecoded, out bytesDecoded );
                }
            }

            if ( hasHalfByteCached && !allowOddChars ) {
                throw new XmlException( Res.Xml_InvalidBinHexValueOddCount, new string( chars ) );
            }

            if ( bytesDecoded < bytes.Length ) {
                byte[] tmp = new byte[ bytesDecoded ];
                Buffer.BlockCopy( bytes, 0, tmp, 0, bytesDecoded );
                bytes = tmp;
            }

            return bytes;
        }
    

Same methods

BinHexDecoder::Decode ( char chars, int startPos, int len ) : int
BinHexDecoder::Decode ( string str, int startPos, int len ) : int
BinHexDecoder::Decode ( char pChars, char pCharsEndPos, byte pBytes, byte pBytesEndPos, bool &hasHalfByteCached, byte &cachedHalfByte, int &charsDecoded, int &bytesDecoded ) : void

Usage Example

Exemple #1
0
 internal static byte[] FromBinHexString(string s, bool allowOddCount)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     return(BinHexDecoder.Decode(s.ToCharArray(), allowOddCount));
 }