Page 1 of 1

Can i check if component is already registered at runtime ?

Posted: 12 May 2025, 08:27
by IdanB-Forsight
I have several components that use some custom control.
In every one of them i have on the CTOR a
RegisterComponent of the UserControl type it's depends on.

However if i have common control, it floods my logs with something like:
[NOESIS/E] /OverlayXaml_MessagesScreen;component/AssistantScreen.xaml(48,9): Component 'FSCommonUIControls.NS_SliderButtonUserControl.cSlideButtonUserControlView ()' already registered
I'm in the process of cleaning up the log of any "false-positive" entries it may have.
I can i check at runtime whether I need to registerComponent or not ?
or prevent log entry in the case it's already registered...

Re: Can i check if component is already registered at runtime ?

Posted: 12 May 2025, 11:03
by sfernandez
You can use Noesis::Factory::IsComponentRegistered(...) for checking if a component is already registered.

Is it not possible for you to have a single function at application start where you register all your components?

Re: Can i check if component is already registered at runtime ?

Posted: 13 May 2025, 10:04
by IdanB-Forsight
sadly i have different componenet that may (or mat not) be present,
and since each is idependent, i cannot perform it on begining.

Noesis::Factory::IsComponentRegistered isn't template.
How do i get from class name a Noesis::Symbol type ?

Do i have function for it ?

Re: Can i check if component is already registered at runtime ?

Posted: 13 May 2025, 11:51
by jsantos
If you have the Type, you can use GetTypeId().

If you only have a string, Symbol provides an explicit constructor that accepts a string:
class Symbol
{
public:
    Symbol();
    explicit Symbol(const char* str);

Re: Can i check if component is already registered at runtime ?

Posted: 13 May 2025, 14:13
by IdanB-Forsight
I have the C++ type.
How do I get from it the Noesis Type class wrapper ?

Re: Can i check if component is already registered at runtime ?

Posted: 13 May 2025, 18:35
by jsantos
If you have the type you can do:
const Type* type = TypeOf<Button>();
Symbol id = type->GetTypeId();
If you have the instance you can do:
Button* button;
const Type* type = button->GetClassType();
Symbol id = type->GetTypeId();