public XmlAbstractItem Create(string typeName)
        {
            var typesDictionary = _typeFinder.GetTypesOf <XmlAbstractItem>();

            if (typesDictionary.ContainsKey(typeName))
            {
                return(Activator.CreateInstance(typesDictionary[typeName]) as XmlAbstractItem);
            }

            return(null);
        }
        private Dictionary <string, ItemDefinition> BuildItemDefinitions()
        {
            var persistentData  = _repository.GetAllItemDefinitions(_buildSettings.SiteId, _buildSettings.IsStage);
            var typesDictionary = _typeFinder.GetTypesOf <AbstractItem>();

            return(persistentData
                   .Where(_ => typesDictionary.ContainsKey(_.TypeName))
                   .Select(_ => new ItemDefinition {
                Id = _.Id, Discriminator = _.Discriminator, TypeName = _.TypeName, Type = typesDictionary[_.TypeName]
            })
                   .ToDictionary(_ => _.Discriminator, _ => _));
        }
Beispiel #3
0
        public AttributeConventionalControllerMapper(ITypeFinder typeFinder)
        {
            var contollerTypes = typeFinder.GetTypesOf <Controller>();

            foreach (var t in contollerTypes.Values)
            {
                var attr = t.GetCustomAttributes(typeof(SiteStructureControllerAttribute), false).Cast <SiteStructureControllerAttribute>().FirstOrDefault();
                if (attr != null && attr.ItemType != null)
                {
                    if (_contollerMap.ContainsKey(attr.ItemType))
                    {
                        throw new Exception($"There are two or many contollers mapped on {attr.ItemType.Name}");
                    }

                    _contollerMap[attr.ItemType] = t;
                }
            }
        }