GetNestedType

  • Thread starter Thread starter Bud J via DotNetMonster.com
  • Start date Start date
B

Bud J via DotNetMonster.com

if i have a class that

public class Jobbers
{
public Type ThisType()
{
return typeof(MyClass);
}
}


why when i call get GetNestedType on jobbers it returns null
 
Hello,
Can you please tell me how are you calling GetNestedType method. I
don't see a NestedType in Jobbers class. ThisType is a method of Jobbers
class right?

Cheers.
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net
 
i think you answered my question. a nested "type" is a nested class/struct


thanks for the help!
 
Bud J via DotNetMonster.com said:
i think you answered my question. a nested "type" is a nested class/struct

Or delegate. It's exactly a type which is nested within another type.
Was it just what "type" meant which was confusing you?
 
Yep that was my problem. what i'm trying to do is put the correct type in
the GetItemProperties method of an itypedlist implementation. If the list
contains only one type no problem for example


if i have a CustomersCollection class that is a list of customer class then
no problem when the GetItemProperties is called listaccessors is null i can
easily pass it Customer. But if one of the properties of customer is
OrdersCollection (istaccessors!=null) how do i pass it Order?

//CollectionType is just an abtract method
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[]
listAccessors)
{
if(listAccessors==null)
{
return TypeDescriptor.GetProperties(this.CollectionType());
}
else
{
System.ComponentModel.PropertyDescriptor pD = listAccessors
[listAccessors.Length -1];
return TypeDescriptor.GetProperties(pD.PropertyType);
}

}
 
Bud J via DotNetMonster.com said:
Yep that was my problem. what i'm trying to do is put the correct type in
the GetItemProperties method of an itypedlist implementation. If the list
contains only one type no problem for example

if i have a CustomersCollection class that is a list of customer class then
no problem when the GetItemProperties is called listaccessors is null i can
easily pass it Customer. But if one of the properties of customer is
OrdersCollection (istaccessors!=null) how do i pass it Order?

I'm not sure I understand the problem. If you have two different types
in the list of PropertyDescriptors, then how do you expect to return
one sensible PropertyDescriptorCollection? If you want to return the
union of the two collections, you could get a collection for each
property type, and add one to the other, but I'm not sure whether
that's really what you want.

To be honest, I haven't used ITypedList myself, so it's a bit hard to
know exactly what's going on.
 
if I hard coded

return TypeDescriptor.GetProperties(Order);

then all would be right

so if i have the type OrdersCollection which the following will give me

return TypeDescriptor.GetProperties(pD.PropertyType);

how do i get Order instead of OrdersCollection? I want to return the
properties Order no OrdersCollection.

there's an example of what i'm trying to do in current issue of msdn magazine
minus this implementation of GetItemProperties.
http://msdn.microsoft.com/msdnmag/code05.aspx. CustomCollectionBinding

I've been tinkering with this for several months now and have it in several
projects with the hardcoding of the class type. If i could figure out how to
do it without having to hard code the type it would do away with a fair
amount of maintenance
 
Bud J via DotNetMonster.com said:
if I hard coded

return TypeDescriptor.GetProperties(Order);

then all would be right

so if i have the type OrdersCollection which the following will give me

return TypeDescriptor.GetProperties(pD.PropertyType);

how do i get Order instead of OrdersCollection? I want to return the
properties Order no OrdersCollection.

there's an example of what i'm trying to do in current issue of msdn magazine
minus this implementation of GetItemProperties.
http://msdn.microsoft.com/msdnmag/code05.aspx. CustomCollectionBinding

I've been tinkering with this for several months now and have it in several
projects with the hardcoding of the class type. If i could figure out how to
do it without having to hard code the type it would do away with a fair
amount of maintenance

I'm afraid without more experience of the kind of thing you're doing, I
won't know. However, you could perhaps look at the members of
OrdersCollection and other collections. Find a common member which,
say, uses the appropriate type as the return type, or a parameter type.
Get that type by reflection, and you'll be away.
 
Back
Top