EDIT: I apologize, I meant protected
instead of restricted
. I was tired.
Is there an equivalent to Java's restricted
and extends
in C#? I can see that neither are in C#, and they would be useful for a current programming project.
Code:
using System;
namespace CServer.API
{
public class Plugin
{
restricted Plugin ()
{
}
}
}
and say a plugin did this:
using System;
using CServer.API;
namespace Whatever
{
public class WhateverPlugin extends Plugin
{
}
}
I want to have a custom constructor that executes some code before the plugin's constructor.
It sounds like you probably want:
using System;
namespace CServer.API
{
public class Plugin
{
protected Plugin()
{
// This code will execute before the body of the constructor
// in WhateverPlugin
}
}
}
and
using System;
using CServer.API;
namespace Whatever
{
// : is broadly equivalent to both implements and extends
public class WhateverPlugin : Plugin
{
public WhateverPlugin() // implicitly calls base constructor
{
// This will execute after the Plugin constructor body
}
}
}
Note that restricted
isn't a keyword in Java; I'm assuming you actually mean protected
.
See more on this question at Stackoverflow