
/// <summary>
/// Create new ODataComplexValue from the old, to discard all null/zero values
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
private ODataComplexValue RebuildComplexValue(ODataComplexValue source)
{
ODataComplexValue newVal = new ODataComplexValue();
newVal.TypeName = source.TypeName;
List<ODataProperty> complexSons = source.Properties.ToList();
//Filter to get new list
List<ODataProperty> filteredSons = new List<ODataProperty>();
foreach (ODataProperty prop in complexSons)
{
PropertyType retType = GetPropertyType(prop);
switch (retType)
{
case PropertyType.SimpleEdmx:
{
if (null != prop.Value)
{
filteredSons.Add(prop);
}
}
break;
case PropertyType.ComplexType:
{
//Recursively
ODataComplexValue comx = RebuildComplexValue((ODataComplexValue)prop.Value);
if (comx.Properties.Count() > 0)
{
prop.Value = comx;
filteredSons.Add(prop);
}
}
break;
case PropertyType.Collection:
{
ODataCollectionValue coll = RebuildCollectionValue((ODataCollectionValue)prop.Value);
List<ODataComplexValue> listSubs = (List<ODataComplexValue>)coll.Items;
if (listSubs.Count > 0)
{
prop.Value = coll;
filteredSons.Add(prop);
}
}
break;
default:
break;
}
}
//Re-Assign sons
newVal.Properties = filteredSons;
return newVal;
}
case PropertyType.SimpleEdmx:
{
if (null != prop.Value)
{
if (prop.Value.GetType().Name == "Int32")
{
//Check the value now.
bool bInclude = false;
try
{
//TODO: You cannot simply do this, potential bugs there maybe.
//Use your own logics the determine if need to ignore ZEORs or not.
int val = Convert.ToInt32(prop.Value);
bInclude = (0 != val);
}
catch (Exception)
{
}
if (bInclude)
filteredSons.Add(prop);
}
else
filteredSons.Add(prop);
}
}
break;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |