Inheriting and Extending internal class

P

Paul Say

This is the situation I have a base class _Job that has an internal class PropertyNames (see code )

public abstract class _JobBase
{
private int _JobId;
private int _JobName;

public virtual int JobId
{
get{return this._JobId;}
set{this._JobId = value;}
}

public virtual string JobName
{
get{return this._JobName;}
set{this._JobName = value;}
}

public class PropertyNames{
public const string JobId = "JobId";
public const string JobName= "JobName";
}

}

When inheriting from _Job if I want to extend the PropertyNames inner class I am doing the following

public class Job:_JobBase
{
public string JobNameExtended
{
get{return this.JobId.ToString() & " - " & this.JobName;}
}


public new class PropertyNames:_JobBase.PropertyNames
{
public const string JobNameExtended = "JobNameExtended";
}
}

What I want to know is if this is the correct way of extending an inner class as this works, or if there is a better way.

Paul
 
C

Carl Daniel [VC++ MVP]

That works just fine.

Using a class as a container for a static list of names seems a bit dodgy - with all members static (const is static), there's no point in ever creating an instance of this class, in which case there's also no point in deriving from the class. Of course, if there's more to the PropertyNames class than you're showing then the use of inheritance (or even of a class) might be justified.

-cd
This is the situation I have a base class _Job that has an internal class PropertyNames (see code )

public abstract class _JobBase
{
private int _JobId;
private int _JobName;

public virtual int JobId
{
get{return this._JobId;}
set{this._JobId = value;}
}

public virtual string JobName
{
get{return this._JobName;}
set{this._JobName = value;}
}

public class PropertyNames{
public const string JobId = "JobId";
public const string JobName= "JobName";
}

}

When inheriting from _Job if I want to extend the PropertyNames inner class I am doing the following

public class Job:_JobBase
{
public string JobNameExtended
{
get{return this.JobId.ToString() & " - " & this.JobName;}
}


public new class PropertyNames:_JobBase.PropertyNames
{
public const string JobNameExtended = "JobNameExtended";
}
}

What I want to know is if this is the correct way of extending an inner class as this works, or if there is a better way.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top