Binding to .aar does not create the classes contained, only the interfaces - c#

I have a very basic java module that contains two interfaces (IOrder, IOrderItem) and two classes that implement those interfaces (Order, OrderItem).
After creating a xamarin binding library in VS2017 I only see the two interfaces.
Checking out the api.xml shows me that both classes are recognized and I even see their generated classes in the obj\Debug\generated\src folder of my project.
Why aren't these classes making it into my object explorer? What am I missing that links these generated files into the project itself?

Related

Generate boilerplate code based on classes in another project

I have a visual studio solution with a couple of C# projects. One of them contains my domain classes and has no infrastructure dependencies and another contains classes that depend on various 3rd party libraries, it's what you'd call an infrastructure project.
For each class in my domain project I have to write a corresponding class in my infrastructure project which contains just some boilerplate code required for using a feature of one of the 3rd party dependencies so I'd like to generate that automatically whenever my domain class is changed.
I was able to generate the classes containing this boilerplate code by creating a source generator with a ISyntaxReceiver that adds the abstract syntax tree of my domain classes for which I need to generate the boilerplate code to a list which is then used by my source generator to create the required classes. I then added this source generator as a project reference to my domain project but I have a problem: the infrastructure classes I need to generate inherit from a class of a 3rd party dependency so I have to add that 3rd party dependency to my domain project.
What I tried to do was to add my source generator as a project reference to my infrastructure project (which already references the 3rd party dependency, and also my domain project) but the source generator does not run because the ISyntaxReceiver's OnVisitSyntaxNode method does not get called for any of the classes in the referenced domain project.
Does anyone know if it's possible to create a source generator that generates code based on classes in projects referenced by the project that references that source generator?
I am aware of the AnalyzerAdditionalFiles, but seems like that should be used for making generation decisions based on more than just C# code

Iterate all app_code types in a .Net Website project C#

From a code behind (I know..) I'm trying to create a list of types that implement a specific interface. The types are within the website projects app_code folder.
Website projects dynamically compile into multiple assemblies, this means that for example Assembly.GetCurrentlyExecutingAssembly() and similar calls e.g.GetType().Assembly don't contain the types I'm looking for. Apart from the walnut with a sledgehammer approach of AppDomain.CurrentDomain.GetAssemblies() is there some way of iterating only the types defined within the website project?
Of course I could move all this functionality into a separate project where it behaves more predictably, but that is a refactor too far at the moment.
From a code-behind file, you should be able to execute the following line of code to enumerate only the types compiled from the classes under the app_code folder.
Assuming that IViusalizationManager is one of the classes under the app_code folder:
Type[] app_codeTypeList = typeof(IViusalizationManager).Assembly.GetTypes();

Only one project accessible where projects share a namespace

I have a solution which contains say, DataAccess and DataAccessImplementation
DataAccess contains: IFooAccess and other Interfaces
DataAccessImplementation contains: FooAccess which implements IFooAccess, along with lots of other classes that do the same.
Now, both of these projects are in the same Namespace.. 'foo.DataAccess'.
The problem I've got is, in my project that references these projects, only one of these two projects is going into the bin folder at a time when I build and only it's interfaces are available in my code. If I include a reference to DataAccess and DataAccessImplementation, only DataAccess will show for example.
DataAccessImplementation won't go in until I unreference DataAccess, but as soon as I reference it again, the only classes I can find are that of the DataAccess project.
Do these projects need to be in seperate namespaces? Why are the two projects not being added?
Usually no they don't have to be - but it isn't best practice to keep them in one namespace either. To be clear (for ourselves and other developers) we separate them according to their focus or intent. For instance:
com.yournamespace.DataAccess
and
com.yournamespace.DataModels
These will be two separate projects. In this example I've replaced your 'DataAccessImplementation' with DataModels because the distinction isn't clear.
The problem I was having wasn't actually due to the namespaces, it was instead the assembly name that was the same. After changing the names to those more appropriate, it worked fine.

Visual Studio Prevent Changes to Linked File

In Visual Studio you can add a link to a source file in another project. Is there a way to enforce preventing any changes from being performed on the linked source file (ie: link them into a project as 'read only', so as to prevent accidental modifications by folks who don't realize they are linked, and not local to the project)?
I have two projects, one of which is a DLL, the other is an EXE. The DLL contains a Windows ServiceInstaller and ServiceBase classes. I link these classes into my EXE (there are multiple flavors of the EXE) from the DLL in order for the EXE to be installable as a service and for me to not have to replicate the ServiceBase and ServiceInstaller in all of the EXEs. I do not however want to inadvertently be able to make changes to the linked classes from within the context of the EXE project.
Not via some Visual Studio-supported mechanism, no.
IMHO, as a general rule you should not be using a linked file like that. Yes, the feature exists in VS, but for the very reason you mention as well as others, it's a great way to create code maintenance headaches.
Note that your own scenario could be just as easily solved by exposing shared types in an assembly and referencing that assembly from those that need them. I.e. just reference the DLL from your EXE and use the types as compiled into the DLL rather than having the EXE define new versions of the types using the same source code.
Visual Studio does not have a way to set a "read-only" attribute for a linked file, but in general, linked files cause more problems than they solve.
Generally speaking, the preferred method for code reuse is to put the classes into a DLL and then reference those classes from the EXE - but in your case, the ServiceInstaller and ServiceBase classes have to be present in the EXE in order for the Windows service mechanism to pick them up.
Instead of linking the files, you could create base classes that inherit from ServiceInstaller and ServiceBase and put those in the DLL. Then add new classes into the EXE that inherit from your custom base class (which contains most of the logic). This way, all of the shared code gets pulled in from the shared DLL, but the EXE(s) still contain the classes necessary for the Windows service to start.

VS 2010: why sequence diagram has different design/style in two different projects?

I can't find any properties or whatsoever to specify how my shapes must look. And I get back two different results. This is from the modeling project I have:
And this one from the Class Library project:
Does the type of the project make it different??!

Categories

Resources