Click here to Skip to main content
15,908,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to enter foreign key values to combobox Pin
darkelv17-Dec-07 16:04
darkelv17-Dec-07 16:04 
GeneralReflection with Generic Lists [modified] Pin
DaveyM6917-Dec-07 9:23
professionalDaveyM6917-Dec-07 9:23 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore17-Dec-07 11:31
Ed.Poore17-Dec-07 11:31 
GeneralRe: Reflection with Generic Lists Pin
DaveyM6918-Dec-07 0:33
professionalDaveyM6918-Dec-07 0:33 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore18-Dec-07 10:04
Ed.Poore18-Dec-07 10:04 
GeneralRe: Reflection with Generic Lists Pin
DaveyM6918-Dec-07 11:18
professionalDaveyM6918-Dec-07 11:18 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore18-Dec-07 14:23
Ed.Poore18-Dec-07 14:23 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore18-Dec-07 14:44
Ed.Poore18-Dec-07 14:44 
Ok I've whipped together a simple demo:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ReflectionComparer
{
	internal static class Program
	{
		[STAThread]
		private static void Main(string[] args)
		{
			// Initialize data
			var students = new StudentCollection();
			var teachers = new TeacherCollection();
			students.AddRange(new Student[] {
				new Student() { ID = 1, Name = "Edward Poore", DOB = new DateTime(1988, 4, 7) },
				new Student() { ID = 2, Name = "Joe Smith", DOB = new DateTime(2001, 5, 6) },
				new Student() { ID = 3, Name = "Davey M69", DOB = new DateTime(2006, 11, 25) }
			});
			teachers.AddRange(new Teacher[] {
				new Teacher() { ID = 1, Name = "Eric Yeatman", DOB = new DateTime(1964, 10, 2), Department = "EEE" },
				new Teacher() { ID = 2, Name = "Chris Maunder", DOB = new DateTime(1972, 3, 19), Department = "CS" },
				new Teacher() { ID = 3, Name = "Marc Clifton", DOB = new DateTime(1984, 5, 1), Department = "BIOL" }
			});

			DisplayInformation(students);
			DisplayInformation(teachers);
		}

		private static void DisplayInformation(object collection)
		{
			// Extract the enumerable collection and the enumerator
			var list = (collection as IEnumerable);
			var enumerator = list.GetEnumerator();
			// If this list is empty then nothing needs to be done
			if (enumerator.MoveNext() == true)
			{
				Sort(list, enumerator.Current.GetType());
			}
		}
		private static void Sort(IEnumerable collection, Type objectType)
		{
			Console.WriteLine(objectType.Name);
			foreach (var property in objectType.GetProperties())
			{
				Console.WriteLine("  {0}", property.Name);
			}
		}
	}
}


Student, Teacher are simple classes which define ID, Name and DOB (Teacher also includes department). The collection classes all inherit from List>T<.

I'm sorry the code uses 3.5 syntax but it saves so much typing and is so elegant I can't resist using it, hopefully things are fairly clear. The one thing that is not clear from your examples is how you decide which properties to sort on. If it were a simple are they the same test then you would simply check all properties are equal but I don't understand how you decide which one takes preference over the other (unless you specify it to the sorter routine).

GeneralRe: Reflection with Generic Lists [modified] Pin
DaveyM6919-Dec-07 0:39
professionalDaveyM6919-Dec-07 0:39 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore19-Dec-07 4:23
Ed.Poore19-Dec-07 4:23 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore19-Dec-07 13:19
Ed.Poore19-Dec-07 13:19 
GeneralRe: Reflection with Generic Lists Pin
DaveyM6920-Dec-07 0:04
professionalDaveyM6920-Dec-07 0:04 
GeneralRe: Reflection with Generic Lists Pin
Ed.Poore20-Dec-07 0:09
Ed.Poore20-Dec-07 0:09 
GeneralTranslatation Pin
mehrdadc4817-Dec-07 8:26
mehrdadc4817-Dec-07 8:26 
GeneralRe: Translatation Pin
Judah Gabriel Himango17-Dec-07 10:34
sponsorJudah Gabriel Himango17-Dec-07 10:34 
GeneralRe: Translatation Pin
Anthony Mushrow17-Dec-07 14:35
professionalAnthony Mushrow17-Dec-07 14:35 
Generalcustom form Pin
netJP12L17-Dec-07 7:18
netJP12L17-Dec-07 7:18 
GeneralRe: custom form Pin
Skippums17-Dec-07 9:20
Skippums17-Dec-07 9:20 
GeneralRe: custom form Pin
netJP12L17-Dec-07 10:27
netJP12L17-Dec-07 10:27 
GeneralRe: custom form Pin
Pete O'Hanlon17-Dec-07 10:19
mvePete O'Hanlon17-Dec-07 10:19 
Generalremove property from inherited control Pin
Eli Nurman17-Dec-07 5:24
Eli Nurman17-Dec-07 5:24 
GeneralRe: remove property from inherited control Pin
m@u17-Dec-07 5:40
m@u17-Dec-07 5:40 
GeneralRe: remove property from inherited control Pin
Skippums17-Dec-07 6:48
Skippums17-Dec-07 6:48 
GeneralRe: remove property from inherited control Pin
Pete O'Hanlon17-Dec-07 9:10
mvePete O'Hanlon17-Dec-07 9:10 
GeneralRe: remove property from inherited control Pin
Eli Nurman17-Dec-07 9:21
Eli Nurman17-Dec-07 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.