Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serializable partial classes

I have the following VB.NET class definition:

<Serializable()> Partial Public Class Customers
End Class

Inside another file I have the same thing (with different methods and variables of course). When I compile, I get the following error:

Attribute 'SerializableAttribute' cannot be applied multiple times.

The error is pretty self explanatory. My question is though, if I just mark the one class as Serializable(), can I assume the entire class with be marked as serializable()? In other words, Do I only need the serializable() tag in 1 spot in the class?

like image 781
Icemanind Avatar asked May 29 '09 21:05

Icemanind


People also ask

What are partial classes?

Partial classes help split the methods into two or more source(. cs) files. All the partial classes will be combined when the whole program is compiled. Partial Class is a unique feature of C#. It can break the functionality of a single class into many files.

Can we have partial classes in Javascript?

partial classes can work by convention. For example consider this convention. // file main function SomeObject() { for (var i = 0, ii = SomeObject. Partial.

Can partial classes have constructors?

You can have multiple constructors in a class defined with partial, but each constructor must be unique (even if they're in different files).

What is the point of a partial class?

Partial classes are portions of a class that the compiler can combine to form a complete class. Although you could define two or more partial classes within the same file, the general purpose of a partial class is to allow the splitting of a class definition across multiple files.


2 Answers

You only need it marked once per class so in a class with more than one 'partial' definitation, you should just remove it from all the other files. The whole 'partial' thing is just a way of visualizing your code so when you apply it once, it will be for the whole class.

like image 55
JasonRShaver Avatar answered Dec 01 '22 10:12

JasonRShaver


Yes, you only need to put it in one of the Partial Classes:
http://msdn.microsoft.com/en-us/library/wa80x488.aspx

At compile time, attributes of partial-type definitions are merged.

like image 42
Badaro Avatar answered Dec 01 '22 11:12

Badaro