0

I have this entity class Map and I have created another partial class that implements the interface which basically carries common properties that is shared among classes.

namespace entity
{
    public partial class Map
    {
        public Guid Id { get; set; }

        public DateTime date1 { get; set; } 

        public DateTime date2 { get; set; } 

        public int? test1 { get; set; }

        public int? test2 { get; set; }

    }

    public partial class Map : ICommonFields 
        {

        }

}

namespace Test
{
    public interface ICommonFields
    {
        Guid Id { get; set; }

        DateTime date1 { get; set; } 

        DateTime date2 { get; set; } 

    }
}

Now, in my code I get List of class Map

check(List<Map>);

private void check(List<ICommonFields> co)
{
   // do something
}

I get this error

"cannot convert from system.collections.generic.list map to system.collections.generic.list ICommonfields"

How can I do this conversion, since I am only interested in common field Id, date1 and date2 ?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
user1005310
  • 737
  • 2
  • 12
  • 40

1 Answers1

1

Your code lack a bit of explaination but if I understand it right whhat you want to do is

var myList = new List<Map>();

/* loading of myList */

check(myList.ToList<ICommonFields>());
Pomme De Terre
  • 342
  • 4
  • 14