Beispiel #1
0
        public static ContentPostModel ConvertToPassingModel(this ContentBase input)
        {
            var result = new ContentPostModel();

            var resultProperty = result.GetType().GetProperties().Where(b => b.BaseProperty()).ToList();
            var properties     = input.GetType().GetProperties();

            foreach (var p in properties)
            {
                if (p.SkippedProperty())
                {
                    continue;
                }
                var inputValue = p.GetValue(input);
                if (p.BaseProperty())
                {
                    var baseP = resultProperty.Where(b => b.Name == p.Name).FirstOrDefault();
                    if (baseP == null)
                    {
                        continue;
                    }
                    if (inputValue == null)
                    {
                        continue;
                    }
                    baseP.SetValue(result, inputValue);
                    continue;
                }
                var prop = p.GetContentPropertyByPropertyInfo(inputValue);
                if (prop == null)
                {
                    continue;
                }
                result.Properties.Add(prop);
            }
            return(result);
        }
Beispiel #2
0
        public static ContentBase ConvertToBaseModel(this ContentPostModel input, bool deleteExistFile = true, List <string> oldFiles = null, List <string> newFiles = null)
        {
            var result       = (ContentBase)input.ConvertBaseTypeToEnity(out var typeName, out var assemblyName);
            var properties   = result.GetType().GetProperties();
            var baseProperty = input.GetType().GetProperties().Where(b => b.BaseProperty()).ToList();

            foreach (var p in properties)
            {
                try
                {
                    if (p.BaseProperty())
                    {
                        var inputBaseProperty = baseProperty.Where(b => b.Name == p.Name).FirstOrDefault();
                        if (inputBaseProperty == null)
                        {
                            continue;
                        }
                        p.SetValue(result, inputBaseProperty.GetValue(input));
                        continue;
                    }
                    if (p.SkippedProperty())
                    {
                        continue;
                    }

                    p.SetPropertyValue(input, result, deleteExistFile, oldFiles, newFiles);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            result.FullType     = typeName;
            result.AssemblyName = assemblyName;
            return(result);
        }