- 1
- 2
- 3
- 4
- 5
if (collection == null) collection = Rows.Where(r => r.ParentId == 0);
foreach (var row in collection.Where(r => r.ParentId > 0))
{
//немного кода
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
if (collection == null) collection = Rows.Where(r => r.ParentId == 0);
foreach (var row in collection.Where(r => r.ParentId > 0))
{
//немного кода
}
Сам писал. Вчера. Трезвый.
Сейчас вот думаю, а чо эта оно не работает?
+3
public class Man
{
public Man(string id, string name, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, year)
{
this.Name = name;
this.Brothers = brothers;
this.Id = id;
this.Age = age;
}
public Man(string id, string name, string note, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, note, year)
{
this.Name = name;
this.Brothers = brothers;
this.Id = id;
this.Age = age;
}
public Man(string id, string name, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, year)
{
this.Name = name;
this.Brothers = brothers;
this.Id = id;
this.Age = age;
}
public Man(string id, string name, string note, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, note, year)
{
this.Name = name;
this.Brothers = brothers;
this.Id = id;
this.Age = age;
}
public Man(string id, string name, Guid id, int year, int age) : base(id, year)
{
this.Name = name;
this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
this.Id = id;
this.Age = age;
}
public Man(string id, string name, string note, Guid id, int year, int age) : base(id, note, year)
{
this.Name = name;
this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
this.Id = id;
this.Age = age;
}
public Man(string id, string name, Guid id, int year, int age) : base(id, year)
{
this.Name = name;
this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
this.Id = id;
this.Age = age;
}
public Man(string id, string name, string note, Guid id, int year, int age) : base(id, note, year)
{
this.Name = name;
this.Id = id;
this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
this.Age = age;
}
public string Name { get; }
public Guid Id { get; }
public IEnumerable<Brother> Brothers { get; }
public int Age { get; }
}
Человек знал, но нехотел использовать значение параметра конструктора по умолчанию, потому что это усложняет структуру.
Переменные переназвал почеловечнее.
+1
// 1188 references
internal static string CombinePaths(string firstPath, string secondPath)
{
return Path.Combine(firstPath, secondPath);
}
- Шо это было?!!
- Cэкономили точку. 1188 раз )))))
+1
public class FileStorage {
public FileStorage() {
try {
if (String.IsNullOrEmpty(Common.GlobalVariables.FileStorage)) {
throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorage", String.Empty));
}
if (!Directory.Exists(Common.GlobalVariables.FileStorage)) {
DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage);
if (!di.Exists) {
throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorageDir", String.Empty));
}
}
} catch (Exception er) {
throw new Exception(er.Message);
}
}
public String CreateFileDirectory() {
try {
int iIdx = 0;
Boolean bIsCreated = false;
while (!bIsCreated && iIdx < 10) {
String sDir = Guid.NewGuid().ToString("N").ToLower();
sDir = sDir.Substring(0, 2);
if (!Directory.Exists(Common.GlobalVariables.FileStorage + sDir + @"\")) {
DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage + sDir + @"\");
if (di.Exists) {
return Common.GlobalVariables.FileStorage + sDir + @"\";
}
}
iIdx++;
}
return null;
} catch (Exception er) {
throw new Exception(er.Message);
}
}
}
может я чего не понимаю, но зачем?
+2
public struct TotalStat
{
public int Level { get; set; }
public int Type { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public int VAL_01_1 { get; set; }
public int VAL_01_2 { get; set; }
public int VAL_01_3 { get; set; }
public int VAL_01_4 { get; set; }
public int VAL_51_1 { get; set; }
public int VAL_51_2 { get; set; }
public int VAL_51_3 { get; set; }
public int VAL_51_4 { get; set; }
public TotalStat[] Children;
public FontWeight FontWeight
{
get
{
return Type == 2 ? FontWeights.Bold : FontWeights.Normal;
}
}
public Thickness Margin
{
get
{
return new Thickness(this.Level * 10, 0, 0, 0);
}
}
public string CNT_01
{
get
{
var v = VAL_01_1 + VAL_01_2 + VAL_01_3 + VAL_01_4;
return v.ToString();
}
}
public string CNT_51
{
get
{
var v = VAL_51_1 + VAL_51_2 + VAL_51_3 + VAL_51_4;
return v.ToString();
}
}
public string CNT_01_1
{
get
{
if (Type == 1) return "";
if (VAL_01_1 == 0) return "-";
return VAL_01_1.ToString();
}
}
public string CNT_01_2
{
get
{
if (Type == 1) return "";
if (VAL_01_2 == 0) return "-";
return VAL_01_2.ToString();
}
}
public string CNT_01_3
{
get
{
if (Type == 1) return "";
if (VAL_01_3 == 0) return "-";
return VAL_01_3.ToString();
}
}
//В том же духе до CNT_51_4
public static TotalStat operator +(TotalStat t, TotalStat c)
{
t.VAL_01_1 += c.VAL_01_1;
t.VAL_01_2 += c.VAL_01_2;
t.VAL_01_3 += c.VAL_01_3;
t.VAL_01_4 += c.VAL_01_4;
t.VAL_51_1 += c.VAL_51_1;
t.VAL_51_2 += c.VAL_51_2;
t.VAL_51_3 += c.VAL_51_3;
t.VAL_51_4 += c.VAL_51_4;
return t;
}
}
На лабу похоже, да? А вот это не лаба. Сириозный праэкт для суровой организации (продолжение).
+2
if (_viewModel.ShowColumnChooser && _viewModel.UseDefaultColumnChooser)
//...
else {
if (!_viewModel.ShowColumnChooser)
return;
//...
}
Сэмпл платного фреймворка Syncfusion. Да, на этом коде они объясняют, как использовать их классы. А в поддержке отвечают сплошные косноязычные Раджеши Кутрапалли.
+4
phases.Where(phase => phase == null || phase.Trim().Length == 0)
Нашёл в своём проекте, эта строка прошла code review. phase - это строка.
0
WriteBuffer = enc.GetBytes("$ FETCH " + number + " BODY[HEADER]\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
ListMessage = strReader.ReadLine();
//...
while ((ListMessage.IndexOf("$ OK ") == -1) && (ListMessage.IndexOf("$ BAD ") == -1))
{
//Типа там читаем всякие заголовки и прочие бла-бла
if (ListMessage.IndexOf("filename=") > -1)
{
temp = ListMessage.Replace("filename=", "");
temp = temp.Trim();
file_name = temp;
is_file = 1; temp = ""; is_att = 1;
}
//...
ListMessage = strReader.ReadLine();
continue;
}
//...
WriteBuffer = enc.GetBytes("$ FETCH " + number + " BODY[TEXT]\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
ListMessage = strReader.ReadLine();
temp = "";
end_file = 0;
body = "";
if (ListMessage.IndexOf("$ BAD ") == -1) ListMessage = strReader.ReadLine();
if (ListMessage == "")
is_body = 0;
else
is_body = 1;
while ((ListMessage.IndexOf("$ OK ") == -1) && (ListMessage.IndexOf("$ BAD ") == -1))
{
if (is_body == 1)
{
if (ListMessage == "")
is_body = 0;
else
body = body + ListMessage;
}
if ((is_att == 1) && (end_file == 0))
{
if (is_file == 1)
{
if (ListMessage.IndexOf("--") > -1)
end_file = 1;
else
temp = temp + ListMessage;
}
if (ListMessage == "")
{
is_file = 1;
}
}
if (ListMessage.IndexOf("Content-Disposition: attachment;") > -1)
{
is_att = 1;
}
//...
ListMessage = strReader.ReadLine();
continue;
}
if (is_att==0)
{
//А тут ничего интересного, просто декодирование из Base64 и сохранение в файл
}
Следите за булями (точнее, их суррогатами).
ЗЫ: да, я уже выкладывал кусок из того же модуля, и там уже были некоторые куски, которые попали и сюда тоже.
0
public override void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (String.Equals(propertyName, "[USERANKTARIFF]", StringComparison.CurrentCultureIgnoreCase))
{
if (((bool)this["USERANKTARIFF"]) == true)
{
this["SALARYLEVEL"] = null;
}
else
{
this["RANKTARIFF"] = null;
}
}
}
Продолжение хардкора. Мы любим ебаться с обжектами и кастами!
+2
public void Initiaize(long buffersCount, int bufferSize)
{
if (bufferSize > Int32.MaxValue)
{
throw new ArgumentOutOfRangeException("bufferSize", bufferSize,
"Buffers size can't be grater than Int32 max value");
}
_bufferSize = bufferSize;
}