Default Value

Dec 10, 2013 at 7:58 PM

I faced with problem.
I have a class with catel property:
    public partial class Solution : AbstractFolder, ISolution
        /// <summary>Register the Folders property so it is known in the class.</summary>
        public static readonly PropertyData FoldersProperty =
            RegisterProperty<Solution, IReadOnlyList<IFolder>>(model => model.Folders, new List<IFolder>());

        private List<IFolder> FoldersPrivate
            get { return GetValue<List<IFolder>>(FoldersProperty); }
            set { SetValue(FoldersProperty, value); }
When i first time instantiate this class the FoldersPrivate is empty.
But when i instantiate it 2nd time and 1st one is not destroied yet, it contains elements from 1st instance.
Is there any way to make default value in PropertyData read only? Because, if i understand correctly, default value updating each time PropertyData data updates.
Here is a test:
        public void LoadSolution()
            var path = RootFolder + @"TestSolution\TestSolution.gesln";

                var sol = SolutionService.CreateSolution("TestSolution", path);
                sol.AddFolder(new SolutionFolder("TestFolder", RootFolder + @"TestSolution\TestFolder"));
                SolutionFolder folder = null;
                sol.AddFolder(folder = new SolutionFolder("TestFolder2", RootFolder + @"TestSolution\TestFolder2"));
                folder.AddFolder(new GameEdProjectBinding().CreateProject(folder, "TestProject", RootFolder + @"TestSolution\TestFolder2\TestProject\TestProject.geprj"));

                var hash1 = Helper.HashFile(path);
                var sol2 = SolutionService.LoadSolution(path);


                var hash2 = Helper.HashFile(RootFolder + @"TestSolution");

Dec 10, 2013 at 8:01 PM
You should use the callback to set the default value. For more information, see this blog post.
Dec 10, 2013 at 8:06 PM
Thank you for fast reply.
It would be nice if you include this information to comments in code.
Dec 10, 2013 at 8:08 PM
I try to do that in examples. Where did you expect to find this information? Then I will add it there.