views:

61

answers:

2

Is there any cost/drawback (apart from typing too much) to adorning a class with System.Runtime.Serialization attributes (like [DataContract]) such that it can be used locally as a direct reference to a desktop Client project or as a type for a WCF service? The goal here is to write a data-tier class that can be used in both rich client (WPF) and Web scenarios. My data classes will be in a project that is separate from Client and WCF (*.svc code-behind) code. Is this a valid attempt to reuse code?

+1  A: 

Adorning a class, property, or method does not incur any cost - except of the time it takes to write the attribute. The attribute will be complied into the metadata of the type, and then is used by another component to implement additional functionality.

Obalix
+1  A: 

The only drawback I can see is the cost of including attributes in the assembly. They have very little performance impact unless they are used.

I would say none but it does make the .DLL larger and does spread the RTTI in the assembly out a bit which, especially if you push a class over a read block boundary, could slow down assembly load (causing a couple extra blocks to be read that wouldn't have been otherwise). These differences are usually only noticable in cold start testing, however.

chuckj