using System.Collections;
using System.Collections.Generic;
public static void Main()
var test = new SomeEnumerable
SomeCollection = new List<SomeEntity>
Id = 1, Value = "Test1", Name = "SomeName1WithEmail", ContactType = ContactPointType.Email, IsDefault = false, IsDeleted = false
Id = 1, Value = "Test1", Name = "SomeName1WithPhone", ContactType = ContactPointType.Phone, IsDefault = false, IsDeleted = false
Id = 2, Value = "Test2", Name = "SomeName2", ContactType = ContactPointType.Email, IsDefault = false, IsDeleted = false
var samples = test.SomeCollection.Where(s => !s.IsDeleted && s.Id == 1)
.Select(s => new SomeTargetClassType
Email = s.GetContactPoint(ContactPointType.Email),
Phone = s.GetContactPoint(ContactPointType.Phone)
samples.ForEach(s => Console.WriteLine(s.Name + " ID --" + s.Id + " Email -- " + s.Email + " Phone -- " + s.Phone));
var testInterface = new SomeOtherEntity{ Value = "It works!", ContactType = ContactPointType.Email};
var result = (from SomeEntity sample in test.SomeCollection where !string.IsNullOrEmpty(sample.GetContactPoint(testInterface.ContactType))
select new SomeTargetClassType
Email = sample.GetContactPoint(ContactPointType.Email),
Phone = sample.GetContactPoint(ContactPointType.Phone)
result.ForEach(s => Console.WriteLine("Interface yielded: Email -- " + s.Email + " Phone -- " + s.Phone));
public class SomeEnumerable
public List<SomeEntity> SomeCollection{get; set;}
public interface IContactable
ContactPointType GetContactType();
public class SomeEntity : IContactable
public int Id { get; set; }
public string Name{get;set;}
public bool IsDeleted{get;set;}
public string Value { get; set; }
public ContactPointType ContactType { get; set; }
public bool IsDefault { get; set; }
public ContactPointType GetContactType()
public class SomeOtherEntity : IContactable
public ContactPointType ContactType {get; set;}
public string Value{get; set;}
public ContactPointType GetContactType()
public enum ContactPointType
public class SomeTargetClassType
public string Name {get;set;}
public string Address{get;set;}
public string Country {get;set;}
public string Email{get;set;}
public string Phone{get;set;}
public static class Extensions
public static string GetContactPoint(this IContactable src, ContactPointType contactType)
return src.GetContactType() == contactType ? src.GetValue() : "";