Exemplo n.º 1
0
        public static void CheckProperty(AbstractTypeConfiguration config, string name, Type configType)
        {
            var pConfig = config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == name);

            Assert.IsNotNull(pConfig, "Could not find property with name {0}".Formatted(name));
            Assert.AreEqual(configType, pConfig.GetType(), "Property {0} is not of expected type".Formatted(name));
        }
        public AbstractTypeConfiguration LoadType(Type type)
        {
            AbstractTypeConfiguration config = null;

            IEnumerable <object> attrs;

            try
            {
                attrs = type.GetCustomAttributes(true);
            }
            catch
            {
                return(null);
            }
            var attr = attrs.FirstOrDefault(y => y is AbstractTypeAttribute) as AbstractTypeAttribute;

            if (attr != null)
            {
                config = attr.Configure(type);
                if (config != null)
                {
                    //load the properties on the type
                    foreach (var property in LoadPropertiesFromType(type))
                    {
                        if (property != null)
                        {
                            config.AddProperty(property);
                        }
                    }
                }
            }

            return(config);
        }
 /// <summary>
 /// Configures the specified type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="config">The config.</param>
 protected virtual void Configure(Type type, AbstractTypeConfiguration config)
 {
     config.Type = type;
     config.ConstructorMethods = Utilities.CreateConstructorDelegates(type);
     config.AutoMap = AutoMap;
     config.Cachable = Cachable;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Configures the specified type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="config">The config.</param>
 protected virtual void Configure(Type type, AbstractTypeConfiguration config)
 {
     config.Type = type;
     config.ConstructorMethods = Utilities.CreateConstructorDelegates(type);
     config.AutoMap            = AutoMap;
     config.Cachable           = Cachable;
 }
        protected override object[] GetConstructorParameters(AbstractTypeConfiguration config)
        {
            var parameters = config.ConstructorMethods.Select(x => x.Key.GetParameters())
                             .OrderBy(x => x.Length)
                             .First();

            var resolved = parameters.Select(x => Container.GetInstance(x.ParameterType));

            return(resolved.ToArray());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectConstructionArgs"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="abstractTypeCreationContext">The abstract type creation context.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="service">The service.</param>
 public ObjectConstructionArgs(
     Context context,
     AbstractTypeCreationContext abstractTypeCreationContext,
     AbstractTypeConfiguration configuration,
     IAbstractService service)
     : base(context)
 {
     AbstractTypeCreationContext = abstractTypeCreationContext;
     Configuration = configuration;
     Service       = service;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Configures the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="config">The config.</param>
        /// <exception cref="ConfigurationException">Type configuration is not of type {0}.Formatted(typeof(UmbracoTypeConfiguration).FullName)</exception>
        public override void Configure(Type type, AbstractTypeConfiguration config)
        {
            var umbConfig = config as UmbracoTypeConfiguration;

            if (umbConfig == null)
            {
                throw new ConfigurationException(
                          "Type configuration is not of type {0}".Formatted(typeof(UmbracoTypeConfiguration).FullName));
            }

            umbConfig.ContentTypeAlias = ContentTypeAlias;
            umbConfig.CodeFirst        = CodeFirst;
            umbConfig.ContentTypeName  = ContentTypeName;

            base.Configure(type, config);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Configs the created.
        /// </summary>
        /// <param name="config">The config.</param>
        protected override void ConfigCreated(AbstractTypeConfiguration config)
        {
            var umbConfig = config as UmbracoTypeConfiguration;

            if (umbConfig != null)
            {
                //find the property configs that will be used to link a umbraco item to a class
                umbConfig.IdConfig =
                    config.Properties.FirstOrDefault(x => x is UmbracoIdConfiguration) as UmbracoIdConfiguration;

                var umbInfos = config.Properties.Where(x => x is UmbracoInfoConfiguration).Cast <UmbracoInfoConfiguration>();
                umbConfig.VersionConfig = umbInfos.FirstOrDefault(x => x.Type == UmbracoInfoType.Version);
            }

            base.ConfigCreated(config);
        }
 public void Setup()
 {
     _configuration = new StubAbstractTypeConfiguration();
 }
 protected abstract object[] GetConstructorParameters(AbstractTypeConfiguration config);
 protected abstract object CreateConcreteInstance(AbstractTypeConfiguration config);
 protected override object CreateConcreteInstance(AbstractTypeConfiguration config)
 {
     return(Container.GetInstance(config.Type));
 }
 /// <summary>
 /// This method is called after a configuration has been loaded. Use this method for any specific
 /// post configuration processing
 /// </summary>
 /// <param name="config">The config.</param>
 protected virtual void ConfigCreated(AbstractTypeConfiguration config)
 {
 }