Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/MsgPack.Mono/MsgPack.Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
Expand Down
1 change: 0 additions & 1 deletion src/MsgPack.Net35/MsgPack.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<Reference Include="System.Numerics, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Windows" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System.Numerics, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<DocumentationFile>..\..\bin\sl4-windowsphone71\MsgPack.Serialization.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
Expand Down
1 change: 0 additions & 1 deletion src/MsgPack/MsgPack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
Expand Down
22 changes: 14 additions & 8 deletions src/MsgPack/Serialization/DataMemberContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,31 @@ public DataMemberContract( MemberInfo member )
}

/// <summary>
/// Initializes a new instance of the <see cref="DataMemberContract"/> struct from <see cref="DataMemberAttribute"/>.
/// Initializes a new instance of the <see cref="DataMemberContract"/> struct.
/// </summary>
/// <param name="member">The target member.</param>
/// <param name="attribute">The data contract member attribute. This value can be <c>null</c>.</param>
public DataMemberContract( MemberInfo member, DataMemberAttribute attribute )
/// <param name="name">The name of member.</param>
/// <param name="nilImplication">The implication of the nil value for the member.</param>
/// <param name="id">The ID of the member. This value cannot be negative and must be unique in the type.</param>
public DataMemberContract( MemberInfo member, string name, NilImplication nilImplication, int? id )
{
Contract.Requires( member != null );
Contract.Requires( attribute != null );

this._name = String.IsNullOrEmpty( attribute.Name ) ? member.Name : attribute.Name;
this._nilImplication = Serialization.NilImplication.MemberDefault;
this._id = attribute.Order;
if ( id < 0 )
{
throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "The member ID cannot be negative. The member is '{0}' in the '{1}' type.", member.Name, member.DeclaringType ) );
}

this._name = String.IsNullOrEmpty( name ) ? member.Name : name;
this._nilImplication = nilImplication;
this._id = id ?? UnspecifiedId;
}

/// <summary>
/// Initializes a new instance of the <see cref="DataMemberContract"/> struct from <see cref="MessagePackMemberAttribute"/>.
/// </summary>
/// <param name="member">The target member.</param>
/// <param name="attribute">The MessagePack member attribute. This value can be <c>null</c>.</param>
/// <param name="attribute">The MessagePack member attribute.</param>
public DataMemberContract( MemberInfo member, MessagePackMemberAttribute attribute )
{
Contract.Requires( member != null );
Expand Down
31 changes: 23 additions & 8 deletions src/MsgPack/Serialization/SerializerBuilder`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,31 @@ private static IEnumerable<SerializingMember> GetTargetMembers()
);
}

if ( typeof( TObject ).IsDefined( typeof( DataContractAttribute ) ) )
if ( typeof( TObject ).GetCustomAttributes( false ).Any( attr => attr.GetType().FullName == "System.Runtime.Serialization.DataContractAttribute" ) )
{
return
members.Where( item => item.IsDefined( typeof( DataMemberAttribute ) ) )
.Select( member =>
new SerializingMember(
member,
new DataMemberContract( member, member.GetCustomAttribute<DataMemberAttribute>() )
)
return members.Select( item => new
{
member = item,
data = item.GetCustomAttributesData()
.FirstOrDefault( data => data.Constructor.DeclaringType.FullName == "System.Runtime.Serialization.DataMemberAttribute" )
})
.Where( item => item.data != null )
.Select( item =>
{
var name = item.data.NamedArguments
.Where( arg => arg.MemberInfo.Name == "Name" )
.Select( arg => (string) arg.TypedValue.Value )
.FirstOrDefault();
var id = item.data.NamedArguments
.Where( arg => arg.MemberInfo.Name == "Order" )
.Select( arg => (int?) arg.TypedValue.Value )
.FirstOrDefault();

return new SerializingMember(
item.member,
new DataMemberContract( item.member, name, NilImplication.MemberDefault, id )
);
});
}

#if SILVERLIGHT || NETFX_CORE
Expand Down