Esempio n. 1
0
        public PluginFamily CreateTemplatedClone(Type[] templateTypes)
        {
            Type templatedType   = _pluginType.MakeGenericType(templateTypes);
            var  templatedFamily = new PluginFamily(templatedType);

            templatedFamily.copyLifecycle(this);

            _instances.GetAll().Select(x => {
                Instance clone = x.CloseType(templateTypes);
                if (clone == null)
                {
                    return(null);
                }

                clone.Name = x.Name;
                return(clone);
            }).Where(x => x != null).Each(templatedFamily.AddInstance);

            if (GetDefaultInstance() != null)
            {
                string   defaultKey = GetDefaultInstance().Name;
                Instance @default   = templatedFamily.Instances.FirstOrDefault(x => x.Name == defaultKey);
                if (@default != null)
                {
                    templatedFamily.SetDefault(@default);
                }
            }

            //Are there instances that close the templatedtype straight away?
            _instances.GetAll()
            .Where(x => x.ConcreteType.CanBeCastTo(templatedType))
            .Each(templatedFamily.AddInstance);

            return(templatedFamily);
        }
Esempio n. 2
0
    public PluginFamily CreateTemplatedClone(Type[] templateTypes)
    {
        Type templatedType = _pluginType.MakeGenericType(templateTypes);
            var templatedFamily = new PluginFamily(templatedType);
            templatedFamily.copyLifecycle(this);

            _instances.GetAll().Select(x => {
                Instance clone = x.CloseType(templateTypes);
                if (clone == null) return null;

                clone.Name = x.Name;
                return clone;
            }).Where(x => x != null).Each(templatedFamily.AddInstance);

            if (GetDefaultInstance() != null)
            {
                string defaultKey = GetDefaultInstance().Name;
                Instance @default = templatedFamily.Instances.FirstOrDefault(x => x.Name == defaultKey);
                if (@default != null)
                {
                    templatedFamily.SetDefault(@default);
                }
            }

            //Are there instances that close the templatedtype straight away?
            _instances.GetAll()
                      .Where(x => x.ConcreteType.CanBeCastTo(templatedType))
                      .Each(templatedFamily.AddInstance);

            return templatedFamily;
    }