4using System.Collections.Generic;
6using System.Reflection;
35 if (overrides !=
null)
37 _overrides = overrides.ToDictionary(attr => attr.GetType(), attr => attr);
46 where TAttribute : Attribute
54 :
Maybe.Nothing<TAttribute>();
60 object[] attributes = assembly.GetCustomAttributes(typeof(TAttribute),
false);
62 TAttribute[] attributes = assembly.GetCustomAttributes<TAttribute>()
66 return attributes.Length > 0
67 ?
Maybe.Just((TAttribute)attributes[0])
68 :
Maybe.Nothing<TAttribute>();
75 return assembly.GetName()
83 return assembly.GetName()
84 .Version.ToStringInvariant();
89 return type.FullName.StartsWith(
"Microsoft.FSharp.Core.FSharpOption`1",
90 StringComparison.Ordinal
103 ConstructorInfo ctor = type.GetTypeInfo()
104 .GetConstructor(constructorTypes);
109 InvalidOperationException($
"Type {type.FullName} appears to be immutable, but no constructor found to accept values."
113 object[] values = (from prms in ctor.GetParameters()
114 select prms.ParameterType.CreateDefaultForImmutable()).ToArray();
116 return ctor.Invoke(values);
123 return Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly();
130 return Enum.GetNames(t);
133 Type u = Nullable.GetUnderlyingType(t);
135 if (u !=
null && u.IsEnum)
137 return Enum.GetNames(u);
140 return Enumerable.Empty<
string>();
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
static void SetAttributeOverride(IEnumerable< Attribute > overrides)
Assembly attribute overrides for testing.
static string GetAssemblyVersion()
static IEnumerable< string > GetNamesOfEnum(Type t)
static string GetAssemblyName()
static bool IsFSharpOptionType(Type type)
static IDictionary< Type, Attribute > _overrides
Per thread assembly attribute overrides for testing.
static Assembly GetExecutingOrEntryAssembly()
static object CreateDefaultImmutableInstance(Type type, Type[] constructorTypes)
static T CreateDefaultImmutableInstance< T >(Type[] constructorTypes)
static Maybe< TAttribute > GetAttribute< TAttribute >()