protected virtual void SetNewItemProperties <TLocal>(TLocal newItem, IInvocationStatement invocation)
        {
            var newProperties  = typeof(TLocal).GetProperties();
            var usedProperties = new List <PropertyInfo>();

            foreach (var arg in invocation.Arguments)
            {
                // TODO: Allow unnamed args by correlating with method parameters.
                var argName  = arg.Name.Substring(0, 1).ToUpperInvariant() + arg.Name.Substring(1);
                var propInfo = newProperties.Where(x => x.Name == argName).FirstOrDefault();
                if (propInfo != null)
                {
                    object value = arg.ValueExpression;
                    if (propInfo.PropertyType == typeof(string))
                    {
                        value = arg.ValueExpression.InitialExpressionString;
                    }
                    propInfo.SetValue(newItem, value);
                    usedProperties.Add(propInfo);
                }
            }
            if (invocation.TypeArguments.Any())
            {
                var propInfo = typeof(TLocal).GetProperties().Where(x => x.Name == "PropertyType").First();
                if (propInfo != null)
                {
                    propInfo.SetValue(newItem, invocation.TypeArguments.First());
                }
            }
        }
        private IEnumerable <T> MapInvocation(IInvocationStatement invocation, IClass source, CodeFirstMetadata parent)
        {
            var newItems = new List <T>();

            if (invocation == null)
            {
                return(newItems);
            }
            if (source == null)
            {
                return(newItems);
            }

            var name = invocation.MethodName;

            // English language convention used here
            if (name.StartsWith("Add"))
            {
                name = name.SubstringAfter("Add");
                var plural  = Pluralizer.Pluralize(name);
                var current = source;
                if (current != null)
                {
                    var property = GetPropertyUseBase(plural, ref current);
                    if (property != null)
                    {
                        var newItem = Activator.CreateInstance <T>();
                        newItem.Parent = parent;
                        SetNewItemProperties(newItem, invocation);
                        newItems.Add(newItem);
                    }
                }
            }
            return(newItems);
        }