DataMemberAttribute Class
This page is specific to:Microsoft Version:3.03.5Silverlight 34.0
.NET Framework Class Library for Silverlight
DataMemberAttribute Class

When applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer.

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

'Usage

Dim instance As DataMemberAttribute

'Declaration

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, Inherited := False,  _
    AllowMultiple := False)> _
Public NotInheritable Class DataMemberAttribute _
    Inherits Attribute
Remarks

Apply the DataMemberAttribute attribute in conjunction with the DataContractAttribute to identify members of a type that are part of a data contract. One of the serializers that can serialize data contracts is the DataContractSerializer.

The data contract model for Silverlight version 3 is an opt-out model. This means that the members are serialized by default unless the IgnoreDataMemberAttribute is applied to a field or property explicitly to specify that the member value is not to be serialized.

By default, the CLR member name is used as the name of the data member. By setting the Name property, you can customize the name of the data member. This can be used to provide a name that may not be allowed as a CLR member name. When mapping to XML using the DataContractSerializer, this name is used as the name of the schema element in a type.

Examples

        ' Define the data contract.
        <DataContract(Name := "Customer", Namespace := "http://www.contoso.com")> _
        Public Class User
            Private privateName As String
            <DataMember(Name := "Last", EmitDefaultValue := True, IsRequired := True, Order := 2)> _
            Public Property Name() As String
                Get
                    Return privateName
                End Get
                Set(ByVal value As String)
                    privateName = value
                End Set
            End Property

            Private privateAge As Integer
            <DataMember(Order := 1)> _
            Public Property Age() As Integer
                Get
                    Return privateAge
                End Get
                Set(ByVal value As Integer)
                    privateAge = value
                End Set
            End Property

            Public Sub New()
            End Sub

            Public Sub New(ByVal newName As String, ByVal newAge As Integer)
                    Name = newName
                    Age = newAge
            End Sub
        End Class


Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Runtime.Serialization..::.DataMemberAttribute
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

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View