PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/rocks/Mono.Cecil.Rocks/TypeReferenceRocks.cs

http://github.com/jbevain/cecil
C# | 89 lines | 62 code | 18 blank | 9 comment | 11 complexity | 1fbf78be03dc1ee023450b3bd1556bf3 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.Collections.Generic;
13using System.Linq;
14
15namespace Mono.Cecil.Rocks {
16
17#if INSIDE_ROCKS
18	public
19#endif
20	static class TypeReferenceRocks {
21
22		public static ArrayType MakeArrayType (this TypeReference self)
23		{
24			return new ArrayType (self);
25		}
26
27		public static ArrayType MakeArrayType (this TypeReference self, int rank)
28		{
29			if (rank == 0)
30				throw new ArgumentOutOfRangeException ("rank");
31
32			var array = new ArrayType (self);
33
34			for (int i = 1; i < rank; i++)
35				array.Dimensions.Add (new ArrayDimension ());
36
37			return array;
38		}
39
40		public static PointerType MakePointerType (this TypeReference self)
41		{
42			return new PointerType (self);
43		}
44
45		public static ByReferenceType MakeByReferenceType (this TypeReference self)
46		{
47			return new ByReferenceType (self);
48		}
49
50		public static OptionalModifierType MakeOptionalModifierType (this TypeReference self, TypeReference modifierType)
51		{
52			return new OptionalModifierType (modifierType, self);
53		}
54
55		public static RequiredModifierType MakeRequiredModifierType (this TypeReference self, TypeReference modifierType)
56		{
57			return new RequiredModifierType (modifierType, self);
58		}
59
60		public static GenericInstanceType MakeGenericInstanceType (this TypeReference self, params TypeReference [] arguments)
61		{
62			if (self == null)
63				throw new ArgumentNullException ("self");
64			if (arguments == null)
65				throw new ArgumentNullException ("arguments");
66			if (arguments.Length == 0)
67				throw new ArgumentException ();
68			if (self.GenericParameters.Count != arguments.Length)
69				throw new ArgumentException ();
70
71			var instance = new GenericInstanceType (self, arguments.Length);
72
73			foreach (var argument in arguments)
74				instance.GenericArguments.Add (argument);
75
76			return instance;
77		}
78
79		public static PinnedType MakePinnedType (this TypeReference self)
80		{
81			return new PinnedType (self);
82		}
83
84		public static SentinelType MakeSentinelType (this TypeReference self)
85		{
86			return new SentinelType (self);
87		}
88	}
89}