1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Windows.Data;
9
using System.Reflection;
11
namespace ICSharpCode.WpfDesign.Designer.Services
13
public class ChooseClass : INotifyPropertyChanged
15
public ChooseClass(IEnumerable<Assembly> assemblies)
17
foreach (var a in assemblies) {
18
foreach (var t in a.GetExportedTypes()) {
20
if (t.IsAbstract) continue;
21
if (t.IsNested) continue;
22
if (t.IsGenericTypeDefinition) continue;
23
if (t.GetConstructor(Type.EmptyTypes) == null) continue;
24
projectClasses.Add(t);
29
projectClasses.Sort((c1, c2) => c1.Name.CompareTo(c2.Name));
30
classes = new ListCollectionView(projectClasses);
31
classes.Filter = FilterPredicate;
34
List<Type> projectClasses = new List<Type>();
36
ListCollectionView classes;
38
public ICollectionView Classes {
39
get { return classes; }
44
public string Filter {
51
RaisePropertyChanged("Filter");
55
bool showSystemClasses;
57
public bool ShowSystemClasses {
59
return showSystemClasses;
62
showSystemClasses = value;
64
RaisePropertyChanged("ShowSystemClasses");
68
public Type CurrentClass {
69
get { return Classes.CurrentItem as Type; }
72
bool FilterPredicate(object item)
74
Type c = item as Type;
75
if (!ShowSystemClasses) {
76
if (c.Namespace.StartsWith("System") || c.Namespace.StartsWith("Microsoft")) {
80
return Match(c.Name, Filter);
83
static bool Match(string className, string filter)
85
if (string.IsNullOrEmpty(filter))
88
return className.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase);
91
#region INotifyPropertyChanged Members
92
public event PropertyChangedEventHandler PropertyChanged;
94
void RaisePropertyChanged(string name)
96
if (PropertyChanged != null) {
97
PropertyChanged(this, new PropertyChangedEventArgs(name));