PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11using System;
12using System.Threading;
13using Mono.Collections.Generic;
14
15namespace Mono.Cecil {
16
17	public interface ICustomAttributeProvider : IMetadataTokenProvider {
18
19		Collection<CustomAttribute> CustomAttributes { get; }
20
21		bool HasCustomAttributes { get; }
22	}
23
24	static partial class Mixin {
25
26		public static bool GetHasCustomAttributes (
27			this ICustomAttributeProvider self,
28			ModuleDefinition module)
29		{
30			return module.HasImage () && module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider));
31		}
32
33		public static Collection<CustomAttribute> GetCustomAttributes (
34			this ICustomAttributeProvider self,
35			ref Collection<CustomAttribute> variable,
36			ModuleDefinition module)
37		{
38			if (module.HasImage ())
39				return module.Read (ref variable, self, (provider, reader) => reader.ReadCustomAttributes (provider));
40
41			Interlocked.CompareExchange (ref variable, new Collection<CustomAttribute> (), null);
42			return variable;
43		}
44	}
45}