1

Closed

Problem with recursive mapping

description

The follow (Attached too) code don't works properly.
 
 
class Program
{
    static void Main(string[] args)
    {
        FileSystemInfo fsi = new FileSystemInfo();
        fsi.FileSystemInfos = new List<FileSystemInfo>()
                                  {
                                      new FileSystemInfo
                                          {
                                              Parent = fsi, FileSystemInfos = null, FullName = "Exams\\Microsoft", IsDirectory = true
                                          },
                                      new FileSystemInfo { 
                                          Parent = fsi, FullName = "Exams\\Oracle", IsDirectory = true, 
                                          FileSystemInfos = new List<FileSystemInfo> {
                                                new FileSystemInfo(){ Parent = null, FullName = "Exams\\Oracle\\teste.vce", IsDirectory = false}
                                          } 
                                      },
                                  };
        fsi.FileSystemInfos[1].FileSystemInfos[0].Parent = fsi.FileSystemInfos[1];
 
        fsi.FullName = "Exams";
        fsi.IsDirectory = true;
 
 
 
        Mapping<FileSystemInfo, FileSystemViewModel> mapper = new Mapping<FileSystemInfo, FileSystemViewModel>();
        FileSystemViewModel model = mapper.Map(fsi);
        Console.WriteLine(model.FileSystemInfos.Count);
    }
}
public class FileSystemInfo
{
    public FileSystemInfo()
    {
        this.Parent = null;
        this.FileSystemInfos = new List<FileSystemInfo>();
    }
    public bool IsDirectory { get; set; }
    public FileSystemInfo Parent { get; set; }
    public string FullName { get; set; }
    public string Name
    {
        get
        {
            String name = "";
            if (!String.IsNullOrWhiteSpace(this.FullName))
            {
                String[] dirsInPath = this.FullName.Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                if (dirsInPath.Length > 0)
                {
                    name = dirsInPath[dirsInPath.Length - 1];
                }
            }
            return name;
        }
    }
    public List<FileSystemInfo> FileSystemInfos { get; set; }
}
public class FileSystemViewModel
{
    public bool IsDirectory { get; set; }
    public String ImagePath
    {
        get
        {
            return this.IsDirectory ? "/Resources/Images/AppBar/appbar.folder.rest.png"
                                    : "/Resources/Images/AppBar/appbar.clipboard.edit.png";
        }
    }
    public FileSystemViewModel Parent { get; set; }
    public string FullName { get; set; }
    public string Name { get; set; }
    public List<FileSystemViewModel> FileSystemInfos { get; set; }
}

file attachments

Closed Jan 8, 2012 at 11:22 AM by ToreVestues
Bug fixed in changeset 71770.

comments

thiagoburgo wrote Dec 29, 2011 at 3:06 AM

I Change my mapping (in attachment), but the error now is throw new GlueException("No object was set when trying to map from type 'FileSystemInfo' to type 'FileSystemViewModel'. Did you remember to instanciate the member of type 'FileSystemViewModel'?");

ToreVestues wrote Jan 8, 2012 at 11:21 AM

Hi, thanks for the feedback.

There are several problems here, one of which was a bug.

First, there is some issues with the code, I've checked in a working copy under GlueExamples\ReportedIssues\ProblemWithUnsetNestedEnumerables.cs

Second, there is a recursive mapping there, which Glue does not support for the moment (I commented it out in the code)

Third, there was a bug: Glue did not handle mapping between enumerables if the from-enumerable is null. This has been fixed.

wrote Jan 8, 2012 at 11:22 AM

wrote Feb 14, 2013 at 6:41 PM

wrote May 16, 2013 at 6:43 AM