Esempio n. 1
0
        public static object Map(this IMapper extended, object source, Type targetType)
        {
            object target = instantiator.Create(targetType);
            object result = Map(extended, source, targetType, target);

            return(result);
        }
        private object GetTargetValue(Type sourceType, object sourceValue, Type targetType)
        {
            if (sourceType.IsValueType || sourceType == typeof(string))
            {
                return(sourceValue);
            }

            object targetValue = instantiator.Create(targetType);

            lazyMapper.Service.Map(sourceType, sourceValue, targetType, targetValue);
            return(targetValue);
        }
Esempio n. 3
0
        public virtual T Spawn <T>() where T : IConcurrentObject, new()
        {
            if (_types != null)
            {
                var result = (T)Spawn(typeof(T).Name);
                return(result);
            }

            if (_instantiator != null)
            {
                var result = (T)_instantiator.Create(typeof(T));
                return(result);
            }

            return(spawnObject(new T()));
        }
Esempio n. 4
0
        public static void FromAssemblies(
            IDistributedApp app,
            IEnumerable <Assembly> assemblies,
            IInstantiator instantiator,
            IEnumerable <string> except = null,
            IEnumerable <string> only   = null)
        {
            var classes   = new List <Type>();
            var instances = new Dictionary <Guid, Type>();

            foreach (var assembly in assemblies)
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (except != null && except.Contains(type.Name))
                    {
                        continue;
                    }

                    if (only != null && !only.Contains(type.Name))
                    {
                        continue;
                    }

                    var id = default(Guid);
                    var isConcurrentType = isConcurrent(type);
                    var isServiceType    = isService(type, out id);
                    if (isConcurrentType)
                    {
                        app.RegisterClass(type);
                    }

                    if (isServiceType)
                    {
                        app.RegisterInstance(id, (IConcurrentObject)instantiator.Create(type));
                    }

                    if (isServiceType || isConcurrentType)
                    {
                        continue;
                    }
                }
            }
        }
Esempio n. 5
0
        public T set <T>()
        {
            if (_instantiator == null)
            {
                _instantiator = get <IInstantiator>();
                if (_instantiator == null)
                {
                    throw new InvalidOperationException("no instantiator registered");
                }
            }

            var value = (T)_instantiator?.Create(typeof(T));

            if (value == null)
            {
                throw new InvalidOperationException($"type not instantiable: {typeof(T)}");
            }

            set(key <T>(), value);
            return(value);
        }