Exemple #1
0
        private static void HandleMember(Dictionary <string, IGeneratorFunc> dict, MemberInfo member, object obj)
        {
            if (dict.ContainsKey(member.Name))
            {
                return;
            }

            var mType = GetMemberType(member);

            var getExp = Expression.Lambda(Expression.PropertyOrField(Expression.Constant(obj), member.Name)).Compile();
            var lExp   = Expression.Lambda(Expression.Convert(Expression.Constant(getExp.DynamicInvoke()), mType));

            dict.Add(member.Name, GeneratorFuncFactory.CreateFromFunc(mType, lExp));
        }
Exemple #2
0
 private bool ValidateParameter(ParameterInfo parameter, IGeneratorFunc[] parameterGenerators, int index, List <IATMap> chain)
 {
     if (constructorParameters.ContainsKey(parameter.Name))
     {
         parameterGenerators[index] = constructorParameters[parameter.Name];
     }
     else
     {
         IATMFactory firstMap;
         if (!TryGetFirstMapForType(parameter.ParameterType, chain, out firstMap))
         {
             return(false);
         }
         var method = typeof(IATMFactory <>).MakeGenericType(parameter.ParameterType).GetMethod("Get");
         var lExp   = Expression.Lambda(Expression.Call(Expression.Constant(firstMap), method));
         parameterGenerators[index] = GeneratorFuncFactory.CreateFromFunc(parameter.ParameterType, lExp);
     }
     return(true);
 }