Exemplo n.º 1
0
        public static IEnumerable <T> InstanceTypesWithAttribute <T>(Type attr, Func <Type, Attribute[], bool>?validator, IEnumerable <Type>?exclude, params Assembly[] assemblies) where T : class
        {
            if (!attr.IsAssignableTo(typeof(Attribute)))
            {
                throw new ArgumentException("Type must be an attribute type", nameof(attr));
            }
            var types = new List <T>();

            Func <Type, Attribute[], bool> isvalid = validator ?? ((x, y) => true);

            Type?curtype = null;

            try
            {
                foreach (var ty in ReflectionCollectionMethods.GetAllTypesAndAttributeInstanceTupleFromAssembly(attr, false, assemblies.Length > 0 ? assemblies : ExecAsm)
                         .Where(x => (exclude ?? NoExclude).All(y => y != x.Type)))
                {
                    curtype = ty.Type;
                    if (isvalid(ty.Type, ty.Attributes))
                    {
                        types.Add((T)Activator.CreateInstance(ty.Type) !);
                    }
                }
                return(types);
            }
            catch (Exception e)
            {
                throw new TypeLoadException($"All classes that are chosen to be loaded must not be generic, abstract, or static, must have a parameterless constructor. Check inner exception for more details. Type that caused the exception: {curtype}", e);
            }
        }
 public static IEnumerable <object> GetAllStaticPropertyValues() => ReflectionCollectionMethods.GetAllStaticPropertyValues(typeinfo);
 public static IEnumerable <PropertyInfo> GetAllInstanceProperties() => ReflectionCollectionMethods.GetAllInstanceProperties(typeinfo);