.NET Framework Class Library
ContractNamespaceAttribute Class

Specifies the CLR namespace and XML namespace of the data contract.

Namespace:  System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)
Syntax

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Module, Inherited := False,  _
    AllowMultiple := True)> _
Public NotInheritable Class ContractNamespaceAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As ContractNamespaceAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Module, Inherited = false, 
    AllowMultiple = true)]
public sealed class ContractNamespaceAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Module, Inherited = false, 
    AllowMultiple = true)]
public ref class ContractNamespaceAttribute sealed : public Attribute
JScript
public final class ContractNamespaceAttribute extends Attribute
Remarks

Apply the ContractNamespaceAttribute attribute to an assembly that contains types to which the DataContractAttribute has been applied. The ContractNamespaceAttribute enables you to set a namespace that is different than the one generated when the type is serialized. For more information about how names are generated, see Data Contract Names.

If you are using a type to conform to an existing data contract, you must match the namespace of the existing contract by using the ContractNamespaceAttribute (or the Namespace property of the DataContractAttribute class).

NoteNote:

In any code, you can use the word ContractNamespace instead of the longer ContractNamespaceAttribute.

Examples

The following example shows the ContractNamespaceAttribute applied to an assembly.

Visual Basic
<assembly: ContractNamespaceAttribute("http://www.cohowinery.com/employees", _
   ClrNamespace := "Microsoft.Contracts.Examples")>

Namespace Microsoft.Contracts.Examples
    <DataContract()>  _
    Public Class Person
        <DataMember()>  _
        Friend FirstName As String
        <DataMember()>  _
        Friend LastName As String
    End Class 
End Namespace 
C#
[assembly: ContractNamespaceAttribute("http://www.cohowinery.com/employees",
    ClrNamespace = "Microsoft.Contracts.Examples")]
namespace Microsoft.Contracts.Examples
{
    [DataContract]
    public class Person
    {
        [DataMember]
        internal string FirstName;
        [DataMember]
        internal string LastName;
    }
}
Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Runtime.Serialization..::.ContractNamespaceAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker