A game about forced loneliness, made by TACStudios
1using System; 2 3namespace Unity.VisualScripting 4{ 5 public partial class EnsureThat 6 { 7 public void HasAttribute(Type param, Type attributeType) 8 { 9 if (!Ensure.IsActive) 10 { 11 return; 12 } 13 14 if (!param.HasAttribute(attributeType)) 15 { 16 throw new ArgumentException(ExceptionMessages.Reflection_HasAttribute_Failed.Inject(param.ToString(), attributeType.ToString()), paramName); 17 } 18 } 19 20 public void HasAttribute<TAttribute>(Type param) where TAttribute : Attribute => HasAttribute(param, typeof(TAttribute)); 21 22 private void HasConstructorAccepting(Type param, Type[] parameterTypes, bool nonPublic) 23 { 24 if (!Ensure.IsActive) 25 { 26 return; 27 } 28 29 if (param.GetConstructorAccepting(parameterTypes, nonPublic) == null) 30 { 31 var message = nonPublic ? ExceptionMessages.Reflection_HasConstructor_Failed : ExceptionMessages.Reflection_HasPublicConstructor_Failed; 32 33 throw new ArgumentException(message.Inject(param.ToString(), parameterTypes.ToCommaSeparatedString()), paramName); 34 } 35 } 36 37 public void HasConstructorAccepting(Type param, params Type[] parameterTypes) => HasConstructorAccepting(param, parameterTypes, true); 38 39 public void HasPublicConstructorAccepting(Type param, params Type[] parameterTypes) => HasConstructorAccepting(param, parameterTypes, false); 40 } 41}