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

    +134.6

    1. 1
    t.GetProperty(item.Split('=')[0].Trim()).SetValue(this, item.Split('=')[1].Trim(), null);

    Инициализация свойства из строик формата имя=значение

    dmtr, 03 Декабря 2009

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

    +89.5

    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
    private void ProcessActionsLookup(object sender)
            {
                LookUpEdit lookUpEdit = sender as LookUpEdit;
                if (lookUpEdit != null)
                {
                    if (lookUpEdit.EditValue != null)
                    {
                        if (lookUpEdit.EditValue.Equals(currentActionLookupValue))
                        {
                            if (actionsGridControlBindingSource.Current != null &&
                                !_presenter.ActionHasProperParameters(actionsGridView.FocusedRowHandle))
                            {
                                SetDataSourceForInnerGrid(sender);
                            }
                        }
                        else
                        {
                            SetDataSourceForInnerGrid(sender);
                        }
                    }
                    else
                    {
                        SetDataSourceForInnerGrid(sender);
                    }
                }
            }

    Мы пойдем другим путем.
    Некоторые скажут что в представленном контексте абсолютно нормальный код, я все же не соглашусь

    codeposter, 03 Декабря 2009

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

    +943.6

    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
    try
            {
                if (CheckLoginLenght())
                {
                    if (CheckPassLenght())
                    { 
                       if (CheckEmptyEMail())
                       {
                            if (CheckIsPassEquals())
                            {
                                if (CheckEmptyLogin())
                                {
                                    if (CheckLoginInBase())
                                    {
                                       if (RadCaptcha1.IsValid)
                                      {
                                          if (CheckMailInBase())
                                          {

    Проверка данных введенных для регситарции (ASP.NET)

    dmtr, 02 Декабря 2009

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

    +123.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    //...
    if ( (x > 0) || (x == 0))
    {
              //....
    }

    Человек явно с головой не дружит

    psina-from-ua, 01 Декабря 2009

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

    +128.8

    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
    public static T Parse<T>(string txt)
            {
                if (string.IsNullOrEmpty(txt))
                    return default(T);
    
                txt = txt.Trim();
    
                Type[] typeArray = new Type[] {
                    typeof(string),
                    typeof(T).MakeByRefType()};
    
                MethodInfo mi = typeof(T).GetMethod("TryParse", typeArray);
    
                T value = default(T);
    
                if (mi != null)
                {
                    object[] prms = new object[]{
                    txt,
                    value};
    
                    if ((bool)mi.Invoke(null, prms) && prms[1] != null)
                        value = (T)prms[1];
                }
    
                return value;
            }

    Не скажу что это такой уж говнокод, но что то говнистое в нем есть =)

    sven47, 26 Ноября 2009

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

    +135.6

    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
    public class Singleton<T> where T : class
        {
            private static T _Instance = null;
            protected static readonly object locker = new object();
    
            public static T Instance
            {
                get
                {
                    if (_Instance == null)
                    {
                        lock (locker)
                        {
                            if (_Instance == null)
                            {
                                ConstructorInfo[] info = typeof(T).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic);
                                if (info.Length > 0)
                                    _Instance = (T)info[0].Invoke(null);
                            }
                        }
                    }
                    return _Instance;
                }
            }
    
            protected Singleton() { }
    
            static Singleton() { }
    
        }

    Вот такой вот универсальный сиглтон нашел в проекте

    sven47, 26 Ноября 2009

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

    +98.6

    1. 1
    private bool IsNamesAreEqual(string itemName, string nodeName) { ... }

    Правда это скорее относится к английскому языку, нежели к шарпу.
    Иногда полезно перечитывать давно написаный код, много нового узнаешь )))

    plsc_rover, 20 Ноября 2009

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

    +129.7

    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
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    public string GetHtmlElement(RepeaterItem Container)
            {
                string Result = string.Empty;
                string AClasses = HAS_CHILDREN_BASE_CSS_CLASS;
                SiteMapNode Node = (SiteMapNode)Container.DataItem;
                string Title = Node.Title;
                string EnabledAttrSign = CustomSiteMapNodeInfo.ENABLED_ATTR_NAME;
                string CssClassNameSign = CustomSiteMapNodeInfo.CSS_CLASS_ATTR_NAME;
    
                string SpanCssClasses = string.Empty;
    
                // checks for separator
                if (string.IsNullOrEmpty(Node.Title) || Node.Title == ShellModuleInitializer.SEPARATOR)
                {
                    SpanCssClasses = MENU_SEPARATOR_CSS_CLASS_NAME;
                    Title = EMPTY_TEXT;
                }
    
                bool HasImage = !string.IsNullOrEmpty(Node[CssClassNameSign]);
                if (HasImage)
                {
                    SpanCssClasses += HAS_IMAGE_CSS_CLASS_NAME;
                }
    
                Result = string.Format("<span class=\"{0}\">{1}</span>", SpanCssClasses, Title);
    
                if (HasImage)
                {
                    Result = string.Format("<span class=\"{0}\">{1}</span>{2}", Node[CssClassNameSign], EMPTY_TEXT, Result);
                }
    
                // checks for disabled item
                if (!string.IsNullOrEmpty(Node[EnabledAttrSign]) && string.Compare(Node[EnabledAttrSign], "false", true) == 0)
                {
                    AClasses += string.Format(" {0}", DISABLED_CSS_CLASS_NAME);
                }
    
                // checks for enabled item
                if (!string.IsNullOrEmpty(Node[EnabledAttrSign]) && string.Compare(Node[EnabledAttrSign], "true", true) == 0)
                {
                    Result = string.Format("<a href=\"{0}\" class=\"{1}\">{2}</a>", GetFullUrl(Container), AClasses, Result);
                }
                else
                {
                    // cheks for non-clickable item
                    Result = string.Format("<a class=\"{0}\">{1}</a>", AClasses, Result);
                }
    
                return Result;
            }

    Valera, 18 Ноября 2009

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

    +136.3

    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
    for (int i = 0; i < count; i++) // перебираем список адресов
                    {
                        email = email_list[i].ToString();                   
                        for (int y = i + 1; y < count; y++)  // перебираем тот же список но начиная со следующего элемента
                        {
                            if (email == email_list[y].ToString())
                            {
                                // если такой "y" уже есть в duble_index то пропускать
                                if (!duble_index.Contains(y))                                
                                    duble_index.Add(y); // он дубликат - заносим его в "ЧЕРНЫЙ СПИСОК" =)
                            }
                         }
                      }
    ***************
    
               System.Collections.ArrayList al = System.Collections.ArrayList.Adapter(duble_index);
                al.Sort();
                int z = 0;
                int [] buff = new Int32[duble_index.Count];
                foreach (Int32 s in al)
                {
                    buff[z] = s;
                    z++;
                }
    
                for (int i = buff.Length-1; i >= 0; i--)
                {
                    email_list.RemoveAt(buff[i]);
                }

    Удаление дубликатов в не отсортированном списке.... Это реально упростить?

    AndrewKo, 17 Ноября 2009

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

    +101.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var r = from t in ds.ProductTags
    		where t.ProductTagID == tag
    			|| t.Parent.ProductTagID == tag
    			|| t.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.Parent.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.Parent.Parent.Parent.Parent.ProductTagID == tag
    			|| t.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.ProductTagID == tag
    		select t;

    Это мой код. Надоело писать рекурсивные СTE чтобы выбрать всех детишек. Спросил у кастомера можно ли ограничить вложенность. Он согласился ;).. На свою голову ;).

    Mike Chaliy, 11 Ноября 2009

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