P
Paguro Bernardo
Hi all,
I'm building a user control in c#. This control has a property which
can contain an instance of a user defined class which has to be a
subclass of an abstract class A. I'd like the user of the control to be
able at design time to select the value of this property from a
dropdownlist showing all the subclasses of A that can be found in the
assemblies referenced in the project, so I wrote my own UITypeEditor
and at first everything seemed to be fine.
But then I noticed that the list in my editor displays only the
subclasses of A that are contained in assemblies which were referenced
before the control was added to the form, while it ignores the ones
contained in assemblies added after the creation of the control.
I found out that the even the classes contained in these late
assemblies are correctly identified by my code, but that the result of
the IsSubclassOf method is false instead of true.
This is a sample of what I'm doing (rs is an ITypeResolutionService):
Solution sol = currentDTE.Solution;
aList=new ArrayList();
foreach (Project prj in sol.Projects)
{
VSProject vsPrj=(VSProject) prj.Object;
References refs = vsPrj.References;
foreach (Reference aRef in refs)
{
AssemblyName aName=new AssemblyName();
aName.Name=aRef.Name;
Assembly anAssembly=rs.GetAssembly(aName);
if (anAssembly!=null)
{
Type[] types=anAssembly.GetTypes();
foreach (Type t in types)
{
if (t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(A)))
aList.Add(t.FullName);
}
}
}
}
Can you tell me what I'm doing wrong?
Many thanks,
Francesco.
I'm building a user control in c#. This control has a property which
can contain an instance of a user defined class which has to be a
subclass of an abstract class A. I'd like the user of the control to be
able at design time to select the value of this property from a
dropdownlist showing all the subclasses of A that can be found in the
assemblies referenced in the project, so I wrote my own UITypeEditor
and at first everything seemed to be fine.
But then I noticed that the list in my editor displays only the
subclasses of A that are contained in assemblies which were referenced
before the control was added to the form, while it ignores the ones
contained in assemblies added after the creation of the control.
I found out that the even the classes contained in these late
assemblies are correctly identified by my code, but that the result of
the IsSubclassOf method is false instead of true.
This is a sample of what I'm doing (rs is an ITypeResolutionService):
Solution sol = currentDTE.Solution;
aList=new ArrayList();
foreach (Project prj in sol.Projects)
{
VSProject vsPrj=(VSProject) prj.Object;
References refs = vsPrj.References;
foreach (Reference aRef in refs)
{
AssemblyName aName=new AssemblyName();
aName.Name=aRef.Name;
Assembly anAssembly=rs.GetAssembly(aName);
if (anAssembly!=null)
{
Type[] types=anAssembly.GetTypes();
foreach (Type t in types)
{
if (t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(A)))
aList.Add(t.FullName);
}
}
}
}
Can you tell me what I'm doing wrong?
Many thanks,
Francesco.