Skip to content

Instantly share code, notes, and snippets.

View Dodecahedrane's full-sized avatar

Oliver Guy Dodecahedrane

  • Plymouth, UK
View GitHub Profile
@Dodecahedrane
Dodecahedrane / exception.cs
Created January 18, 2024 16:50
C# Custom Exception
public class ExceptionName : Exception
{
public ExceptionName() { }
public ExceptionName(string message) : base(message) { }
public ExceptionName(string message, Exception innerException) : base(message, innerException) { }
}
@Dodecahedrane
Dodecahedrane / ImageFileAttribute.cs
Last active January 18, 2024 16:46
File Extension Validation Attribute C# .NET
public class ImageFile : ValidationAttribute
{
private readonly string[] _allowedExtensions = { ".png", ".jpeg", ".gif" };
public override bool IsValid(object value)
{
if (value is IFormFile file)
{
var fileExtension = System.IO.Path.GetExtension(file.FileName).ToLower();
if (!_allowedExtensions.Contains(fileExtension))