none
interface not implemented RRS feed

  • Question

  • Hi,

    I am learning C#, and got some code in VS 2010, since I can't find VS 2010 any more, so I installed VS 2012.

    The following is the code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ML.Util.CSV;
    using System.IO;
    using System.Windows.Forms;

    namespace ML.Data.Market.Loader
    {
        public class CSVFileLoader : IMarketLoader
        {

            #region IMarketLoader Members


            string Precision { get; set; }
            public static string LoadedFile { get; set; }


            public ICollection<LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList<MarketDataType> neededTypes, DateTime from, DateTime to, string File)
            {
                try
                {
                    //We got a file, lets load it.
                    ICollection<LoadedMarketData> result = new List<LoadedMarketData>();
                    ReadCSV csv = new ReadCSV(File, true, CSVFormat.English);
                    csv.DateFormat = "yyyy.MM.dd HH:mm:ss";

                    DateTime ParsedDate = from;


                    //  Time,Open,High,Low,Close,Volume
                    while (csv.Next() && ParsedDate >= from && ParsedDate <= to  )
                    {
                        DateTime date = csv.GetDate("Time");
                        double Bid= csv.GetDouble("Bid");
                        double Ask = csv.GetDouble("Ask");
                        double AskVolume = csv.GetDouble("AskVolume");
                        double BidVolume= csv.GetDouble("BidVolume");
                        double _trade = ( Bid + Ask ) /2;
                        double _tradeSize = (AskVolume + BidVolume) / 2;
                        LoadedMarketData data = new LoadedMarketData(date, symbol);
                        data.SetData(MarketDataType.Trade, _trade);
                        data.SetData(MarketDataType.Volume, _tradeSize);
                        result.Add(data);

                        Console.WriteLine("Current DateTime:"+ParsedDate.ToShortDateString()+ " Time:"+ParsedDate.ToShortTimeString() +"  Start date was "+from.ToShortDateString());
                        Console.WriteLine("Stopping at date:" + to.ToShortDateString() );
                        ParsedDate = date;
                        //double open = csv.GetDouble("Open");
                        //double close = csv.GetDouble("High");
                        //double high = csv.GetDouble("Low");
                        //double low = csv.GetDouble("Close");
                        //double volume = csv.GetDouble("Volume");
                        //LoadedMarketData data = new LoadedMarketData(date, symbol);
                        //data.SetData(MarketDataType.Open, open);
                        //data.SetData(MarketDataType.High, high);
                        //data.SetData(MarketDataType.Low, low);
                        //data.SetData(MarketDataType.Close, close);
                        //data.SetData(MarketDataType.Volume, volume);
                        result.Add(data);
                    }

                    csv.Close();
                    return result;
                }

                catch (Exception ex)
                {

                    Console.WriteLine("Something went wrong reading the csv");
                    Console.WriteLine("Something went wrong reading the csv:" + ex.Message);
                }

                Console.WriteLine("Something went wrong reading the csv");
                return null;
            }



            public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to)
            {
                ICollection<LoadedMarketData> result = new List<LoadedMarketData>();



                
                if (File.Exists(LoadedFile))
                {
                   
                  
                    result = ReadAndCallLoader(ticker, dataNeeded, from, to, LoadedFile);
                    return result;
                }


                return null;
            }



            #endregion

            #region IMarketLoader Members


           

            #endregion

            #region IMarketLoader Members


            /// <summary>
            /// Gets the file we want to parse.
            /// </summary>
            /// <param name="file">The file.</param>
            /// <returns></returns>
            public string GetFile(string file)
            {
                if (File.Exists(file))
                    LoadedFile = file;
                return LoadedFile;
            }

            #endregion
        }
    }

    However, I got compiler error:

    'ML.Data.Market.Loader.CSVTicksLoader' does not implement interface member ML.Data.Market.Loader.IMarketLoader.GetFile(string)

    I don't know much about interface, but I can see the code for GetFile was there.

    Any idea on how to correct the mistake?

    Thanks and have a nice day!

    Monday, August 13, 2012 6:01 PM

Answers

  • The CSVFileLoader class in your sample implements a GetFile method. What about the CSVTicksLoader about which the message is talking?
    Tuesday, August 14, 2012 7:31 AM

All replies

  • Take a look at this example of interface, and one classs that implements a interface methods.
        public interface Person
        {
            int Age(int a, int b);
        }
    
        public class Student : Person
        {
            public int Age(int a, int b)
            {
                return a + b;
            }
        }
    Note that i just declare my return type, the method name, and the're params. And in my class, i do my stuff. Check this link here.
    And this one, here.


    Web Developer

    • Proposed as answer by milan.matejka Monday, August 13, 2012 6:17 PM
    Monday, August 13, 2012 6:07 PM
  • Check the return type of IMarketLoader.GetFile(string).  If that interface member doesn't return a string, your method (public string GetFile(string file)) would not implement it.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, August 13, 2012 6:21 PM
    Moderator
  • The CSVFileLoader class in your sample implements a GetFile method. What about the CSVTicksLoader about which the message is talking?
    Tuesday, August 14, 2012 7:31 AM