public IEnumerable<SqlQuery> PrepareQueries(Type[] types, bool onlyEnabledQueries = true)
 {
     // Search for types with at least one attribute that have a QueryAttribute
     return types.SelectMany(t => t.GetCustomAttributes<QueryAttribute>()
                                   .Where(a => !onlyEnabledQueries || a.Enabled)
                                   .Select(a => new SqlQuery(t, a, _dapper)))
                 .ToArray();
 }
Ejemplo n.º 2
0
 IInitializableProperty[] CreateInitializableProperties(Type type, Type[] baseTypes)
 {
     return type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
         .Concat(baseTypes // Need to recover the private members from base types.
             .SelectMany(t => t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic))
             .Where(p => p.IsPrivate()))
         .Where(propertyFilter)
         .Select(p => CreateInitializableProperty(p))
         .ToArray();
 }
Ejemplo n.º 3
0
 IInitializableField[] CreateInitializableFields(Type type, Type[] baseTypes)
 {
     return type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
         .Concat(baseTypes // Need to recover the private members from base types.
             .SelectMany(t => t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
             .Where(f => f.IsPrivate))
         .Where(fieldFilter)
         .Select(f => CreateInitializableField(f))
         .ToArray();
 }
Ejemplo n.º 4
0
        public static Type[] AllHandledEventTypes(this ITypeProvider typeProvider)
        {
            var handlers = new Type[0]
                .Union(typeProvider.MulticastEventHandlerTypes)
                .Union(typeProvider.CompetingEventHandlerTypes)
                .ToArray();

            var handledEvents = handlers.SelectMany(hand => hand.GetInterfaces())
                                        .Where(i => i.IsClosedTypeOf(typeof (IHandleCompetingEvent<>)) || i.IsClosedTypeOf(typeof (IHandleMulticastEvent<>)))
                                        .SelectMany(i => i.GetGenericArguments());

            return handledEvents.Distinct().ToArray();
        }
        public void RegisterByAttribute(Type type, InjectAttribute attribute)
        {
            var interfaces = new Type[] { };

            // Get as types
            if (attribute.InjectType == InjectType.AsInterface)
            {
                interfaces = type.GetInterfaces().Except(type.BaseType.GetInterfaces()).ToArray();

                if (interfaces.Length > 1)
                {
                    interfaces = interfaces.Except(interfaces.SelectMany(t => t.GetInterfaces())).ToArray();
                }

                if (interfaces.Length == 0)
                {
                    interfaces = type.BaseType.GetInterfaces();
                }
            }
            else if (attribute.InjectType == InjectType.AsSelf)
            {
                interfaces = new[] { type };
            }

            if (interfaces.Length == 0)
            {
                throw new Exception();
            }

            for (int index = 0; index < interfaces.Length; index++)
            {
                var interfaceType = interfaces[index];

                if (interfaceType.IsInterface && interfaceType.IsGenericType)
                {
                    interfaces[index] = interfaceType.GetGenericTypeDefinition();
                }
            }

            Register(type, interfaces, (int)attribute.LifeType);
        }
Ejemplo n.º 6
0
        public IEnumerable<MethodInfo> FindAvailableMethods(Type[] types)
        {
            if (!string.IsNullOrEmpty(TypeName))
            {
                types = types.Where(type => type.Name == TypeName).ToArray();

                if (!types.Any())
                {
                    var message = string.Format("No type named '{0}' could be found.", TypeName);
                    throw new InvalidOperationException(message);
                }
            }

            const BindingFlags bindingFlags =
                BindingFlags.Public |
                BindingFlags.Static |
                BindingFlags.Instance |
                BindingFlags.DeclaredOnly;

            return types.SelectMany(type => type.GetMethods(bindingFlags)
                .OrderByDescending(method => method.GetParameters().Length));
        }
Ejemplo n.º 7
0
        private List<string> FindPluginBundles(Type[] types)
        {
            var unfilteredCatalogs = InMemoryRavenConfiguration.GetUnfilteredCatalogs(Configuration.Catalog.Catalogs);

            AggregateCatalog unfilteredAggregate = null;

            var innerAggregate = unfilteredCatalogs as AggregateCatalog;
            if (innerAggregate != null)
            {
                unfilteredAggregate = new AggregateCatalog(innerAggregate.Catalogs.OfType<BuiltinFilteringCatalog>());
            }

            if (unfilteredAggregate == null || unfilteredAggregate.Catalogs.Count == 0)
                return new List<string>();

            return types
                .SelectMany(type => unfilteredAggregate.GetExports(new ImportDefinition(info => info.Metadata.ContainsKey("Bundle"), type.FullName, ImportCardinality.ZeroOrMore, false, false)))
                .Select(info => info.Item2.Metadata["Bundle"] as string)
                .Where(x => x != null)
                .Distinct()
                .OrderBy(x => x)
                .ToList();
        }
Ejemplo n.º 8
0
 IInjectableField[] CreateInjectableFields(Type type, Type[] baseTypes)
 {
     return type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
         .Concat(baseTypes // Need to recover the private members from base types.
             .SelectMany(t => t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
             .Where(f => f.IsPrivate))
         .Where(f => !f.IsSpecialName && f.IsDefined(typeof(InjectAttribute), true))
         .Select(f => CreateInjectableField(f))
         .ToArray();
 }
Ejemplo n.º 9
0
 IInjectableProperty[] CreateInjectableProperties(Type type, Type[] baseTypes)
 {
     return type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
         .Concat(baseTypes // Need to recover the private members from base types.
             .SelectMany(t => t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic))
             .Where(p => p.IsPrivate()))
         .Where(p => !p.IsSpecialName && p.IsDefined(typeof(InjectAttribute), true))
         .Select(p => CreateInjectableProperty(p))
         .ToArray();
 }
Ejemplo n.º 10
0
 IInjectableMethod[] CreateInjectableMethods(Type type, Type[] baseTypes)
 {
     return type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
         .Concat(baseTypes // Need to recover the private members from base types.
             .SelectMany(t => t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic))
             .Where(m => m.IsPrivate))
         .Where(m => !m.IsSpecialName && !m.IsConstructor && m.IsDefined(typeof(InjectAttribute), true))
         .Select(m => CreateInjectableMethod(m))
         .ToArray();
 }
