IConstantProvider.cs 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 ILRuntime.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. }