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

    +138

    1. 1
    2. 2
    3. 3
    4. 4
    code = _factorCodeMax[factorUnid];
    code++;
    _factorCodeMax[factorUnid] = code;
    return code;

    Maps, 10 Августа 2012

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var priorities = Repository.Get<IIncidentPriority>().Query().OrderBy(x => x.Priority)
     .Select(x => new InputItem { Id = x.Id.ToString(CultureInfo.InvariantCulture), Value = x.LocalizationValue })
    .ToList();
    
    priorities.Add(new InputItem { Id = "-1", Value = Localizator.Get("X4.Incident.Undefined") });
    priorities.Reverse();

    тру хацкеры презирают метод Insert )

    tob1az, 09 Августа 2012

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

    +134

    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
    private void LettersOnChanged(object sender, EventArgs eventArgs)
            {
                this._lettersBinding.Clear();
                this._lettersBinding.AddRange(this._letters);
    
                this.MailAgentGridControl.ResetBindings();
                this.MailAgentGridControl.RefreshDataSource();
                _bindingSourceLetters.ResetCurrentItem();
                _bindingSourceLetters.ResetBindings(false);
    
                int pos = _bindingSourceLetters.Position;
    
                this.MailAgentGridControl.DataSource = null;
                this.MailAgentGridControl.DataSource = _bindingSourceLetters;
    
                if (_bindingSourceLetters.Current == null)
                {
                    _guiCtrl.CurrentLetter = null;
                    return;
                }
    
                if (pos > _bindingSourceLetters.Count - 1)
                    pos = _bindingSourceLetters.Count - 1;
    
                if (pos < 0)
                    return;
    
                _bindingSourceLetters.Position = pos;
    
                MailAgentGridControlTableView.UnselectRow(MailAgentGridControlTableView.GetRowHandle(0));
                MailAgentGridControlTableView.SelectRow(pos);
            }

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

    partizan, 09 Августа 2012

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (Cache[articlesRssData] != null)
    {
         return Cache[articlesRssData] as ArticleRssData?;
    }
    
    return null;

    uusb, 08 Августа 2012

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

    +137

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static Tag GetTopic(Guid tagId)
    {
     var tag = DataService.PerThread.TagSet.SingleOrDefault(x => x.Id == tagId);
     if (tag == null && tag.GroupId != null)
      return null;
    
     if (tag.TopicState != (byte)TopicState.GroupTopic)
      return null;
    
     return tag;
    }

    Arbium, 08 Августа 2012

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

    +142

    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
    while (true)
    {
        try
        {
            ProductService.Invoke(method);
            return; 
        }
        catch(Exception ex)
        {
            if (ex is System.ServiceModel.CommunicationException)
            {
                if (currentRetryCount == RetryCount)
                        throw new CommunicationException(CommunicationFailureMessage, ex);
                    System.Threading.Thread.Sleep(RetryWait);
                    currentRetryCount++;
            }
        }
    }

    abatishchev, 03 Августа 2012

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

    +140

    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
    FileInfo file = new FileInfo(fileName);
    FileSecurity fSecurity = File.GetAccessControl(fileName);
    
    foreach (FileSystemAccessRule permissions in fSecurity.GetAccessRules(true, true, typeof(NTAccount)))
    {
         string login = permissions.IdentityReference.Translate(typeof(NTAccount)).Value.ToString();
         string permiss =  permissions.FileSystemRights.ToString();
    
         if ((login != "логин") && (login != "логин") && (login != "логин"))
         {
             fSecurity.SetAccessRuleProtection(true, false);
             fSecurity.RemoveAccessRule(new FileSystemAccessRule(login, permissions.FileSystemRights, AccessControlType.Allow));
         }
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
    
    }
    File.SetAccessControl(fileName, fSecurity);

    vertu, 03 Августа 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach (var item in text.Split(' ')) {
    	if (!string.IsNullOrEmpty(item)) {
    		text = item;
    		break;
    	}
    }

    переменная text всегда содержит несколько пробелов и затем идентификатор.

    paladin80, 02 Августа 2012

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

    +106

    1. 1
    IDictionary activeProcesses = (IDictionary)(new Hashtable());

    По мотивам

    http://govnokod.ru/11512
    Код встречен в книге
    http://tinyurl.com/eai-patterns
    Можно объяснить человеку, не знакомому с тонкостями C#, зачем это нужно, если Hashtable : IDictionary?

    roman-kashitsyn, 01 Августа 2012

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

    +137

    1. 1
    model = (IModel)Activator.CreateInstance("DataModel", type).Unwrap() as IModel;

    Maps, 01 Августа 2012

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