Check for specific file types using the type hierarchy
masterFile formats are organized into a type hierarchy. You can check for a specific format or use a base type to match multiple related formats using C# pattern matching.
- Use a specific class (e.g.,
Pdf) to match exactly one format. - Use a base class (e.g.,
OfficeOpenXmlorImage) to match a group of related formats.
var format = inspector.DetermineFileFormat(stream);
if(format is Pdf) {
// Just matches Pdf
}
if(format is OfficeOpenXml) {
// Matches Word, Excel, Powerpoint
}
if(format is Image) {
// Matches any image format
}