0

嗨,这是我的基类

public abstract class IEnvelopeFactory {

        public Queue<IEnvelopeFactory> m_Queue;
        //public Queue<IEnvelopeFactory> m_Queue<IEnvelopeFactory>;

        public IEnvelopeFactory(){

        }

        ~IEnvelopeFactory(){

        }

        public virtual void Dispose(){

        }

        /// <summary>
        /// Parsing
        /// </summary>
        /// <param name="input"></param>
        /// <param name="envelope"></param>
        public abstract bool Parse(string input, out Envelope envelope);

        /// <summary>
        /// Formatting
        /// </summary>
        /// <param name="env"></param>
        /// <param name="envStr"></param>
        public abstract bool Format(Envelope env, out string envStr);

    }

子类如下

public class XMLTYPE4Factory : IEnvelopeFactory
    {

        public XMLTYPE4 m_XMLTYPE4;

        public XMLTYPE4Factory()
        {

        }

        ~XMLTYPE4Factory()
        {

        }

        public override void Dispose()
        {

        }

        /// <summary>
        /// Parsing
        /// </summary>
        /// <param name="input"></param>
        public override Envelope Parse(string input)
        {

            return null;
        }

        /// <summary>
        /// Formatting
        /// </summary>
        /// <param name="env"></param>
        public override string Format(Envelope env)
        {

            return "";
        }

    }

我收到以下错误

'XMLTYPE4Factory' does not implement inherited abstract member 
'IEnvelopeFactory.Format(CCN.MSG.ENV.Envelope, out string)' 


'XMLTYPE4Factory' does not implement inherited abstract member 
'IEnvelopeFactory.Parse(string, out CCN.MSG.ENV.Envelope)'
4

3 回答 3

1

方法签名不匹配:

public abstract bool Parse(string input, out Envelope envelope);
public override Envelope Parse(string input)

此外,如果它不是接口,你不应该在类名前加上 I 前缀。

于 2012-10-31T04:40:15.627 回答
1

是的,签名与您在基类中定义的不匹配。格式是否应该返回一个字符串并有一个字符串作为输出参数?

此外,C# 接口中的标准命名约定以 I 开头。您应该从基类中删除 I 前缀。

public class XMLTYPE4Factory : IEnvelopeFactory {

    public XMLTYPE4 m_XMLTYPE4;

    public XMLTYPE4Factory()
    {

    }

    ~XMLTYPE4Factory()
    {

    }

    public override void Dispose()
    {

    }

    /// <summary>
    /// Parsing
    /// </summary>
    /// <param name="input"></param>
    public override Envelope Parse(string input, out string envStr)
    {
envStr= null;
        return null;
    }

    /// <summary>
    /// Formatting
    /// </summary>
    /// <param name="env"></param>
    public override string Format(Envelope env, out string envStr)
    {
        envStr = null;
        return "";
    }

}
于 2012-10-31T04:41:22.700 回答
1

您还没有使用正确的参数实现方法

Envelope env;
string s;

public override Envelope Parse(string input,out Envelope env)
{
    env = new Envelope();
    return env;
}

public override string Format(Envelope env,out string s)
{
    s="somestring";
    return s;
}
于 2012-10-31T04:44:18.677 回答