Beispiel #1
0
        private object Instantiate(InstantiateModel model)
        {
            var argumentList = from string name
                               in ObjectStorage.Keys
                               where (from ParameterInfo paramInfo
                                      in model.Method.GetParameters()
                                      select IsEqualName(name, paramInfo)
                                      ).Aggregate(false, CommonHelper.Disjunction)
                               select ObjectStorage[name];

            return(model.IsConstructorType ? Activator.CreateInstance(model.Type, argumentList.ToArray()) : model.Method.Invoke(Context, argumentList.ToArray()));
        }
Beispiel #2
0
        private void UpdateWeight(InstantiateModel model)
        {
            var weight = (from string name
                          in ModelStorage.Keys
                          where (from ParameterInfo paramInfo
                                 in model.Method.GetParameters()
                                 select IsEqualName(name, paramInfo)
                                 ).Aggregate(false, CommonHelper.Disjunction)
                          select ModelStorage[name].Weight
                          ).Aggregate(0, (a, b) => a + b);

            model.UpdateWeight(weight);
        }
Beispiel #3
0
        private bool CanInstantiate(InstantiateModel model)
        {
            var parameterInfos = model.Method.GetParameters();
            var required       = parameterInfos.Length;
            var complete       = (from string name
                                  in ObjectStorage.Keys
                                  where (from ParameterInfo paramInfo
                                         in parameterInfos
                                         select IsEqualName(name, paramInfo)
                                         ).Aggregate(false, CommonHelper.Disjunction)
                                  select ModelStorage[name]
                                  ).Count();

            return(required == complete);
        }
 public DependencyNotFoundException(InstantiateModel model) : base($"Can not instantiate : {model.Name}")
 {
 }
Beispiel #5
0
 private InstantiateModel AddModel(InstantiateModel model)
 {
     return(ModelStorage[model.Name] = model);
 }