/Mono.Cecil/ICustomAttributeProvider.cs

http://github.com/jbevain/cecil · C# · 45 lines · 27 code · 9 blank · 9 comment · 2 complexity · 8bc87bcab76685c4ffb801b9fd3be4b7 MD5 · raw file

  1. //
  2. // Author:
  3. // Jb Evain (jbevain@gmail.com)
  4. //
  5. // Copyright (c) 2008 - 2015 Jb Evain
  6. // Copyright (c) 2008 - 2011 Novell, Inc.
  7. //
  8. // Licensed under the MIT/X11 license.
  9. //
  10. using System;
  11. using System.Threading;
  12. using Mono.Collections.Generic;
  13. namespace Mono.Cecil {
  14. public interface ICustomAttributeProvider : IMetadataTokenProvider {
  15. Collection<CustomAttribute> CustomAttributes { get; }
  16. bool HasCustomAttributes { get; }
  17. }
  18. static partial class Mixin {
  19. public static bool GetHasCustomAttributes (
  20. this ICustomAttributeProvider self,
  21. ModuleDefinition module)
  22. {
  23. return module.HasImage () && module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider));
  24. }
  25. public static Collection<CustomAttribute> GetCustomAttributes (
  26. this ICustomAttributeProvider self,
  27. ref Collection<CustomAttribute> variable,
  28. ModuleDefinition module)
  29. {
  30. if (module.HasImage ())
  31. return module.Read (ref variable, self, (provider, reader) => reader.ReadCustomAttributes (provider));
  32. Interlocked.CompareExchange (ref variable, new Collection<CustomAttribute> (), null);
  33. return variable;
  34. }
  35. }
  36. }