1. C# / Говнокод #23243

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    internal static object CreateDefaultEqualityComparer(Type type)
            {
                Debug.Assert(type != null && type is RuntimeType);
    
                object result = null;
                var runtimeType = (RuntimeType)type;
    
                // Specialize for byte so Array.IndexOf is faster.
                if (type == typeof(byte))
                {
                    result = new ByteEqualityComparer();
                }
                // If T implements IEquatable<T> return a GenericEqualityComparer<T>
                else if (typeof(IEquatable<>).MakeGenericType(type).IsAssignableFrom(type))
                {
                    result = CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericEqualityComparer<int>), runtimeType);
                }
                // Nullable does not implement IEquatable<T?> directly because that would add an extra interface call per comparison.
                // Instead, it relies on EqualityComparer<T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.
                else if (type.IsGenericType)
                {
                    if (type.GetGenericTypeDefinition() == typeof(Nullable<>))
                    {
                        result = TryCreateNullableEqualityComparer(runtimeType);
                    }
                }
                // The equality comparer for enums is specialized to avoid boxing.
                else if (type.IsEnum)
                {
                    result = TryCreateEnumEqualityComparer(runtimeType);
                }
                
                return result ?? CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(ObjectEqualityComparer<object>), runtimeType);
            }

    Код взят из CoreCLR mscorlib сырцов.

    Внимание вопрос. Нахерна было писать эту обосгость когда данный метод легко делается генериком без какого либо вызова "невидимого" кода?

    вот пример как все должно было быть

    ```
    internal static object CreateDefaultEqualityComparer<T>()
    {
    // Specialize for byte so Array.IndexOf is faster.
    if (typeof(T) == typeof(byte))
    {
    result = new ByteEqualityComparer();
    }
    // If T implements IEquatable<T> return a GenericEqualityComparer<T>
    else if (typeof(IEquatable<T>).IsAssignableFrom( typeof(T)))
    {
    result new GenericEqualityComparer<T>();
    }
    // Nullable does not implement IEquatable<T?> directly because that would add an extra interface call per comparison.
    // Instead, it relies on EqualityComparer<T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.
    else if (typeof(T).IsGenericType)
    {
    if (typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>))
    {
    result = new NullableEqualityComparer<T>();
    }
    }
    // The equality comparer for enums is specialized to avoid boxing.
    else if (typeof(T).IsEnum)
    {
    result = TryCreateEnumEqualityComparer<T>();
    }

    return result ?? new ObjectEqualityComparer<T>();
    }
    ```

    ASD_77, 07 Августа 2017

    Комментарии (10)
  2. C# / Говнокод #23239

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    internal static object CopyImmutableSortedDictionary<K, V>(object original, ICopyContext context)
    {
                return original;
    }

    Microsoft Orleans https://github.com/dotnet/orleans

    Копирование объекта в 2к17

    ClockworkAlex, 04 Августа 2017

    Комментарии (5)
  3. C# / Говнокод #23238

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    public void GetMapping(DbObject obj, IEnumerable<DbObject> map = null, params string[] additional)
    {
        Mapper m = Mapper.Get(obj.DialectType);
        switch (m.MapperType)
        {
            case MapperType.SST:
                m.Initialize(null, additional);
                break;
            case MapperType.SSM:
                m.Initialize(null, additional);
                break;
            default:
                throw new ArgumentException();
        }
        // применение: этот метод возвращает List<Tupple<DbObject, DbObject>>
        m.GetMappingByDialect(obj, map);
    }
    
    public enum MapperType
    {
        SST,
        SSM,
    }

    Во-вторник - этот код, выбил меня из рабочего процесса на весь день ...

    spyrytus, 04 Августа 2017

    Комментарии (0)
  4. C# / Говнокод #23191

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    private void button1_Click(object sender, EventArgs e)
            {
                short number = 34;
                folderBrowserDialog1.ShowDialog();
           //fileListBox1.FileName = folderBrowserDialog1.SelectedPath;
    
                DirectoryInfo myFolder = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
    
                foreach (FileInfo T in myFolder.GetFiles())
                {
                    number++;
                    string filename = T.Name;
                    File.Move(folderBrowserDialog1.SelectedPath + "" + filename, folderBrowserDialog1.SelectedPath + "" + number.ToString());
                }
            }
        }
    }

    Решил я тут старые проекты копнуть...

    caffeinemania, 17 Июля 2017

    Комментарии (2)
  5. C# / Говнокод #23184

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public bool CheckBool(string value)
           {
               value = value.ToLower();
               return !string.IsNullOrEmpty(value) && (value == "on" || value == "yes" || value == "1") ? true : false;
           }

    another variant ;D

    selicate, 14 Июля 2017

    Комментарии (4)
  6. C# / Говнокод #23183

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    static string[] nums = new string[60] {
                "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
                "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
                "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
                "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
                "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
                "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"
            };
    
            /// <summary>
            /// Форматирует дату в dd.MM.yyyy
            /// </summary>
            /// <param name="date"></param>
            /// <returns></returns>
            public static string ShortRuDateStr(ref DateTime date)
            {
                return string.Concat(nums[date.Day], ".", nums[date.Month], ".", YearToString(date.Year));
            }
    
    
            /// <summary>
            /// Возвращает текущую дату в формате yyyyMMddHHmmss
            /// </summary>
            /// <returns></returns>
            public static string Timestamp(ref DateTime date)
            {
                return string.Concat(YearToString(date.Year), nums[date.Month], nums[date.Day], nums[date.Hour], nums[date.Minute], nums[date.Second]);
            }
    
            public static string YearToString(int year)
            {
                return year.ToString().PadLeft(4, '0');
            }

    michael443959, 13 Июля 2017

    Комментарии (20)
  7. C# / Говнокод #23177

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private bool CheckBool(string value)
           {
               if (value == "on")
                   return true;
               else
                   return false;
           }

    ////

    selicate, 12 Июля 2017

    Комментарии (2)
  8. C# / Говнокод #23166

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    public static int[] GetRandomComStats(int level)
        {
            int[] stats = new int[3] { -1, -1, -1 };
            int summ = (int)(1.2f * level);
            int minStat = level / 3f - (level+ 1) / 10 < 0 ? 0 : (int)(level / 3f - (level + 1) / 10);
            int maxStat = (int)(level / 3f + (level + 1) / 10);
            Debug.Log("level: " + level + " min stat: " + minStat + " max stat: " + maxStat + " summ: " + summ);
            int fr = Random.Range(0, 2);
            int f2 = Random.Range(0, 3);
            int f1 = 0;
            stats[f2] = Random.Range(minStat, maxStat + 1);
            for (int i = 0; i < 3; i++)
            {
                if (fr == 1 && stats[i] == -1)
                {
                    if (summ - stats[f2] > maxStat) stats[i] = Random.Range(minStat,  maxStat + 1);
                    else if (summ - stats[f2] < 0) stats[i] = 0;
                    else stats[i] = Random.Range(minStat, summ - stats[f2] + 1);
                    f1 = i;
                    goto label;
                }
                fr = 1;
    
            }
            label: 
            for (int i = 0; i < 3; i++)
            {
                if (stats[i] == -1)
                {
                    if (summ < stats[f1] + stats[f2]) stats[i] = 0;
                    else if (summ - stats[f1] - stats[f2] > maxStat) stats[i] = maxStat;
                    else stats[i] = summ - stats[f1] - stats[f2];
                    Debug.Log(f1 + ": " + stats[f1]+ " " + f2 + ": " + stats[f2] + " " + i + ": " + stats[i]);
                }
            }
            return stats;
        }

    Генерация рандомных стат персонажей в зависимости от уровня.

    Super_Indus_coding, 07 Июля 2017

    Комментарии (1)
  9. C# / Говнокод #23149

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public bool isUnderpayment(double paymentValue)
     {
         if (paymentValue > 0)
             return true;
    
            return false;
      }

    Пятница, смеркалось.

    allex32, 27 Июня 2017

    Комментарии (2)
  10. C# / Говнокод #23138

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    for (int i = 0; i < components.Length; i++) 
    { 
              if (components[i]) components[i].GetComponent<ComponentScript>().ChangeComponent(CalculateCircuitScript.ComponentDataArray[components[i].GetComponent<ComponentScript>().lineNumber, components[i].GetComponent<ComponentScript>().elementNumber]); 
    }

    Конструктор трёхфазных цепей на Unity3D

    Super_Indus_coding, 19 Июня 2017

    Комментарии (0)