Сделано сейчас.Я пометил свои Объекты, которые содержат Linqobject [Serializable]
и включил интерфейс ISerializable
.DBOItem
- это мой LinqObject
public void GetObjectData( SerializationInfo info, StreamingContext context )
{
PropertyInfo[] infos = this.DBOItem.GetType().GetProperties();
foreach ( PropertyInfo pi in infos )
{
bool isAssociation = false;
foreach ( object obj in pi.GetCustomAttributes( true ) )
{
if ( obj.GetType() == typeof( System.Data.Linq.Mapping.AssociationAttribute ) )
{ isAssociation = true; break; }
}
if ( !isAssociation )
{
if ( pi.GetValue( this.DBOItem, null ) != null )
{
info.AddValue( pi.Name, pi.GetValue( this.DBOItem, null ) );
}
}
}
}
Ctor, который необходимо включить для десериализации, выглядит следующим образом:
protected BusinessObjectBase( SerializationInfo info, StreamingContext context )
{
this.DBOItem = new T();
PropertyInfo[] properties = this.DBOItem.GetType().GetProperties();
SerializationInfoEnumerator enumerator = info.GetEnumerator();
while ( enumerator.MoveNext() )
{
SerializationEntry se = enumerator.Current;
foreach ( PropertyInfo pi in properties )
{
if ( pi.Name == se.Name )
{
pi.SetValue( this.DBOItem, info.GetValue( se.Name, pi.PropertyType ), null );
}
}
}
}