I like the tight coupling between LinqToSql data context objects and the underlying SQL database, however I’m curious how obfuscation fits into the picture.
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FamilyId", IsPrimaryKey=true, IsDbGenerated=true)]
public int FamilyId
{
get
{
return this._FamilyId;
}
set
{
if ((this._FamilyId != value))
{
this.OnFamilyIdChanging(value);
this.SendPropertyChanging();
this._FamilyId = value;
this.SendPropertyChanged("FamilyId");
this.OnFamilyIdChanged();
}
}
}
In the data context, the property autogenerated setter for my objects in this case hard codes the PropertyName eg. “FamilyId” string in the SendPropertyChanging method call. Changes in this code will be replaced next time the file is regenerated, so I can’t use reflection helpers to get the property names.
Clearly once obfuscation has occured this property will be call something entirely different. This appears to prevent the notification event from reaching WPF applications UI eventhandlers.
So I thought, let’s try wrap those autogenerated data objects up, adapter pattern style. At least the wrappers will be obfuscated. So as per stackoverflow hardcode vs reflection
private Family _family;
public int FamilyId
{
get { return _family.FamilyId; }
set
{
NotifyPropertyChanging(() => FamilyId);
_family.FamilyId= value;
NotifyPropertyChanged(() => FamilyId);
}
}
Which seems okay until I try and deal with collections. EntitySet collections are more complex as each element in the collection needs to cast to the wrap type. Additionally complexity starts growing when we start talking lazy loading, transactions and the fact we are not performing the Business Layer Logic on real types but wraps types.
So my gut feel is that this is getting way to complex.
Does anybody else use WPF, LinqToSql data classes and obfuscation that can shed some light on a more correct architecture?
Which obfuscation tool are you using that helps support this process?
Looking back on what you have learnt from your attempts, can you recommend whether you would go throught the same process again? Would you attempt another way.
My preference is of course to have everything obfuscated completely, not stick with half baked wrapping with high overheads if it gives me very little protection.
“My preference is of course to have everything obfuscated completely, not stick with half baked wrapping with high overheads if it gives me very little protection.”
Are you sure you need obfuscation in this area of your solution? What are you actually trying ‘to protect’?
In my experience, the benefit comes from obfuscating custom UI code and business logic classes. (that a competitor could possibly copy and leverage).
There isn’t a great deal of benefit in obfuscating auto-generated service code. You don’t really have much IP there to protect…
The tool you are using should allow you to define which classes you want to obfuscate and which ones you don’t. I wouldn’t describe this approach as ‘half baked’