Use interfaces for the objects you would like to group together, make two checks. For example,
****************************************
interface ISimilarObject{
public int PrimaryKey{
get;
set;
}
public string Name{
get;
set;
}
}
****NOW IMPLEMENT THIS INTERFACE WITH THE OBJECTS YOU WANT TO GROUP TOGETHER****
public class ObjectOne: ISimilarObject{
private string name;
private int primaryKey;
public Object(){}
///other methods, properties, etc.///
****IMPLEMENT METHODS/PROPERTIES/ETC. REQUIRED BY THE INTERFACE*********
public int PrimaryKey{
get{ return this.primaryKey; }
set{ this.primaryKey = value; }
}
public string Name{
get{ return this.name; }
set{ this.name = value; }
}
}
public class ObjectTwo: ISimilarObject{
private string name;
private int primaryKey;
public Object(){}
///other methods, properties, etc.///
****IMPLEMENT METHODS/PROPERTIES/ETC. REQUIRED BY THE INTERFACE*********
public int PrimaryKey{
get{ return this.primaryKey; }
set{ this.primaryKey = value; }
}
public string Name{
get{ return this.name; }
set{ this.name = value; }
}
}
******NOW CHECk FOR THE INTERFACE INSTEAD OF AN ACTUAL OBJECT TYPE********
foreach(ISimilarObject similar in collection){
}
I dont know the VB specific syntax, but this should be enough. You will need to implement interfaces in order to do what you would like, otherwise you will waste a lot of time and sacrifice performance.
Good luck!