PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Mono.Cecil/IGenericParameterProvider.cs

http://github.com/jbevain/cecil
C# | 58 lines | 38 code | 11 blank | 9 comment | 2 complexity | 489a6e6719165469eb8184f1bf3877e0 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.Threading;
12using Mono.Collections.Generic;
13
14namespace Mono.Cecil {
15
16	public interface IGenericParameterProvider : IMetadataTokenProvider {
17
18		bool HasGenericParameters { get; }
19		bool IsDefinition { get; }
20		ModuleDefinition Module { get; }
21		Collection<GenericParameter> GenericParameters { get; }
22		GenericParameterType GenericParameterType { get; }
23	}
24
25	public enum GenericParameterType {
26		Type,
27		Method
28	}
29
30	interface IGenericContext {
31
32		bool IsDefinition { get; }
33		IGenericParameterProvider Type { get; }
34		IGenericParameterProvider Method { get; }
35	}
36
37	static partial class Mixin {
38
39		public static bool GetHasGenericParameters (
40			this IGenericParameterProvider self,
41			ModuleDefinition module)
42		{
43			return module.HasImage () && module.Read (self, (provider, reader) => reader.HasGenericParameters (provider));
44		}
45
46		public static Collection<GenericParameter> GetGenericParameters (
47			this IGenericParameterProvider self,
48			ref Collection<GenericParameter> collection,
49			ModuleDefinition module)
50		{
51			if (module.HasImage ())
52				return module.Read (ref collection, self, (provider, reader) => reader.ReadGenericParameters (provider));
53
54			Interlocked.CompareExchange (ref collection, new GenericParameterCollection (self), null);
55			return collection;
56		}
57	}
58}