Repository navigation
Expand file tree
/
Copy pathConstructor.cs
More file actions
86 lines (75 loc) · 2.29 KB
/
Copy pathConstructor.cs
File metadata and controls
86 lines (75 loc) · 2.29 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSModuleDevelopment.PsmdAssembly
{
/// <summary>
/// Class containing information about a class's constructor
/// </summary>
public class Constructor
{
/// <summary>
/// The type the constructor is part of
/// </summary>
public Type Type
{
get { return ConstructorItem.DeclaringType; }
}
/// <summary>
/// The constructor definition
/// </summary>
public string Definition
{
get
{
StringBuilder temp = new StringBuilder();
temp = temp.AppendFormat("{0}(", Type.Name);
bool first = true;
foreach (ParameterInfo info in Parameters)
{
if (!first)
temp = temp.Append(", ");
temp = temp.AppendFormat("{0} {1}", info.ParameterType.Name, info.Name);
if (info.HasDefaultValue)
temp = temp.AppendFormat("[ = {0}]", info.DefaultValue);
if (first)
first = false;
}
temp = temp.Append(")");
return temp.ToString();
}
}
/// <summary>
/// Whether the constructor is public
/// </summary>
public bool Public
{
get { return ConstructorItem.IsPublic; }
}
/// <summary>
/// The actual parameters of the constructor
/// </summary>
public ParameterInfo[] Parameters
{
get
{
return ConstructorItem.GetParameters();
}
}
/// <summary>
/// The actual constructor object
/// </summary>
public ConstructorInfo ConstructorItem { get; set; }
/// <summary>
/// Creates a new constructor object, designed for display in PowerShell
/// </summary>
/// <param name="Info">The constructor info object describing the constructor</param>
public Constructor(ConstructorInfo Info)
{
ConstructorItem = Info;
}
}
}