Share Assembly Definition?

Hi there,

Lets suppose a third party package has its own assembly definition and have a partial class named SomeClass.
Problem is if i add a partial class on my own code for SomeClass then unity treat it differently and reason is assembly definition.

So is there a way i can tell Unity that this my own partial class belongs to that SomeClass original assembly definition?

Please advise

Are you sure this is the reason? I would imagine a more likely reason is different namespace. Have you investigated what the namespaces are?

Disclaimer: I haven’t futzed with assembly definitions in Unity, so I cannot address that directly.

1 Like

I don’t really know what you mean by assembly definition, but partial classes cannot be used to extend classes outside the original assembly. Partial classes are stitched together during compilation of the assembly and cannot be used to modify a class after compiling. In terms of multiple assembly projects, this means partial classes are only useful within the same project.

If you have the source code for the third party package, you could add your partial class to the original project and recompile. Of course, you could also just add your code directly to their class.

1 Like

Yes, you are right and thats the reason im unable to make partial class work.

But at the same time, as Unity is using Assembly Definition files (with open source code) so i wanted to know if there is a way i could just explain to unity that i need my class to make it part of package assembly definition without puting my class in the package code (which is a maintainance hell)

Thanks

No, there is no way around that since assembly definition files work on folders. They essentially allow you to include seperate DLL projects inside your project. However what belongs together is defined by the folder your assembly definition file is in.

On that matter partial classes should be used sparely. They are just a way to split a single class over multiple files which generally doesn’t help reading or maintaining that code. I think this feature has been introduced with the VS form designer in mind so we could have an auto generated code and user code in seperate files so they don’t get in their way.

Like eisenpony said partial classes can only be used in the same assembly and not across multiple assemblies. So no, this is not possible without placing your partial class inside the same folder.

For example I used partial classes for my SimpleJSON parser because I have seperated out Unity specific extensions into a seperate extension file. They both still belong to the same framework. So a partial class should always be seen in this perspective. When you define another “part” of a partial class you do not derive the class, but you literally modify the original class. So there’s no difference between pulling a framework and just modifying it locally. The neat thing about partial classes is that you can keep your additions in a seperate file. Though that doesn’t change the fact that you actually modified the framework itself.

1 Like

Thank you for your detailed answer and you are right.

However in my case, i have a lot of different third party packages which are using these definititions, and i want to use their editor inspector and introduce few context menus to automate some stuff which is “easily” possible if i have partial classes support because directly adding code inside the folder means whenever there is an update, my code goes away.

For now i’m subclassing them but then their inspector works bit differently; a problem i wanted to avoid.