Esempio n. 1
0
        /// <summary>
        ///     generates container manifest of given type
        /// </summary>
        /// <param name="type"> </param>
        public ManifestClassDefinition(Type type, object[] predesc = null)
        {
            // we use indirect attribute usage to avoid msbuild context problems - we have to make compoents even in different versions of system
            Type    = type;
            predesc = predesc ??
                      type.GetCustomAttributes(true).Where(x =>
            {
                var baseType = x.GetType().BaseType;
                return(baseType != null && (x.GetType().Name == typeof(ContainerComponentAttribute).Name
                                            ||
                                            baseType.Name == typeof(ContainerComponentAttribute).Name));
            }).ToArray();

            foreach (var p in predesc)
            {
                var d = new ContainerComponentAttribute
                {
                    Lifestyle    = p.GetValue <Lifestyle>("Lifestyle"),
                    Name         = p.GetValue <string>("Name"),
                    Help         = p.GetValue <string>("Help"),
                    Role         = p.GetValue <string>("Role"),
                    ServiceType  = p.GetValue <Type>("ServiceType"),
                    Priority     = p.GetValue <int>("Priority"),
                    Tag          = p.GetValue <string>("Tag"),
                    Names        = p.GetValue <string[]>("Names"),
                    ServiceTypes = p.GetValue <Type[]>("ServiceTypes")
                };
                if (null == d.ServiceType && null == d.ServiceTypes)
                {
                    d.ServiceType =
                        type.GetInterfaces()
                        .Except(type.BaseType.GetInterfaces())
                        .FirstOrDefault(x => x != typeof(IContainerBound)) ??
                        type;
                }
                Descriptors.Add(d);
            }
        }
		/// <summary>
		/// 	generates container manifest of given type
		/// </summary>
		/// <param name="type"> </param>
		public ManifestClassDefinition(Type type, object[] predesc = null) {
            
            // we use indirect attribute usage to avoid msbuild context problems - we have to make compoents even in different versions of system
            Type = type;
            predesc = predesc ??
                type.GetCustomAttributes(true).Where(x =>
                {
                    var baseType = x.GetType().BaseType;
                    return baseType != null && (x.GetType().Name == typeof(ContainerComponentAttribute).Name
                                                                                      ||
                                                                                      baseType.Name == typeof(ContainerComponentAttribute).Name);
                }).ToArray();

            foreach (var p in predesc)
            {
                var d = new ContainerComponentAttribute
                {
                    Lifestyle = p.GetValue<Lifestyle>("Lifestyle"),
                    Name = p.GetValue<string>("Name"),
                    Help = p.GetValue<string>("Help"),
                    Role = p.GetValue<string>("Role"),
                    ServiceType = p.GetValue<Type>("ServiceType"),
                    Priority = p.GetValue<int>("Priority"),
                    Tag = p.GetValue<string>("Tag"),
                    Names = p.GetValue<string[]>("Names"),
                    ServiceTypes = p.GetValue<Type[]>("ServiceTypes")
                };
                if (null == d.ServiceType && null == d.ServiceTypes)
                {
                    d.ServiceType =
                        type.GetInterfaces()
                            .Except(type.BaseType.GetInterfaces())
                            .FirstOrDefault(x => x != typeof(IContainerBound)) ??
                        type;
                }
                Descriptors.Add(d);
            }
        }