Skip to content

Create custom type

Aleksander J. Mitev edited this page Mar 10, 2020 · 7 revisions

In order to create new identifiable type you should inherit FileType class. When you do this you will be notice that the parent class has two constructors with different signatures.

public FileType(string name, string extension, byte[] magicBytes){}       
public FileType(string name, string extension, byte[][] magicBytesJaggedArray){}       

The first one will be used in cases when the current type of file has only one variation of bytes. The second one will be helpful in situation where our type can has multiple bytes variation.

Here is the code sample how your custom class should be implemented

using FileTypeChecker.Abstracts;

public class MyCustomFileType : FileType
{
    private static readonly string name = "My Super Cool Custom Type 1.0";
    private static readonly string extension = "ext";
    private static readonly byte[] magicBytes = new byte[] { 0xAF };

    public MyCustomFileType() : base(name, extension, magicBytes){}
}
using FileTypeChecker.Abstracts;

 class MyCustomFileTypeWithManyVersions : FileType
 {
     private static readonly string name = "My Super Cool Custom Type 1.0";
     private static readonly string extension = "ext2";
     private static readonly byte[][] magicBytesJaggedArray = { new byte[] { 0xAF }, new byte[] { 0xEF } };

      
    public MyCustomFileTypeWithManyVersions() : base(name, extension, magicBytesJaggedArray){}
}
Clone this wiki locally