tags:

views:

183

answers:

5

I need to inherit from a base class, one method of which has a constructor with 8 arguments.

I won't ever need all 8 arguments, I only need one. However, I do need to implement that method.

public MyClass : BaseClass
{    
    public class MyClass(string myArg):base(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
    {
         // do stuff
    }
}

results in an epic fail compiler message where args2-8 are hard-coded. Any hints?

Clarification: Arguments are all properties of the base class which are set via with this initialization.

As the base class is a framework class, I'm not in a position to amend its properties or constructor.

Hopefully the final edit for those who want to know what the arguments are (and no, the opening brace is not an issue, thanks anyway) here's the VB.NET code I'm trying to port as part of a Custom Membership Provider.

Sadly, finding an en example of C# membership provider was not possible.

Public Sub New(ByVal userName As String)
            MyBase.New("Shiningstar.SSSMembershipProvider", userName, _
            userName.GetHashCode, userName, "", "", False, False, Today, _
            Today, Today, Today, Today)

            Me.m_UserName = userName ' UserName() is read only
End Sub

The base class in this case is System.Web.Security.MembershipUser

+3  A: 

I've never heard of method constructors, so I assume you mean a normal constructor. You should be able to hard code some of the parameters in. Here is a small code example that compiles without error:

public class MyBaseClass
    {
        public MyBaseClass ( int arg2, string arg1,string ar3)
        { }
    }

    public class MyClass : MyBaseClass
    {
        public MyClass (int argument) : base (argument, "not supplied", "hard-coded") 
        { }

    }

I hope this answers your question.

Edit (some stumble-stones:)


Are you sure you have the right access modifiers (protected, internal, private, public, protected internal) ?

wsd
+1  A: 

Wild guess here. Is the problem that you're missing the class keyword in your class declaration?

public class MyClass : BaseClass
{
    public MyClass(string myArg):base(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
    {
         // do stuff
    }
}

And depending on what you do in "do stuff", you might be throwing away your myArg... but that's probably not your problem.

Blair Conrad
I think if I didn't know enough to declare a class as a class, I'd probably have bigger problems than inheritance.Could you simply assume a typo on the sample which does not exist in the code - or the error would be popping up somewhere entirely different. No?
Really, it's not clear what your problem is. I mentioned that it was a wild guess, but since you hadn't supplied the error message when I wrote the comment (and maybe I'm blind, but I still don't see it), I thought I'd use some of my time to try to help out what could have been a novice programmer who made a basic mistake. I hope someone else is able to help you with your problem, as I don't know how to, with the information you've provided. Good luck.
Blair Conrad
A: 

Without the exact error message, I cannot be sure, but I suspect that your arg1 .. arg8 are instance fields of the class, which cannot be used before the base constructor.

If you make them static fields, that problem would be solved.

SLaks
arg1-8 are base class properties, yes.The base class is not modifiable, sadly.
It is not possible to do this - you cannot use the base classs until after it has been constructed.
SLaks
Which properties are you trying to use?None of the parameters in the VB example you gave are properties of the base class.
SLaks
+1  A: 

Can you give us some more context on what arg2-arg8 are?

There are restrictions on the type of values that can be passed into the base class constructor. For instance you cannot pass instance fields or properties. Constants, constructor arguments and literals should be just fine though.

JaredPar
you should now have all the context you want.
+1  A: 

If you want to use properties of the base or current class as arguments to a constructor, those properties need to be static. I am guessing the error you are getting is something about the "this reference is not initialized" or similar. The same is true of any methods that would return a value to then use as an argument.

Kleinux