Mega Code Archive

 
Categories / C# / Reflection
 

Get Assembly As Bytes

// // XGenPlus Tool // // Please visit http://www.codeplex.com/xgenplus for latest updates. // // This source is subject to the GNU General Public License v2. //  // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE. // using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Reflection; namespace XGenPlus.SerializerLib {     class Util     {         public byte[] GetAssemblyAsBytes(String path)         {             if (!File.Exists(path))             {                 return null;             }             try             {                 FileInfo file = new FileInfo(path);                 byte[] bytes = new byte[file.Length];                 FileStream stream = new FileStream(path, FileMode.Open);                 stream.Read(bytes, 0, bytes.Length);                 stream.Close();                 return bytes;             }             catch (Exception ex)             {                 return null;             }         }     } }