Class Helpers
Some helper functions used by OAT.
Inheritance
Inherited Members
Namespace: Microsoft.CST.OAT.Utils
Assembly: OAT.dll
Syntax
public static class Helpers
Methods
| Improve this Doc View SourceConstructedOfLoadedTypes(ConstructorInfo)
Determines if the ConstructorInfo given is constructable given what is loaded into the AppDomain.
Declaration
public static bool ConstructedOfLoadedTypes(ConstructorInfo constructorInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.ConstructorInfo | constructorInfo |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if only basic types and types derived from basic types can be used to construct. |
ConstructedOfLoadedTypes(Type)
Recursively checks if the object Type given can be constructed given what is loaded into the AppDomain.
Declaration
public static bool ConstructedOfLoadedTypes(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | The Type to Check |
Returns
| Type | Description |
|---|---|
| System.Boolean |
CreateDictionary(Type, Type)
Create a Dictionary to hold the given types
Declaration
public static IDictionary CreateDictionary(Type keyType, Type valueType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | keyType | The Type of the Key |
| System.Type | valueType | The Type of the Value |
Returns
| Type | Description |
|---|---|
| System.Collections.IDictionary | A Dictionary of the given types or null. |
CreateList(Type)
Create a list to hold the given type
Declaration
public static IList CreateList(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.Collections.IList | A List of the given type or null. |
GetAllNestedFieldsAndProperties(Type, String)
Gets the Paths of all the Fields and Properties in the provided Type
Declaration
public static List<string> GetAllNestedFieldsAndProperties(Type type, string currentPath = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | |
| System.String | currentPath |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> |
GetAllNestedFieldsAndPropertiesMemberInfo(Type, String)
Get MemberInfo and Paths for all the BasicType properties and fields in the Type
Declaration
public static List<(string Path, MemberInfo MemInfo)> GetAllNestedFieldsAndPropertiesMemberInfo(Type type, string currentPath = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | |
| System.String | currentPath |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.ValueTuple<System.String, System.Reflection.MemberInfo>> |
GetConstructors(Type)
Get the constructors which exclusively use loaded/basic types (are constructable)
Declaration
public static List<ConstructorInfo> GetConstructors(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.Reflection.ConstructorInfo> |
GetDefaultValueForType(Type)
Gets a sensible default value for the type.
Declaration
public static object GetDefaultValueForType(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | The type to get a default value for. |
Returns
| Type | Description |
|---|---|
| System.Object | The default value for the type. |
GetFriendlyName(Type)
Get the friendly name for a type
Declaration
public static string GetFriendlyName(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.String |
GetListType(Type)
Create a list to hold the given type
Declaration
public static IList GetListType(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.Collections.IList | A List of the given type or null. |
GetTypesInNamespace(Assembly, String)
Returns a list of the Types in the given namespace in the given assembly.
Declaration
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.Assembly | assembly | The Assembly to scan |
| System.String | nameSpace | The Namespace to look for. |
Returns
| Type | Description |
|---|---|
| System.Type[] |
GetValueByPropertyOrFieldName(Object, String)
Gets the object value stored at the field or property named by the string. Property tried first. Returns null if none found.
Declaration
public static object GetValueByPropertyOrFieldName(object obj, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The target object |
| System.String | propertyName | The Property or Field name |
Returns
| Type | Description |
|---|---|
| System.Object | The object at that Name or null |
GetVersionString()
Returns the assembly version string.
Declaration
public static string GetVersionString()
Returns
| Type | Description |
|---|---|
| System.String |
IsBasicType(Type)
Checks if this is a type that OAT Blazor has a component for
Declaration
public static bool IsBasicType(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type |
Returns
| Type | Description |
|---|---|
| System.Boolean |
IsNullable(Type)
Determines if a type is nullable
Declaration
public static bool IsNullable(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | The type |
Returns
| Type | Description |
|---|---|
| System.Boolean |
IsValidRegex(String)
Determines if a Regex is valid or not by checking if a Regex object can be created with it.
Declaration
public static bool IsValidRegex(string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pattern |
Returns
| Type | Description |
|---|---|
| System.Boolean |
PrintViolations(IEnumerable<Violation>)
Prints out the Enumerable of violations to Warning
Declaration
public static void PrintViolations(IEnumerable<Violation> violations)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<Violation> | violations | An Enumerable of Violations to print |
SetValueByPropertyOrFieldName(Object, String, Object)
Sets the object value stored at the field or property named by the string. Property tried first.
Declaration
public static void SetValueByPropertyOrFieldName(object obj, string propertyName, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The target object |
| System.String | propertyName | The Property or Field name |
| System.Object | value | The value to set. |