Connecting Tech Pros Worldwide Forums | Help | Site Map

Class Inheritance and Overriding Methods

Newbie
 
Join Date: Jul 2009
Posts: 4
#1: Jul 3 '09
Hello,

I am currently using Linq To Sql classes in my project, and I am implementing validation, but I am having a problem trying to create a generic validation class that I can use with the Linq To Sql classes.

Specifically, I have a class named Contact - that has been generated automatically by Linq To Sql. So I can't change anything in it. But as it is a partial class I created another partial Contact that I want to perform validation in.

In my partial Contact class I want to provide a partial method called OnValidate where it will do validation specific to the Contact class object. (I have this working so far)

But in an effort to make my system more generic I would like my partial Contact class to inherit from a generic validation class, where it provides the base OnValidate method, and my partial Contact class overrides it, should specific validation be required.

The problem I am having is I am not sure what access modifier I need to create on the class and methods of my validation class for this scenario to work.

Below is the general structure, I hope someone can see what I need to fix:

Expand|Select|Wrap|Line Numbers
  1. public partial class Contact : INotifyPropertyChanging, INotifyPropertyChanged
  2. {
  3.     partial void OnValidate(System.Data.Linq.ChangeAction action);
  4. }
  5.  
  6. public partial class Contact : Validation
  7. {
  8.     // ???? Some sort of override of the validation class?
  9.     partial void OnValidate(System.Data.Linq.ChangeAction action)
  10.     {
  11.         // Class specific validation
  12.     }
  13. }
  14.  
  15. ????? class Validation
  16. {
  17.     ?????    OnValidate(System.Data.Linq.ChangeAction action)
  18.     {
  19.         // General validation
  20.     }        
  21. }
  22.  
Any guidance is greatly appreciated

Cheers,
Scott

Newbie
 
Join Date: Jul 2009
Posts: 4
#2: Jul 4 '09

re: Class Inheritance and Overriding Methods


Its ok I found a pretty painless solution in the end. Not as neat as I wanted it, but still sufficient.
Reply

Tags
classes, csharp, inheritance, overriding, partial