internal void LoadParent(PropertyViewModel viewModel)
 {
     Load(viewModel.FindParent <TypeViewModel>(true));
 }
Esempio n. 2
0
 public override void Unload()
 {
     _node = null;
 }
        protected override void LoadChildren(List <NodeViewModel> children)
        {
            var moduleViewModel = FindParent <ModuleViewModel>(true);
            var projectModule   = moduleViewModel.ProjectModule;

            // Load methods
            var methods = new Dictionary <IMethodSignature, MethodDeclaration>(SignatureComparer.IgnoreMemberOwner);

            foreach (var method in _type.Methods)
            {
                methods.Add(method, method);
            }

            // Load properties
            List <PropertyViewModel> propertyViewModels = null;

            if (_type.Properties.Count > 0)
            {
                propertyViewModels = new List <PropertyViewModel>(_type.Properties.Count);
                var projectProperties = projectModule.Properties;

                foreach (var property in _type.Properties)
                {
                    AD.ProjectProperty projectProperty;
                    if (!projectProperties.TryGetValue(property, out projectProperty))
                    {
                        projectProperty = new AD.ProjectProperty();
                    }

                    var propertyViewModel = new PropertyViewModel(property, projectProperty, this);

                    propertyViewModel.AddMethods(
                        CreateMethodSemantic(property.GetMethod, propertyViewModel, moduleViewModel, methods),
                        CreateMethodSemantic(property.SetMethod, propertyViewModel, moduleViewModel, methods));

                    propertyViewModels.Add(propertyViewModel);
                }
            }

            // Load events
            List <EventViewModel> eventViewModels = null;

            if (_type.Events.Count > 0)
            {
                eventViewModels = new List <EventViewModel>(_type.Events.Count);
                var projectEvents = projectModule.Events;

                foreach (var e in _type.Events)
                {
                    AD.ProjectEvent projectEvent;
                    if (!projectEvents.TryGetValue(e, out projectEvent))
                    {
                        projectEvent = new AD.ProjectEvent();
                    }

                    var eventViewModel = new EventViewModel(e, projectEvent, this);

                    eventViewModel.AddMethods(
                        CreateMethodSemantic(e.AddMethod, eventViewModel, moduleViewModel, methods),
                        CreateMethodSemantic(e.RemoveMethod, eventViewModel, moduleViewModel, methods),
                        CreateMethodSemantic(e.InvokeMethod, eventViewModel, moduleViewModel, methods));

                    eventViewModels.Add(eventViewModel);
                }
            }

            // Add nested types
            if (_type.NestedTypes.Count > 0)
            {
                int index        = children.Count;
                var projectTypes = projectModule.Types;

                foreach (var nestedType in _type.NestedTypes)
                {
                    AD.ProjectType projectType;
                    if (!projectTypes.TryGetValue(nestedType, out projectType))
                    {
                        projectType = new AD.ProjectType();
                    }

                    var typeViewModel = new TypeViewModel(nestedType, projectType, this);
                    children.Add(typeViewModel);
                }

                children.Sort(index, children.Count - index, NodeComparer.Default);
            }

            // Add fields
            if (_type.Fields.Count > 0)
            {
                int index         = children.Count;
                var projectFields = projectModule.Fields;

                foreach (var field in _type.Fields)
                {
                    AD.ProjectField projectField;
                    if (!projectFields.TryGetValue(field, out projectField))
                    {
                        projectField = new AD.ProjectField();
                    }

                    var fieldViewModel = new FieldViewModel(field, projectField, this);
                    children.Add(fieldViewModel);
                }

                children.Sort(index, children.Count - index, NodeComparer.Default);
            }

            // Add methods
            if (methods.Count > 0)
            {
                int index          = children.Count;
                var projectMethods = projectModule.Methods;

                foreach (var method in methods.Values)
                {
                    AD.ProjectMethod projectMethod;
                    if (!projectMethods.TryGetValue(method, out projectMethod))
                    {
                        projectMethod = new AD.ProjectMethod();
                    }

                    var methodViewModel = new MethodViewModel(method, projectMethod, this);
                    children.Add(methodViewModel);
                }

                children.Sort(index, children.Count - index, NodeComparer.Default);
            }

            // Add properties
            if (propertyViewModels != null)
            {
                int index = children.Count;

                foreach (var propertyViewModel in propertyViewModels)
                {
                    children.Add(propertyViewModel);
                }

                children.Sort(index, children.Count - index, NodeComparer.Default);
            }

            // Add events
            if (eventViewModels != null)
            {
                int index = children.Count;

                foreach (var eventViewModel in eventViewModels)
                {
                    children.Add(eventViewModel);
                }

                children.Sort(index, children.Count - index, NodeComparer.Default);
            }
        }