コード例 #1
0
 private void WriteChar(Object obj, BinaryWritingContext context)
 {
     try
         {
             if (obj is char)
             {
                 var bytes = BitConverter.GetBytes((char)obj);
                 Array.Reverse(bytes);
                 context.WriteBytes(bytes);
             }
             else throw new InvalidOperationException("Passed object is not a char");
         }
         catch (Exception exception)
         {
             throw new InvalidOperationException("Cannot write char to given context", exception);
         }
 }
コード例 #2
0
 private void WriteString(object obj, BinaryWritingContext context)
 {
     try
         {
             if (obj is string)
             {
                 var str = (string)obj;
                 foreach (var ch in str)
                 {
                     context.WriteBytes(BitConverter.GetBytes(ch));
                 }
             }
             else throw new InvalidOperationException("Passed object is not a string");
         }
         catch (Exception exception)
         {
             throw new InvalidOperationException("Cannot write string to given context", exception);
         }
 }
コード例 #3
0
 private void WriteShort(object obj, BinaryWritingContext context)
 {
     try
         {
             if (obj is short)
             {
                 context.WriteBytes(BitConverter.GetBytes((short)obj));
             }
             else throw new InvalidOperationException("Passed object is not a short");
         }
         catch (Exception exception)
         {
             throw new InvalidOperationException("Cannot write short to given context", exception);
         }
 }