|
static IDictionary< Type, Attribute > | _overrides |
| Per thread assembly attribute overrides for testing.
|
|
Definition at line 14 of file ReflectionHelper.cs.
◆ CreateDefaultImmutableInstance()
static object CommandLine.Infrastructure.ReflectionHelper.CreateDefaultImmutableInstance |
( |
Type |
type, |
|
|
Type[] |
constructorTypes |
|
) |
| |
|
static |
Definition at line 101 of file ReflectionHelper.cs.
102 {
103 ConstructorInfo ctor = type.GetTypeInfo()
104 .GetConstructor(constructorTypes);
105
106 if (ctor == null)
107 {
108 throw new
109 InvalidOperationException($"Type {type.FullName} appears to be immutable, but no constructor found to accept values."
110 );
111 }
112
113 object[] values = (from prms in ctor.GetParameters()
114 select prms.ParameterType.CreateDefaultForImmutable()).ToArray();
115
116 return ctor.Invoke(values);
117 }
◆ CreateDefaultImmutableInstance< T >()
Definition at line 94 of file ReflectionHelper.cs.
95 {
96 Type t = typeof(T);
97
99 }
static object CreateDefaultImmutableInstance(Type type, Type[] constructorTypes)
◆ GetAssemblyName()
static string CommandLine.Infrastructure.ReflectionHelper.GetAssemblyName |
( |
| ) |
|
|
static |
Definition at line 71 of file ReflectionHelper.cs.
72 {
74
75 return assembly.GetName()
76 .Name;
77 }
static Assembly GetExecutingOrEntryAssembly()
◆ GetAssemblyVersion()
static string CommandLine.Infrastructure.ReflectionHelper.GetAssemblyVersion |
( |
| ) |
|
|
static |
Definition at line 79 of file ReflectionHelper.cs.
80 {
82
83 return assembly.GetName()
84 .Version.ToStringInvariant();
85 }
◆ GetAttribute< TAttribute >()
static Maybe< TAttribute > CommandLine.Infrastructure.ReflectionHelper.GetAttribute< TAttribute > |
( |
| ) |
|
|
static |
Definition at line 45 of file ReflectionHelper.cs.
46 : Attribute
47 {
48
50 {
51 return
54 :
Maybe.Nothing<TAttribute>();
55 }
56
58
59#if NET40
60 object[] attributes = assembly.GetCustomAttributes(typeof(TAttribute), false);
61#else
62 TAttribute[] attributes = assembly.GetCustomAttributes<TAttribute>()
63 .ToArray();
64#endif
65
66 return attributes.Length > 0
67 ?
Maybe.Just((TAttribute)attributes[0])
68 :
Maybe.Nothing<TAttribute>();
69 }
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
static IDictionary< Type, Attribute > _overrides
Per thread assembly attribute overrides for testing.
◆ GetExecutingOrEntryAssembly()
static Assembly CommandLine.Infrastructure.ReflectionHelper.GetExecutingOrEntryAssembly |
( |
| ) |
|
|
staticprivate |
Definition at line 119 of file ReflectionHelper.cs.
120 {
121
122
123 return Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly();
124 }
◆ GetNamesOfEnum()
static IEnumerable< string > CommandLine.Infrastructure.ReflectionHelper.GetNamesOfEnum |
( |
Type |
t | ) |
|
|
static |
Definition at line 126 of file ReflectionHelper.cs.
127 {
128 if (t.IsEnum)
129 {
130 return Enum.GetNames(t);
131 }
132
133 Type u = Nullable.GetUnderlyingType(t);
134
135 if (u != null && u.IsEnum)
136 {
137 return Enum.GetNames(u);
138 }
139
140 return Enumerable.Empty<string>();
141 }
◆ IsFSharpOptionType()
static bool CommandLine.Infrastructure.ReflectionHelper.IsFSharpOptionType |
( |
Type |
type | ) |
|
|
static |
Definition at line 87 of file ReflectionHelper.cs.
88 {
89 return type.FullName.StartsWith("Microsoft.FSharp.Core.FSharpOption`1",
90 StringComparison.Ordinal
91 );
92 }
◆ SetAttributeOverride()
static void CommandLine.Infrastructure.ReflectionHelper.SetAttributeOverride |
( |
IEnumerable< Attribute > |
overrides | ) |
|
|
static |
Assembly attribute overrides for testing.
The implementation will fail if two or more attributes of the same type are included in overrides .
- Parameters
-
overrides | Attributes that replace the existing assembly attributes or null, to clear any testing attributes. |
Definition at line 33 of file ReflectionHelper.cs.
34 {
35 if (overrides != null)
36 {
37 _overrides = overrides.ToDictionary(attr => attr.GetType(), attr => attr);
38 }
39 else
40 {
42 }
43 }
◆ _overrides
IDictionary<Type, Attribute> CommandLine.Infrastructure.ReflectionHelper._overrides |
|
staticprivate |
The documentation for this class was generated from the following file: