tags:

views:

65

answers:

6

I have a method Modify which doing a operation ClientModify inside.

public bool Modify()
{
  bool retval = false;

  retval = Spa.ClientModify(col);    
}

Here what i wanted is the ClientModify should perform only after three events completed in the eventhandler "ServerEvents" otherwise it should return(retval ) false .How can i do that checks on "Spa.ClientModify"

  static private void ServerEvents(eventType type, event this_event, object passback)
    {
             if (this_event.type == eventType.SPD_spurtEvent)
            { 

           if (this_event.objectName == "ready")
            {                  
           // some operation 
            }
           else if (this_event.objectName == "info")
            {
           // some operation
            }

           else if (this_event.objectName == "serverstate")
            {
           // some operation
            }

        }

}

So what i did is

 public class Server : ModelObject, IServer
    {
   public class MyState
{
    public bool Method1HasExecuted { get; set; }
    public bool Method2HasExecuted { get; set; }
    public bool Method3HasExecuted { get; set; }
}
   }

        static private void ServerEvents(eventType type, event this_event, object passback)
        {
          MyState s = new MyState();

each three operation i did  check like this  s.Method1HasExecuted = true; like this 
}

and modify method i did this way
    public bool Modify()
    {
        return MyClassState.Method1HasExecuted && MyClassState.Method2HasExecuted && MyClassState.Method3HasExecuted ? Spa.ClientModify() : false;
    }

}

Then i am getting error Spo.Plugins.Server.MyState.Method1HasExecuted.get' must declare a body because it is not marked abstract or extern,,IS there any other way

+1  A: 
public bool Method1HasExecuted { get; set; }

The get/set methods of this property aren't implemented, so that is why the compiler is complaining. Implement both the setter and getter of the property to get rid of the error.

Matias Valdenegro
means i didnt get you
peter
Those are just Automatic Properties. The compiler adds the backing field automagically.
AllenG
Since the error specifically mentions "Spo.Plugins.Server.MyState.Method1HasExecuted.get must declare a body" I think that Matias is right. My guess would be that Peter has copied some post 3.0 .NET code and is trying to compile it against a 2.0 msbuild.
Martin Harris
i am using 2.0 here
peter
A: 

Typically, the error you reference in your title comes up when you have a method defined as anything other than abstract or extern but you don't have a body. Possibly something like one of the following:

public virtual void DoStuff();
public int GetANumber();
public string ReturnAString();

None of those will compile. My guess, based on what you've provided, is that you have some method (possibly ClientModify since I don't see it's definition in your posted code) which is defined with a name and signature, but no body.

If this is not the case, please specify the method to which the compiler error is referring (you can get this by double-clikcing on the error in VS, if it doesn't specify in the error message) and post its code and a sample of the code which refers to it.

AllenG
A: 

You haven't posted your IServer interface, however, the error is likely because you haven't implemented all the methods or properties on your interface IServer in class Server

If you are using .NET 3.5 or later the public bool Method1HasExecuted { get; set; } will be an automatic property

I'm not sure that I understand your question completely, but you need to hook into 3 unrelated method calls so that you can flag the corresponding booleans in your statemanagement class?

nonnb
+3  A: 

public bool Method1HasExecuted { get; set; } is an Auto-implemented property, which is available from C#3.0 onwards.

Are you using C#2.0? Then you will have to write out that property:

private bool _method1HasExecuted;
public bool Method1HasExecuted 
{
  get { return _method1HasExecuted; }
  set { _method1HasExecuted = value; }
}
Hans Kesting
yes i am using 2.0
peter
@peter: extended my answer
Hans Kesting
A: 

How are you compiling this. The code public bool Method1HasExecuted { get; set; } is valid C#3 (auto-implemented properties) but not valid C#2 (doesn't have auto-implemented properties). To C#2 it looks like you wrote an abstract or extern property but didn't mark it as such. Check you're compiling with the 3.5 Framework.

Jon Hanna
A: 

You're using .net 2.0 so you can't use the autoimplemented properties. You need to change the MyState class to be like this:

public class MyState 
{ 
    private bool _method1HasExecuted;
    private bool _method2HasExecuted;
    private bool _method3HasExecuted;

    public bool Method1HasExecuted
    {
        get
        {
            return _method1HasExecuted;
        }
        set
        {
            _method1HasExecuted = value;
        }
    }

    public bool Method2HasExecuted
    {
        get
        {
            return _method2HasExecuted;
        }
        set
        {
            _method2HasExecuted = value;
        }
    }
    public bool Method3HasExecuted
    {
        get
        {
            return _method3HasExecuted;
        }
        set
        {
            _method3HasExecuted = value;
        }
    }
} 
Jimmy Hoffa