private string GetRecordTypeFor(string field, RecordEntryViewModelBase viewModel)
        {
            var split = field?.Split('.') ?? new string[0];

            if (!split.Any())
            {
                return(null);
            }
            var propertyInfo = GetPropertyInfo(split.First(), viewModel.GetRecord().Type);

            if (propertyInfo != null)
            {
                if (propertyInfo.GetType().Name == "IEnumerable`1" && split.Count() > 1)
                {
                    var enumeratedType = propertyInfo.GetType().GenericTypeArguments[0];
                    propertyInfo = enumeratedType.GetProperty(split.ElementAt(1)) ?? propertyInfo;
                }
                var attribute = propertyInfo.GetCustomAttribute <ReferencedType>();
                if (attribute != null)
                {
                    return(attribute.Type);
                }
            }
            foreach (var parentField in ObjectRecordService.GetPropertyInfos(viewModel.GetRecordType()))
            {
                var lookupForAttributes =
                    parentField.GetCustomAttributes(typeof(RecordTypeFor), true).Cast <RecordTypeFor>();
                foreach (var lookupForAttribute in lookupForAttributes)
                {
                    if (lookupForAttribute.LookupProperty == field)
                    {
                        //can't use the field view model as called on load and may trigger infinite loop loading field list
                        var record = viewModel.GetRecord();
                        if (record is ObjectRecord)
                        {
                            var objectrecord  = (ObjectRecord)record;
                            var propertyValue = objectrecord.Instance.GetPropertyValue(parentField.Name);
                            if (propertyValue is RecordType)
                            {
                                return(((RecordType)propertyValue).Key);
                            }
                        }
                    }
                }
            }
            var parentForm = viewModel.ParentForm;

            if (parentForm is ObjectEntryViewModel)
            {
                foreach (var parentField in ((ObjectEntryViewModel)parentForm).GetObject().GetType().GetProperties())
                {
                    var lookupForAttributes =
                        parentField.GetCustomAttributes(typeof(RecordTypeFor), true).Cast <RecordTypeFor>();
                    foreach (var lookupForAttribute in lookupForAttributes)
                    {
                        if (lookupForAttribute.PropertyPaths.Count() == 2 &&
                            lookupForAttribute.PropertyPaths.First() == viewModel.ParentFormReference &&
                            lookupForAttribute.PropertyPaths.Last() == field)
                        {
                            var parentsFieldViewmOdel = parentForm.GetRecordTypeFieldViewModel(parentField.Name);
                            if (parentsFieldViewmOdel.Value != null)
                            {
                                return(parentsFieldViewmOdel.Value.Key);
                            }
                        }
                    }
                }
            }
            return(null);
        }