KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a method SaveChanges<T>(T object) that is frequently called throughout my code, except depending on the action calling the method, there would be a different method called from within SaveChanges. Something like this... protected void SaveChanges<T>(T mlaObject, SomeFunction(arg)) where T : WebObject { try { this._db.SaveChanges(); } catch (Exception e) { Console.WriteLine("Error: " + e); SomeFunction(arg); } } Usage Examples: SaveChanges<MlaArticle>(article, article.Authors.Remove(person)) //person is an object of type MlaPerson //OR SaveChanges<MlaArticle>(article, article.RelatedTags.Remove(tag)) //tag is an object of type Tag //OR SaveChanges<MlaArticle>(article, article.RelatedWebObjects.Remove(location)) //location is an object of type MlaLocation I've read up on delegate methods but I'm a little confused as to how to implement this with my requirements or if my requirements warrant use for delegates at all. EDIT: Also, would it be possible to pass multiple Actions?
Tags (comma-separated)
Save Edits
Cancel