Ejemplo n.º 11
0
 private static IEnumerable<Experiment> FindExperiments (Type[] registries)
 {
     return registries.SelectMany (
                reg => reg.GetFields (BindingFlags.Static | BindingFlags.Public)
                .Where (f => f.FieldType == typeof (Experiment))
                .Select (f => (Experiment)f.GetValue (null))
            )
            .Where (e => e.Enabled);
 }
		protected virtual IEnumerable<MethodInfo> GetMethods(Type baseType, Type [] additionalInterfaceTypes)
		{
			if (baseType != interfaceProxyType)
			{
				return (baseType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.IsFinal == false && (x.IsVirtual == true || x.IsAbstract == true)).Concat(additionalInterfaceTypes.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(y => y.IsVirtual == true))).Distinct().ToList());
			}
			else
			{
				return (additionalInterfaceTypes.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(y => y.IsFinal == false && (y.IsVirtual == true || y.IsAbstract == true))).Distinct().ToList());
			}
		}
		protected virtual IEnumerable<PropertyInfo> GetProperties(Type baseType, Type[] additionalInterfaceTypes)
		{
			if (baseType != interfaceProxyType)
			{
				return (baseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => ((x.CanRead == true) && (x.GetMethod.IsVirtual == true)) || ((x.CanWrite == true) && (x.SetMethod.IsVirtual == true))).Concat(additionalInterfaceTypes.SelectMany(x => x.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(y => ((y.CanRead == true) && (y.GetMethod.IsVirtual == true)) || ((y.CanWrite == true) && (y.SetMethod.IsVirtual == true))))).Distinct().ToList());
			}
			else
			{
				return (additionalInterfaceTypes.SelectMany(x => x.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(y => ((y.CanRead == true) && (y.GetMethod.IsVirtual == true)) || ((y.CanWrite == true) && (y.SetMethod.IsVirtual == true)))).Distinct().ToList());
			}
		}