M
M
Michael2022-03-24 16:14:42
Python
Michael, 2022-03-24 16:14:42

How to call a class from another C# project?

Hello!
I have a project (Test), I created several more projects inside one solution (TestA, TestB)
TestA, TestB are WPF application modules with an interface (UserControl) and a viewmodel for them.
I want to call the VM from the TestA module in the main Test application and load the usercontrol in Test, but
when I initialize the viewmodel from the TestA module (CurrentVM = new TestAVM()) in the call method,
I get an error.
TestAVM is not available due to its security level.
If you open the TestAVM class and add the public modifier, the error disappears, but then such problems begin inside the module, as a result, almost all classes inside the module have to be made public.
How to implement it correctly? I know that you can use prism and so on, but I want to try to figure it out myself.

The project structure is
--Test
----Models
----View
----ViewModels
--TestA
----Models
----View
----ViewModels
--TestB
----Models
--- -View
----ViewModels

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-07-04
@sim3x

stackoverflow.com/questions/4871369/python-error-a...
mikegrouchy.com/blog/2012/05/be-pythonic-__init__p...
https://docs.python.org/3/tutorial/modules. html
__init__.py

More accurately, your EasyTables directories are not modules, they are packages. The file easyTables.py is a module.
Python does not automatically import subpackages or modules. You have to explicitly do it, or "cheat" by adding import statements in the initializers.

V
Vasily Bannikov, 2022-03-24
@vabka

TestAVM is not available due to its security level.

Declare it as public. Most likely it is declared as internal
, but then such problems begin inside the module, as a result, almost all classes inside the module have to be made public.

As an alternative - you can do InternalsVisibleTo
https://docs.microsoft.com/en-us/dotnet/api/system...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question