public static Type GetType(this IDotnetExpander expander, string name) { string assemblyName, typeName, value; expander.ParseName(name, out assemblyName, out typeName, out value); return(expander.GetType(assemblyName, typeName)); }
public static FieldInfo[] GetFields(this IDotnetExpander expander, string assemblyName, string typeName) { return(Ex.Cache.Read("fields", assemblyName ?? "", typeName ?? "", () => { var type = expander.GetType(assemblyName, typeName); return type == null ? new FieldInfo[0] : (type.IsEnum ? type.GetFields() : type.GetFields(BindingFlags.Instance | BindingFlags.Public)); })); }
public static PropertyInfo[] GetSelfProperties(this IDotnetExpander expander, string assemblyName, string typeName) { return(Ex.Cache.Read("selfproperties", assemblyName ?? "", typeName ?? "", "properties", () => { var type = expander.GetType(assemblyName, typeName); return type?.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) ?? new PropertyInfo[0]; })); }
public static MethodInfo[] GetMethods(this IDotnetExpander expander, string assemblyName, string typeName) { return(Ex.Cache.Read("methods", assemblyName ?? "", typeName ?? "", () => { var type = expander.GetType(assemblyName, typeName); return type?.GetMethods(BindingFlags.Instance | BindingFlags.Public) ?? new MethodInfo[0]; })); }
public static T GetTypeAttribute <T>(this IDotnetExpander expander, string assemblyName, string typeName) where T : Attribute { return(Ex.Cache.Read("typeattribute", assemblyName ?? "", typeName ?? "", () => { var type = expander.GetType(assemblyName, typeName); var customAttributes = type?.GetCustomAttributes(typeof(T), true); return customAttributes?.Length > 0 ? customAttributes[0] as T : default(T); })); }
public static object CreateInstance(this IDotnetExpander expander, string name, object[] args = null) { string assemblyName, typeName, value; expander.ParseName(name, out assemblyName, out typeName, out value); if (string.IsNullOrWhiteSpace(value)) { return(expander.CreateInstance(assemblyName, typeName, args)); } var type = expander.GetType(assemblyName, typeName); return(ValueExtensions.IsPrimitive(type) ? value.As(type) : expander.CreateInstance(assemblyName, typeName, args)); }
public static Attribute[] GetTypeAttributes(this IDotnetExpander expander, string assemblyName, string typeName) { return(Ex.Cache.Read("typeattributes", assemblyName ?? "", typeName ?? "", () => { var type = expander.GetType(assemblyName, typeName); if (type == null) { return new Attribute[0]; } var list = new List <Attribute>(); foreach (var item in type.GetCustomAttributes(true)) { var attribute = item as Attribute; if (attribute != null) { list.Add(attribute); } } return list.ToArray(); })); }
public static object CreateInstance(this IDotnetExpander expander, string assemblyName, string typeName, object[] args = null) { return(expander.CreateInstance(expander.GetType(assemblyName, typeName), args)); }