User avatar
CornNieu
Topic Author
Posts: 11
Joined: 24 Oct 2022, 15:58
Location: Sweden, Falun
Contact:

Get type of ObservableCollection from Basecomponent

24 Oct 2022, 16:07

Hi Noesis Devs!

I've been struggling with getting the templated type of a ObservableCollection from a BaseComponent. I've managed to get ObservableCollection from conversion with "DynamicPtrCast". But am now halted as i need to add the correct class type into the ObservableCollection, so that i can set the values of the reflected properties of that certain class through ImGui.

TLDR;
Want the correct T type to insert into a ObservableCollection, but don't know the T type.
 
User avatar
jsantos
Site Admin
Posts: 4822
Joined: 20 Jan 2012, 17:18
Contact:

Re: Get type of ObservableCollection from Basecomponent

24 Oct 2022, 16:45

Right now there is no way to get that information. I assume when you mention using DynamicPtrCast you mean BaseObservableCollection instead of ObservableCollection right?

I need to understand more about your scenario to help you. Do you want to box the elements and add them using the BaseCollection API?
 
User avatar
CornNieu
Topic Author
Posts: 11
Joined: 24 Oct 2022, 15:58
Location: Sweden, Falun
Contact:

Re: Get type of ObservableCollection from Basecomponent

25 Oct 2022, 07:54

Well ATM i get the base type of my class which is based on BaseComponent, so " ObservableCollection < iDataModel > ". Which allows me to add and remove but not add the 'specific' class. Which doesn't allow me to have the correct properties.

So Yes, i want to box a BaseComponent into T of ObservableCollection, so that i can add them using the API.

For more context, i'm making a recursive property setter for Noesis with ImGui. This is made for other developers to test Noesis Layouts without needing backend info
 
User avatar
CornNieu
Topic Author
Posts: 11
Joined: 24 Oct 2022, 15:58
Location: Sweden, Falun
Contact:

Re: Get type of ObservableCollection from Basecomponent

26 Oct 2022, 08:52

"Finally after what feels like forever there is light at the end of the tunnel. It is however a lamp and not the exit"

We managed to make it work using the CPP rob function, which basically is a void function ptr to a member of a class you can specify. If you find another solution please do share, as more solutions means better results.

Thank you nonetheless for taking the time to help me.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Get type of ObservableCollection from Basecomponent

26 Oct 2022, 11:31

Want the correct T type to insert into a ObservableCollection, but don't know the T type.
If you don't know the right T then I guess the collection will be passed to you as a BaseComponent.
And the same happens for the item you want to add, if you don't know the exact type, it will be just boxed or a BaseComponent inherited class.

My suggestion then is to process everything through the base classes:
void AddItem(BaseComponent* collection, BaseComponent* item)
{
  BaseCollection* collection_ = (BaseCollection*)collection; // or use DynamicCast if you don't know for sure it is a BaseCollection
  collection_->AddComponent(item);
}
The specific ObservableCollection will check item type is compatible with T.

Who is online

Users browsing this forum: No registered users and 5 guests