I have tow classes Class1 and Program a shown below:
class Class1
{
public void xx()
{
}
}
class Program : Class1
{
static void Main(string[] args)
{
}
}
But when i see the method table i not see the inherited public functions in Program class.
Why this is happened?I think inherited methods should be present in method table program class.
Related
I have to write a report where I create and implement the Data Type (Set) using java.
I have to write pseudocode for it an include it in my report.
How do I write a class and call it from another pseudocode program.
say I have the Set class:
public class Set() {
public Set() {
//constructor
basicMethod();
}
public void basicMethod() {
//do something
}
}
and my driver class:
public class Driver {
public static void main(String[] args) {
Set s = new Set();
}
}
How would I write this as pseudocode?
How would instantiate a new object inside of another class?
how would i encompass the class entirely? To define a class in pseudocode would i just say:
Set {
// pseudocode in here
}
also, how would I write a constructor in pseudocode?
I have a method ResetMethod(ClassA a) in a class and I have accessed this method by property of ResetMethod's class like this:
public class MyClass1
{
public MyClass1()
{
}
public void ResetMethod(ClassA a)
{
}
}
public class MyClass2
{
MyClass1 class1;
public MyClass2()
{
ClassA a= new ClassA();
MyClass1.ResetMethod(a);
}
public MyClass1 MyClass1
{
get
{
if (myClass1 == null)
myClass1 = new MyClass1 ();
return myClass1 ;
}
set
{
myClass1 = value;
}
}
}
While running FxCop rules, for method ResetMethod, it shows this error:
The 'this' parameter (or 'Me' in Visual Basic) of 'MyClass1.ResetMethod(MyClassA)' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate.
How do I resolve this error?
You invocation of MyClass1.ResetMethod(a); is already calling a static method. So the code you posted does not compile to my understanding.
So all that's left to the do is to make the method itself static:
public static void ResetMethod(ClassA a)
{
// ...
}
I have a class like this
#Component
public class TestClass {
public void testMethod(){
FinalClass f = new FinalClass("string");
somePrivateMethod(f.getSomeString());
}
private void somePrivateMethod(String s){
}
}
As you can see it has a public method and private method. In public method it is instantiating an instance of FinalClass, which is a class in some third party library and it is final. Lets say it is like this
public final class FinalClass {
private final String someString;
public FinalClass(final String s) {
someString = s;
}
public String getSomeString() {
return someString;
}
}
And Now I am writing unit test for my test class. Since I have to verify final classes and private methods, I am using powermockito. And this is how my test class looks like
#RunWith(PowerMockRunner.class)
#PrepareForTest({TestClass.class, FinalClass.class})
public class TestClassTest {
private TestClass testClass;
private FinalClass finalClass;
#Before
public void setUp() {
finalClass = PowerMockito.mock(FinalClass.class);
testClass = spy(new TestClass());
}
#Test
public void testSomething() throws Exception {
whenNew(FinalClass.class).withAnyArguments().thenReturn(finalClass);
testClass.testMethod();
verifyNew(FinalClass.class);
//verifyPrivate(testClass).invoke("testMethod");
}
}
It works fine. But the problem is the last two statements verifyNew and verifyPrivate are working mutually exclusively. I mean when I comment one of those(doesn't matter which), the test passes. But when both are enabled, the test fails
Does anyone have any idea why this is happening?
public interface IFoo {}
public class Foo : IFoo {}
public sealed class NinjaModule : NinjectModule //Appropriately configured in project
{
public override void Load()
{
Bind<IFoo>.To<Foo>.InTransientScope();
}
}
public class SomeOtherClass : ISomeOtherInterface
{
public SomeOtherClass();
public IFoo GetFoo(IFoo foo)
{
return foo;
}
public void GetFoos()
{
foreach (var thing in everything)
{
var localFoo = GetFoo();
localFoo.UniqueProperty = "I am unique";
_fooList.Add(localFoo);
}
}
}
I need my code to look something like that.
Yes, I am fairly new to inject. I am fairly certain that I am missing a basic principle.
Thanks for any help.
I think the best approach here would be to use a factory to create the different Foo instances. And with Ninject and the Factory extension that's pretty easy.
public sealed class NinjaModule : NinjectModule //Appropriately configured in project
{
public override void Load()
{
Bind<IFoo>().To<Foo>().InTransientScope();
Bind<IFooFactory>().ToFactory();
}
}
public interface IFooFactory
{
IFoo CreateFoo();
}
public class SomeOtherClass : ISomeOtherInterface
{
private IFooFactory fooFactory;
public SomeOtherClass(IFooFactory fooFactory)
{
this.fooFactory = fooFactory;
}
public IFoo GetFoo(IFoo foo)
{
return this.fooFactory.CreateFoo();
}
public void GetFoos()
{
foreach (var thing in everything)
{
var localFoo = GetFoo();
localFoo.UniqueProperty = "I am unique";
_fooList.Add(localFoo);
}
}
}
This was a bad question. I figured out this needed to be implemented higher up by the class controlling these implementations.
i have a class and want to create,delete and edit sessions on it
but have error:"object null reference" when i want to add data to my session.
if i remove inheritance from controller how can i handle it?
my data is string value like "name"
why this syntax: Session[name]=value; works fine in controller but not works in my class and give me null reference error?
public class StateManager : Controller
{
public void RemoveFromApplication(string name)
{
Session.Remove(name);
}
public void AddToApplication(string name, object value)
{
//value like "name"
Session[name]=value;
}
}
It probably doesn't work because the controller isn't instantiated the same way by MVC, when it doesn't matches the current route.
You could instead create a static class like this:
public static class SessionManager
{
public static void RemoveFromApplication(string name)
{
HttpContext.Current.Session.Remove(name);
}
public static void AddToApplication(string name, object value)
{
HttpContext.Current.Session[name] = value;
}
}
You could also pass the session in the the methods as a parameter:
public static class SessionManager
{
public static void RemoveFromApplication(string name, HttpSessionStateBase session)
{
session.Remove(name);
}
public static void AddToApplication(string name, object value, HttpSessionStateBase session)
{
session[name] = value;
}
}
The class and methods doesn't need to be static, if you don't want it to be.