Advertisement
pszczyg

FasterCanConvertMethod

Apr 8th, 2024
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1.  static HashSet<Type> _classesConvertable = new HashSet<Type>();
  2.  static HashSet<Type> _classesNonConvertable = new HashSet<Type>();
  3.  
  4.  public override bool CanConvert(Type objectType)
  5.  {
  6.      if (_classesConvertable.Contains(objectType)) return true;
  7.      if(_classesNonConvertable.Contains(objectType)) return false;
  8.      
  9.      if (typeof(IContainSecretData).IsAssignableFrom(objectType))
  10.      {
  11.          _classesConvertable.Add(objectType);
  12.          return true;
  13.      }
  14.      else
  15.      {
  16.          _classesNonConvertable.Add(objectType);
  17.          return false;
  18.      }
  19.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement