- 1
- 2
- 3
- 4
- 5
- 6
- 7
if (_viewModel.ShowColumnChooser && _viewModel.UseDefaultColumnChooser)
//...
else {
if (!_viewModel.ShowColumnChooser)
return;
//...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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;
}
+2
public int Add(T item)
{
var p = m_parent as DataTreeRecord;
var i = item as DataTreeRecord;
if (m_newData == null || m_newData.Length == 0) m_newData = new T[8];
if (m_newData.Length <= m_newCount) Array.Resize(ref m_newData, m_newData.Length * 2);
if (p != null && i != null)
{
i.Parent = p;
}
m_newData[m_newCount++] = item;
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new T[1] { item }));
return this.Count - 1;
}
Мы любим ебаться с array. List? Зачем, он медленный! Мы напишем свой ORM с аррэями и PHP внутри няшного сишарпика.
Приходилось работать с этим проектом. Это просто кладезь говнокода, и это ещё не самое ужасное место.
+2
public interface ICachedObject<TCachedValue>
{
TCachedValue Value { get; set; }
}
public interface ICacheProvider<TCachedObject, TCachedValue>
where TCachedObject : ICachedObject<TCachedValue>
{
TCachedObject Get(string key);
void Set(string key, TCachedObject value);
void Remove(string key);
IEnumerable<TCachedObject> GetAll();
}
public class CachedEntityObject : ICachedObject<IEntity>
{
public EntityState State { get; set; }
public IEntity Value { get; set; }
}
public abstract class CacheProvider<TCache, TCachedObject, TCachedValue> :
ICacheProvider<TCachedObject, TCachedValue>
where TCache : IDictionary<string, TCachedObject>
where TCachedObject : ICachedObject<TCachedValue>
{
protected TCache Cache;
protected abstract void InitializationCache();
public abstract TCachedObject Get(string key);
public abstract void Set(string key, TCachedObject value);
public abstract void Remove(string key);
public abstract IEnumerable<TCachedObject> GetAll();
}
public class CacheEntity : CacheProvider<Dictionary<string, CachedEntityObject>, CachedEntityObject, IEntity>
{
public CacheEntity()
{
InitCache();
}
protected sealed override void InitCache()
{
Cache = new Dictionary<string, CachedEntityObject>();
}
public override CachedEntityObject Get(string key)
{
if (Cache[key] == null)
throw new NullReferenceException($"{nameof(key)} not found from cache list");
return Cache[key];
}
public override void Set(string key, CachedEntityObject value)
{
Remove(key);
Cache[key] = value;
}
public override void Remove(string key)
{
if (Cache.ContainsKey(key))
Cache.Remove(key);
}
public override IEnumerable<CachedEntityObject> GetAll()
{
return Cache.Values;
}
}
Кэш сущностей
+1
private int GetSroOper(MiscTransactionParams param)
{
if (param.ExpenseItem != null)
{
switch (param.ContractType)
{
case Entities.AT.ContractType.Undefined:
case Entities.AT.ContractType.TimeAndMaterials:
case Entities.AT.ContractType.Retainer:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.RecurringService:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.FixedPrice:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation500 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.Incident:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
default:
throw new InvalidOperationException("Unsupported ContractType value");
}
}
else
{
switch (param.ContractType)
{
case Entities.AT.ContractType.Undefined:
case Entities.AT.ContractType.TimeAndMaterials:
case Entities.AT.ContractType.Retainer:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
case Entities.AT.ContractType.RecurringService:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
case Entities.AT.ContractType.FixedPrice:
case Entities.AT.ContractType.Incident:
int sroOper = (int)param.OrderOperation.EntityRow()[Constants.ServiceOrderOperation.Field.SroOper];
switch (sroOper)
{
case 500:
case 600:
case 800:
case 850:
case 950:
return sroOper;
default:
throw new InvalidOperationException("Unsupported Operation value");
}
default:
throw new InvalidOperationException("Unsupported ContractType value");
}
}
}
Это наш сеньор написал
+3
public static bool AddStringIfNoExist(this List<string> strlist, string str)
{
if (str == "") return true;
foreach (string s in strlist) if (s == str) return true;
strlist.Add(str);
return false;
}
Hashset? А что это такое?
+5
public enum Status : byte
{
Disabled = 0,
Enabled
}
Мопед не мой, прислала боевая подруга из Канады, реальный проект за недетские деньги.
Лаконичности була не хватило, лучше свой енум сделать, чем писать bool IsEnabled.
KISS.