My Code
partial class User
{
[OnSerializing]
public void ClearPassword()
{
Password = null;
}
}
Linq-to-SQL
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[User]")]
[global::System.Runtime.Serialization.DataContractAttribute()]
public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
{
[global::System.Runtime.Serialization.OnSerializingAttribute()]
[global::System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
public void OnSerializing(StreamingContext context)
{
this.serializing = true;
}
}
Result
Invalid attribute. Both 'Void ClearPassword()' and 'Void OnSerializing(System.Runtime.Serialization.StreamingContext)' in type 'AuthenticationManager.User' have 'System.Runtime.Serialization.OnSerializingAttribute'.
Now, did the engineers at Microsoft create a way for two separate blocks of code to fire some events on serialization independent of one another? Especially considering the fact that they hijack this event to set this.serializing = true
?
Thanks in advance.
If your
Password
property is using a backing field, you can set it toNonSerialized