- 1
t.GetProperty(item.Split('=')[0].Trim()).SetValue(this, item.Split('=')[1].Trim(), null);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+134.6
t.GetProperty(item.Split('=')[0].Trim()).SetValue(this, item.Split('=')[1].Trim(), null);
Инициализация свойства из строик формата имя=значение
+89.5
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);
}
}
}
Мы пойдем другим путем.
Некоторые скажут что в представленном контексте абсолютно нормальный код, я все же не соглашусь
+943.6
try
{
if (CheckLoginLenght())
{
if (CheckPassLenght())
{
if (CheckEmptyEMail())
{
if (CheckIsPassEquals())
{
if (CheckEmptyLogin())
{
if (CheckLoginInBase())
{
if (RadCaptcha1.IsValid)
{
if (CheckMailInBase())
{
Проверка данных введенных для регситарции (ASP.NET)
+123.8
//...
if ( (x > 0) || (x == 0))
{
//....
}
Человек явно с головой не дружит
+128.8
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;
}
Не скажу что это такой уж говнокод, но что то говнистое в нем есть =)
+135.6
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() { }
}
Вот такой вот универсальный сиглтон нашел в проекте
+98.6
private bool IsNamesAreEqual(string itemName, string nodeName) { ... }
Правда это скорее относится к английскому языку, нежели к шарпу.
Иногда полезно перечитывать давно написаный код, много нового узнаешь )))
+129.7
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;
}
+136.3
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]);
}
Удаление дубликатов в не отсортированном списке.... Это реально упростить?
+101.2
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 чтобы выбрать всех детишек. Спросил у кастомера можно ли ограничить вложенность. Он согласился ;).. На свою голову ;).