-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayOfType.cs
More file actions
92 lines (78 loc) · 3.22 KB
/
ArrayOfType.cs
File metadata and controls
92 lines (78 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*****************************************************************************
* *
* ArrayOfType.cs *
* 7 July 2007 *
* Project: MetaphysicsIndustries.Build *
* Written by: Richard Sartor *
* Copyright © 2007 Metaphysics Industries, Inc. *
* *
* Converted from C++ to C# on 4 August 2007 *
* *
* A type that represents an array of elements of some other type. *
* *
*****************************************************************************/
using System;
using System.Collections.Generic;
namespace MetaphysicsIndustries.Build
{
public class ArrayOfType : Build.Type
{
public static ArrayOfType GetArrayOfType(Build.Type type)
{
return GetArrayOfType(type, 1);
}
public static ArrayOfType GetArrayOfType(Build.Type type, int rank)
{
if (type == null) { throw new ArgumentNullException("type"); }
if (rank < 1) { throw new ArgumentOutOfRangeException("rank"); }
if (!ArrayOfTypes.ContainsKey(rank))
{
ArrayOfTypes[rank] = new Dictionary<Build.Type,ArrayOfType>();
}
Dictionary<Build.Type,ArrayOfType> temp = ArrayOfTypes[rank];
if (temp.ContainsKey(type))
{
return temp[type];
}
return new ArrayOfType(type, rank);
}
private static Dictionary<int,Dictionary<Build.Type,ArrayOfType>> _arrayOfTypes = new Dictionary<int,Dictionary<Build.Type,ArrayOfType>>();
protected static Dictionary<int,Dictionary<Build.Type,ArrayOfType>> ArrayOfTypes
{
get { return _arrayOfTypes; }
}
protected ArrayOfType(Build.Type elementType)
: this(elementType, 1)
{
}
protected ArrayOfType(Build.Type elementType, int rank)
{
if (elementType == null) { throw new ArgumentNullException("elementType"); }
if (rank < 1) { throw new ArgumentOutOfRangeException("rank"); }
_elementType = elementType;
_rank = rank;
}
public override ProjectElement Clone()
{
return GetArrayOfType((Type)ElementType.Clone(),Rank);
}
public override string Name
{
get
{
return string.Format("{0}[{1}]", ElementType.Name, new string(',', Rank - 1));
}
}
private Type _elementType;
public virtual Type ElementType
{
get { return _elementType; }
set { _elementType = value; }
}
private int _rank;
public int Rank
{
get { return _rank; }
}
}
}