PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11namespace Mono.Cecil {
12
13	public interface IConstantProvider : IMetadataTokenProvider {
14
15		bool HasConstant { get; set; }
16		object Constant { get; set; }
17	}
18
19	static partial class Mixin {
20
21		internal static object NoValue = new object ();
22		internal static object NotResolved = new object ();
23
24		public static void ResolveConstant (
25			this IConstantProvider self,
26			ref object constant,
27			ModuleDefinition module)
28		{
29			if (module == null) {
30				constant = Mixin.NoValue;
31				return;
32			}
33
34			lock (module.SyncRoot) {
35				if (constant != Mixin.NotResolved)
36					return;
37				if (module.HasImage ())
38					constant = module.Read (self, (provider, reader) => reader.ReadConstant (provider));
39				else
40					constant = Mixin.NoValue;
41			}
42		}
43	}
44}