Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You should use IEnumerable<> instead of List<> as the former will only gather the values if accessed. See http://stackoverflow.com/a/3628705/2655508https://stackoverflow.com/a/3628705/2655508

You should use IEnumerable<> instead of List<> as the former will only gather the values if accessed. See http://stackoverflow.com/a/3628705/2655508

You should use IEnumerable<> instead of List<> as the former will only gather the values if accessed. See https://stackoverflow.com/a/3628705/2655508

edited body
Source Link
BCdotWEB
  • 11.3k
  • 2
  • 27
  • 45

What you did good
Generally the naming of your methods with its parameters is good.
You are using barcesbraces { } also for single line if commands which is very good.

What you did good
Generally the naming of your methods with its parameters is good.
You are using barces { } also for single line if commands which is very good.

What you did good
Generally the naming of your methods with its parameters is good.
You are using braces { } also for single line if commands which is very good.

added 19 characters in body
Source Link
Heslacher
  • 50.4k
  • 5
  • 81
  • 175
private IEnumerable<SerializerContainer> SortList(IEnumerable<SerializerContainer> listParam)
{ 

    if (!listParam.Any()) { return Enumerable.Empty<SerializerContainer>(); }

    int listParamCount = listParam.Count();
    SerializerContainer[] scArray = new SerializerContainer[listParamCount];

    if (!listParam.Any()) { return scArray.AsEnumerable(); }

    List<SerializerContainer> imList = listParam.FilterBySource("XXX").ToList();
    List<SerializerContainer> dmList = listParam.FilterBySource("YYY").ToList();

    imList.Sort();
    dmList.Sort();

    int idx;
    for (int i = imList.Count - 1; i >= 0; i--)
    {
        if (imList[i].Order >= listParamCount)
        {
            idx = listParamCount - 1;
        }
        else
        {
            idx = imList[i].Order - 1;
        }

        while (scArray[idx] != null)
        {
            idx--;
        }

        if (idx >= 0)
        {
            scArray[idx] = imList[i];
        }
        else
        {
            throw new ArgumentOutOfRangeException(@"The index for the configuration list sort operation is less than zero.");
        }
    }

    idx = 0;

    foreach (SerializerContainer sc in dmList)
    {
        while (scArray[idx] != null)
        {
            idx++;
        }

        scArray[idx] = sc;
    }

    return scArray.AsEnumerable();
}  
private IEnumerable<SerializerContainer> SortList(IEnumerable<SerializerContainer> listParam)
{
    int listParamCount = listParam.Count();
    SerializerContainer[] scArray = new SerializerContainer[listParamCount];

    if (!listParam.Any()) { return scArray.AsEnumerable(); }

    List<SerializerContainer> imList = listParam.FilterBySource("XXX").ToList();
    List<SerializerContainer> dmList = listParam.FilterBySource("YYY").ToList();

    imList.Sort();
    dmList.Sort();

    int idx;
    for (int i = imList.Count - 1; i >= 0; i--)
    {
        if (imList[i].Order >= listParamCount)
        {
            idx = listParamCount - 1;
        }
        else
        {
            idx = imList[i].Order - 1;
        }

        while (scArray[idx] != null)
        {
            idx--;
        }

        if (idx >= 0)
        {
            scArray[idx] = imList[i];
        }
        else
        {
            throw new ArgumentOutOfRangeException(@"The index for the configuration list sort operation is less than zero.");
        }
    }

    idx = 0;

    foreach (SerializerContainer sc in dmList)
    {
        while (scArray[idx] != null)
        {
            idx++;
        }

        scArray[idx] = sc;
    }

    return scArray.AsEnumerable();
}  
private IEnumerable<SerializerContainer> SortList(IEnumerable<SerializerContainer> listParam)
{ 

    if (!listParam.Any()) { return Enumerable.Empty<SerializerContainer>(); }

    int listParamCount = listParam.Count();
    SerializerContainer[] scArray = new SerializerContainer[listParamCount];

    List<SerializerContainer> imList = listParam.FilterBySource("XXX").ToList();
    List<SerializerContainer> dmList = listParam.FilterBySource("YYY").ToList();

    imList.Sort();
    dmList.Sort();

    int idx;
    for (int i = imList.Count - 1; i >= 0; i--)
    {
        if (imList[i].Order >= listParamCount)
        {
            idx = listParamCount - 1;
        }
        else
        {
            idx = imList[i].Order - 1;
        }

        while (scArray[idx] != null)
        {
            idx--;
        }

        if (idx >= 0)
        {
            scArray[idx] = imList[i];
        }
        else
        {
            throw new ArgumentOutOfRangeException(@"The index for the configuration list sort operation is less than zero.");
        }
    }

    idx = 0;

    foreach (SerializerContainer sc in dmList)
    {
        while (scArray[idx] != null)
        {
            idx++;
        }

        scArray[idx] = sc;
    }

    return scArray.AsEnumerable();
}  
Source Link
Heslacher
  • 50.4k
  • 5
  • 81
  • 175
Loading