Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# inheritance issue

I'm using an API that has a "Member" class. I wish to extend this so i have create "MemberProfile" which inherits from "Member"

I have some issue creating the constructor for this class. I wish to something like the following

    var member = Member.GetCurrentMember();
    var memberProfile = new MemberProfile(member);

How would the constructor on MemberProfile look. Do i need to do some kind of cast?

like image 433
frosty Avatar asked Nov 21 '25 04:11

frosty


1 Answers

I suggest adding a Member field to the MemberProfile class and initialize it in the constructor. Don't inherit from Member.

public class MemberProfile {
    public Member Member { get; private set; }
    public MemberProfile(Member member) { Member = member; }
}

If you really want to inherit from Member, you'll have to copy all the properties off the passed argument to the new instance manually.

like image 63
mmx Avatar answered Nov 23 '25 20:11

mmx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!