E
Ethan Strauss
Hi,
I have a class which "BiologySequence" which looks about like this.
public class BiologySequence
{
private string _Sequence;
public string Sequence
{
get
{
return _Sequence;
}
set
{
_Sequence = value;
}
}
public BiologySequence(string sequence)
{
if (sequence != null)
{
_Sequence = sequence;
}
else
{
_Sequence = string.Empty;
}
}
}
and an inherited class (NucleicAcidSequence) which has no other properties
important for this question.
I want to have the base class have a "Subsquence" method which is
essentially the same as the substring method of string. I have written
public BiologySequence Subsequence(int firstBase, int lastBase)
{
BiologySequence ToReturn = this.MemberwiseClone();
ToReturn.Sequence = _Sequence.Substring(firstBase, lastBase -
firstBase);
return (ToReturn);
}
which, I think works, but it always returns an object of type
BiologySequence regardless of what actual class it is called from.
I have tried all sorts of things to recast the object to be returned as the
same type as the calling type, but I can't find one which works.
Is there a way to do this, or do I need to explicitly write this method for
each inheriting class?
Thanks!
Ethan
Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
I have a class which "BiologySequence" which looks about like this.
public class BiologySequence
{
private string _Sequence;
public string Sequence
{
get
{
return _Sequence;
}
set
{
_Sequence = value;
}
}
public BiologySequence(string sequence)
{
if (sequence != null)
{
_Sequence = sequence;
}
else
{
_Sequence = string.Empty;
}
}
}
and an inherited class (NucleicAcidSequence) which has no other properties
important for this question.
I want to have the base class have a "Subsquence" method which is
essentially the same as the substring method of string. I have written
public BiologySequence Subsequence(int firstBase, int lastBase)
{
BiologySequence ToReturn = this.MemberwiseClone();
ToReturn.Sequence = _Sequence.Substring(firstBase, lastBase -
firstBase);
return (ToReturn);
}
which, I think works, but it always returns an object of type
BiologySequence regardless of what actual class it is called from.
I have tried all sorts of things to recast the object to be returned as the
same type as the calling type, but I can't find one which works.
Is there a way to do this, or do I need to explicitly write this method for
each inheriting class?
Thanks!
Ethan
Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)