Page 1 of 1
Get type of ObservableCollection from Basecomponent
Posted: 24 Oct 2022, 16:07
by CornNieu
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.
Re: Get type of ObservableCollection from Basecomponent
Posted: 24 Oct 2022, 16:45
by jsantos
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?
Re: Get type of ObservableCollection from Basecomponent
Posted: 25 Oct 2022, 07:54
by CornNieu
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
Re: Get type of ObservableCollection from Basecomponent
Posted: 26 Oct 2022, 08:52
by CornNieu
"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.
Re: Get type of ObservableCollection from Basecomponent
Posted: 26 Oct 2022, 11:31
by sfernandez
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.