/Mono.Cecil/IConstantProvider.cs

http://github.com/jbevain/cecil · C# · 44 lines · 28 code · 7 blank · 9 comment · 5 complexity · 510b49efb7ca94413b878e31f697ee5c 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. namespace Mono.Cecil {
  11. public interface IConstantProvider : IMetadataTokenProvider {
  12. bool HasConstant { get; set; }
  13. object Constant { get; set; }
  14. }
  15. static partial class Mixin {
  16. internal static object NoValue = new object ();
  17. internal static object NotResolved = new object ();
  18. public static void ResolveConstant (
  19. this IConstantProvider self,
  20. ref object constant,
  21. ModuleDefinition module)
  22. {
  23. if (module == null) {
  24. constant = Mixin.NoValue;
  25. return;
  26. }
  27. lock (module.SyncRoot) {
  28. if (constant != Mixin.NotResolved)
  29. return;
  30. if (module.HasImage ())
  31. constant = module.Read (self, (provider, reader) => reader.ReadConstant (provider));
  32. else
  33. constant = Mixin.NoValue;
  34. }
  35. }
  36. }
  37. }