コード例 #1
0
        public void AddProperty(PropertyViewModel property)
        {
            if (property.Parent != this)
                throw new InvalidOperationException("Bad parent");
            workingProperties.Add(property);

            property.PropertyChanged += OnPropertyViewModelPropertyChanged;
        }
コード例 #2
0
ファイル: RootViewModel.cs プロジェクト: yongweisun/paradox
        private async Task LoadAssembly(string assemblyFilename)
        {
            if (string.IsNullOrWhiteSpace(assemblyFilename))
            {
                throw new ArgumentException("Invalid 'assemblyFilename' argument");
            }

            Assembly assembly = null;

            try
            {
                assembly = await Task.Factory.StartNew(() =>
                {
                    try
                    {
                        return(Assembly.LoadFrom(assemblyFilename));
                    }
                    catch
                    {
                        return(null);
                    }
                });
            }
            catch
            {
                return;
            }

            if (assembly == null)
            {
                return;
            }

            IEnumerable <Type> configurationSections = null;

            try
            {
                configurationSections = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ConfigurationSection)));
            }
            catch
            {
                return;
            }

            foreach (var configSection in configurationSections)
            {
                var hasValidProperties = false;
                var sectionViewModel   = new SectionViewModel(assembly, configSection);

                var properties = await Task.Factory.StartNew(arg => ((Type)arg).GetProperties(BindingFlags.Public | BindingFlags.Instance), configSection);

                foreach (var property in properties.OrderBy(p => p.Name))
                {
                    var attribute = property.GetCustomAttributes(typeof(ConfigurationPropertyAttribute), true)
                                    .Cast <ConfigurationPropertyAttribute>()
                                    .FirstOrDefault();

                    if (attribute != null)
                    {
                        var propertyViewModel = new PropertyViewModel(sectionViewModel, property, attribute);
                        sectionViewModel.AddProperty(propertyViewModel);

                        hasValidProperties = true;
                    }
                }

                if (hasValidProperties)
                {
                    workingSections.Add(sectionViewModel);
                }
            }
        }
コード例 #3
0
ファイル: RootViewModel.cs プロジェクト: Powerino73/paradox
        private async Task LoadAssembly(string assemblyFilename)
        {
            if (string.IsNullOrWhiteSpace(assemblyFilename))
                throw new ArgumentException("Invalid 'assemblyFilename' argument");

            Assembly assembly = null;

            try
            {
                assembly = await Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            return Assembly.LoadFrom(assemblyFilename);
                        }
                        catch
                        {
                            return null;
                        }
                    });
            }
            catch
            {
                return;
            }

            if (assembly == null)
                return;

            IEnumerable<Type> configurationSections = null;

            try
            {
                configurationSections = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ConfigurationSection)));
            }
            catch
            {
                return;
            }

            foreach (var configSection in configurationSections)
            {
                var hasValidProperties = false;
                var sectionViewModel = new SectionViewModel(assembly, configSection);

                var properties = await Task.Factory.StartNew(arg => ((Type)arg).GetProperties(BindingFlags.Public | BindingFlags.Instance), configSection);

                foreach (var property in properties.OrderBy(p => p.Name))
                {
                    var attribute = property.GetCustomAttributes(typeof(ConfigurationPropertyAttribute), true)
                        .Cast<ConfigurationPropertyAttribute>()
                        .FirstOrDefault();

                    if (attribute != null)
                    {
                        var propertyViewModel = new PropertyViewModel(sectionViewModel, property, attribute);
                        sectionViewModel.AddProperty(propertyViewModel);

                        hasValidProperties = true;
                    }
                }

                if (hasValidProperties)
                    workingSections.Add(sectionViewModel);
            }
        }