예제 #1
0
        /// <summary>
        /// Registers a control into the global <see cref="ControlRegistrator"/>.
        /// </summary>
        /// <param name="key">The key, that should identify the registered control.</param>
        /// <param name="type">The type to register.</param>
        /// <exception cref="NotSupportedException">Can't register type. The type is no instance of the
        /// registered type identified by <see cref="CheckTypeAttribute"/>.</exception>
        public static void RegisterControl(Enum key, Type type, IInstanceLifetime lifetime)
        {
            Gu.NotNull(() => key, key);
            Gu.NotNull(() => type, type);
            Gu.NotNull(() => lifetime, lifetime);

            // classSpecificationWindowType = type;
            // var xxx = Data.BackupItemViewModel.WindowTypes.TaskEditor.GetType();
            // var yyy = xxx.GetCustomAttributes(false);
            var kindType = key.GetType();
            var member   = kindType.GetMembers().FirstOrDefault(e => e.Name == key.ToString());

            if (member != null)
            {
                var attrs  = member.GetCustomAttributes(false);
                var ctattr = attrs.OfType <CheckTypeAttribute>();
                foreach (var item in ctattr)
                {
                    if (!type.IsSubclassOf(item.Type))
                    {
                        throw new NotSupportedException(
                                  "Can't register type. The type "
                                  + type + " is no instance of " + item.Type);
                    }

                    /*if (!type.IsInstanceOfType(item.Type))
                     *                  {
                     *                      throw new NotSupportedException("Can't register type. The type "
                     + type.ToString() + " is no instance of " + item.Type.ToString());
                     +                  }*/
                }
            }

            // var values = Enum.GetValues(kindType);
            // var attrs = kindType.GetCustomAttributes(false);
            RegisteredControlTypes.Add(key, new InstanceInfo(type, lifetime));

            // var w = CreateInstanceFromType<Window>(type);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new fully specified instance of the <see cref="InstanceInfo"/> class.
 /// </summary>
 /// <param name="Instance">The Instance</param>
 /// <param name="Lifetime">The Lifetime</param>
 internal InstanceInfo(Type instanceType, IInstanceLifetime lifetime)
 {
     this.InstanceType = instanceType;
     this.Lifetime     = lifetime;
 }