So I have these partial classes. See below for the partial implementation of ParseFCIE and my question.
class CiscoSwitch
{
Dictionary<int, CiscoVSAN> VSANList = new Dictionary<int, CiscoVSAN>();
public void ParseFCIE(string block)
{}
}
class CiscoVSAN
{
Dictionary<string, CiscoSwitch> MemberSwitches = new Dictionary<string, CiscoSwitch> ();
}
Part of ParseFCIE is to check whether an incoming switch in the input data is already in the SwitchMembers dictionary of any CiscoVSAN objects, if not, add it. I have 2 dictionary statements. The first statement works, the second the compiler says it can’t determine the type of the predicate and I don’t know why. I prefer the second second statement since it is only one step. The first way I have search for the switch then check for a null value on the result of the search.
ParseFCIE(string block)
{
string DID = string.Empty;
//partial implementation
// 'this' is a CiscoSwitch object
//this works
var vsans= this.VSANList.SelectMany(v => v.Value.MemberSwitches.
Where(d => d.Value.switchName == this.switchName));
// assume DID now has a value;
// this line the compiler says the type arguments cannot be inferred from usage
if (this.VSANList.SelectMany(v => v.Value.MemberSwitches.ContainsKey(DID)))
{}
}
1 Answer