I have 2 IEnumerable of Type1 and Type2, ie. IEnumerable<Type1>
& IEnumerable<Type2>
. Type1 and Type2 have 1 common field, called TypeID. Multiple of same TypeID may exists in IEnumerable<Type2>
, I would like to check against the 2 IEnumerables and if TypeID inside Type2 equals to TypeID inside Type1, I would combine the 2 into a new object. If they are not, then the new object just set IEnumerable<Type2>
as null
. It's a bit confusing, so I've include a pseudo code to better demonstrate what I'm trying to accomplish:
namespace test
{
public class ConfigMetaDataColumns
{
public int FieldID { get { return ValueInt("FieldID"); } }
public string Label { get { return ValueString("Label"); } }
public string FieldName { get { return ValueString("FieldName"); } }
}
public class ConfigDataColumns
{
public int FieldID { get { return ValueInt("FieldID"); } }
public double NumericValue { get { return ValueDouble("NumericValue"); } }
}
public class ConfigMetaDataCombinedColumns
{
public ConfigMetaDataColumns ConfigMetaData { get; set; }
public IEnumerable<ConfigDataColumns> ConfigData { get; set; }
}
public class GetCombinedData
{
// Get ConfigMetaData
private IEnumerable<ConfigMetaDataColumns> GetConfigMetaData()
{
var requester = GetConfigMetaDataMethodHere();
return requester.Items;
}
// Get ConfigMeta
private IEnumerable<ConfigMetaDataColumns> GetConfigMetaData()
{
var requester = GetConfigDataMethodHere();
return requester.Items;
}
// Combine the two here!
private IEnumerable<ConfigMetaDataCombinedColumns> GetData()
{
/*
* ConfigMetaDataColumns example:
* FieldID: 1
* Label: Label1
* FieldName: FieldName1
*
* FieldID: 2
* Label: Label2
* FieldName: FieldName2
*
* FieldID: 3
* Label: Label3
* FieldName: FieldName3
* */
/*
* ConfigDataColumns example:
* FieldID: 1
* NumericVal: NumericVal1
* FieldID: 1
* NumericVal: NumericVal2
* FieldID: 3
* NumericVal: NumericVal3
* */
/*
* Cobined data should be:
*
* FieldID: 1
* Label: Label1
* FieldName: FieldName1
{* FieldID: 1
* NumericVal: NumericVal1
* FieldID: 1
* NumericVal: NumericVal2}
*
* FieldID: 2
* Label: Label2
* FieldName: FieldName2
{* NULL *}
*
* FieldID: 3
* Label: Label3
* FieldName: FieldName3
{* FieldID: 3
* NumericVal: NumericVal3}
* */
}
}
}
Thank you.