- 1
- 2
- 3
- 4
- 5
- 6
- 7
Func<int,int> fact = (int i_in) => i_in;
fact = (int i_in) =>
{
if (i_in>1) return (fact(i_in-1)*i_in);
else return (1);
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
Func<int,int> fact = (int i_in) => i_in;
fact = (int i_in) =>
{
if (i_in>1) return (fact(i_in-1)*i_in);
else return (1);
};
+2
public ActionResult Exception()
{
throw new Exception("You better not to execute this!");
}
нашел говнокод, оставленный прошлым архитектором)
0
<cms:CMSWebPartZone ZoneID="AnalZone" runat="server" />
ASP.NET, аналитика
+2
switch (button.Tag.ToString()) {
case "Ezp":
{
if (nowLayer.OpenedFiles.Count == 0)
{
nowLayer.OpenedFiles = new List<ExemplarFile> { new ExemplarFile("") };
}
if (nowLayer.OpenedFiles[0].EdinZemleps == null)
{
nowLayer.OpenedFiles[0].EdinZemleps = new List<EdinZemlep>();
}
var strName = ":ЕЗ" + (nowLayer.OpenedFiles[0].EdinZemleps.Count + 1);
nowLayer.OpenedFiles[0].EdinZemleps.Add(new EdinZemlep(strName) { Status = StatusEnum.Образуемый });
_ezpListTreeView.Add(new EzpTreeView { NameEzp = strName, ContourList = new List<ContourTreeView>(), ParcelList = new List<PartZuTreeView>(), IsEzpVisible = true, IsSelectedEzp = false } );
_dictionaryEzpTreeViewFile.Add(_ezpListTreeView[_ezpListTreeView.Count - 1], nowLayer.OpenedFiles[0]);
_dictionaryEzpTreeViewEdinZemlep.Add(_ezpListTreeView[_ezpListTreeView.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[nowLayer.OpenedFiles[0].EdinZemleps.Count - 1]);
break;
}
case "ContourEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((button.Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
var strName = (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].CadNum != "" ? nowLayer.OpenedFiles[0].EdinZemleps[indexEz].CadNum : nowLayer.OpenedFiles[0].EdinZemleps[indexEz].LastName) + "(" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours.Count + 1) + ")";
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].AddContour(new Contour(strName) { Status = StatusEnum.Образуемый });
if (_ezpListTreeView[indexEz].ContourList == null)
{
_ezpListTreeView[indexEz].ContourList = new List<ContourTreeView>();
}
strName = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours.Last().Name;
_ezpListTreeView[indexEz].ContourList.Add(new ContourTreeView { NameContour = strName, IsContourVisible = true, IsSelectedContour = false } );
for (var i = 0; i < _ezpListTreeView[indexEz].ContourList.Count; i++)
{
_ezpListTreeView[indexEz].ContourList[i].NameContour = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours[i].Name;
}
break;
}
case "ZuEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((button.Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
var strName = ":ЗУ" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Count + 1);
if (_ezpListTreeView[indexEz].ParcelList == null)
{
_ezpListTreeView[indexEz].ParcelList = new List<PartZuTreeView>();
}
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Add(new Parcel(strName) { Status = StatusEnum.Образуемый });
_ezpListTreeView[indexEz].ParcelList.Add(new PartZuTreeView { NamePartZu = strName, ContourList = new List<ContourTreeView>(), PartList = new List<PartTreeView>(), IsPartZuVisible = true, IsSelectedPartZu = false });
_dictionaryPartZuTreeViewFile.Add(_ezpListTreeView[indexEz].ParcelList[_ezpListTreeView[indexEz].ParcelList.Count - 1], nowLayer.OpenedFiles[0]);
_dictionaryPartZuTreeViewParcel.Add(_ezpListTreeView[indexEz].ParcelList[_ezpListTreeView[indexEz].ParcelList.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Count - 1]);
break;
}
case "PartZuEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
indexZu = ((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Children.IndexOf((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid));
var sbPrclName = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].LastName + "/чзу" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Count + 1);
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Add(new Subparcel(sbPrclName) { Status = StatusEnum.Образуемый });
if (_ezpListTreeView[indexEz].ParcelList[indexZu].PartList == null)
{
_ezpListTreeView[indexEz].ParcelList[indexZu].PartList = new List<PartTreeView>();
}
_ezpListTreeView[indexEz].ParcelList[indexZu].PartList.Add(new PartTreeView { NamePart = sbPrclName, ContourList = new List<ContourTreeView>(), IsPartVisible = true, IsSelectedPart = _ezpListTreeView[indexEz].ParcelList[indexZu].IsSelectedPartZu });
_dictionaryPartTreeViewSubparcel.Add(_ezpListTreeView[indexEz].ParcelList[indexZu].PartList[_ezpListTreeView[indexEz].ParcelList[indexZu].PartList.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels[nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Count - 1]);
break;
}
и это продолжается, продолжается и продолжается....
−1
if (string.IsNullOrWhiteSpace(frmDelegatorLogin.ViewModel.Username))
throw new Exception("Не введен логин");
if (dbEmployee == null)
throw new Exception(string.Format("Не найден пользователь с логином \"{0}\"", frmDelegatorLogin.ViewModel.Username));
if (dbEmployee.DelegatePassword != frmDelegatorLogin.ViewModel.Password)
throw new Exception("Указан неверный пароль");
Вот такой вот новый метод валидации полей. Да, логин и пароль вводятся текстом, да, Exception потом ничем не ловится и пользователь получает unhandeled exception...
+3
protected override void mergeModels(IStuff Stuff, IStuff With)
{
var stuff = (MyObject)Stuff;
var with = (MyObject)With;
if (with.title != null)
stuff.title = with.title;
if (with.description != null)
stuff.description = with.description;
if (with.creator != null)
stuff.creator = with.creator;
if (with.status != null)
stuff.status = with.status;
if (with.client_name != null)
stuff.client_name = with.client_name;
if (with.client_mail != null)
stuff.client_mail = with.client_mail;
if (with.client_phone != null)
stuff.client_phone = with.client_phone;
if (with.folder != null)
stuff.folder = with.folder;
if (with.flag1 != null)
stuff.flag1 = with.flag1;
if (with.flag2 != null)
stuff.flag2 = with.flag2;
if (with.flag3 != null)
stuff.flag4 = with.flag3;
if (with.flag4 != null)
stuff.flag4 = with.flag4;
if (with.flag5 != null)
stuff.flag5 = with.flag5;
if (with.flag6 != null)
stuff.flag6 = with.flag6;
if (with.flag7 != null)
stuff.flag7 = with.flag7;
}
Копирование данных из одного объекта в другой.
+1
namespace SmalltalkPHP
{
class Model
{
internal static void CreateClass(string className)
{
ClassObject = new Class(className);
}
public static Class ClassObject { get; set; }
public class Message
{
public class Arguments
{
private SortedList arguments = new SortedList();
public void Add(String key, String name)
{
this.arguments.Add(key, name);
}
public String AsPhp()
{
String[] sb = new String[arguments.Count];
int i = 0;
foreach (DictionaryEntry arg in arguments)
{
if ((String)(arg.Value) != "") sb[i] = "$" + arg.Value;
i++;
}
return String.Join(", ", sb);
}
public String MakeFunctionName()
{
String[] sb = new String[arguments.Count];
int i = 0;
foreach (DictionaryEntry arg in arguments)
{
if ((String)(arg.Key) != "") sb[i] = (String)arg.Key;
i++;
}
return String.Join("_", sb);
}
}
public class Generic
{
public virtual string AsPhp()
{
return "nya";
}
}
public class Unary : Generic
{
public Unary(String name, Boolean isStatic = false)
{
this.Name = name;
this.Arguments = new Arguments();
this.IsStatic = isStatic;
}
public string Name { get; set; }
public Arguments Arguments { get; set; }
public Boolean IsStatic { get; set; }
public string PhpHeader
{
get
{
return String.Format("public {0}function {1}()", IsStatic ? "static " : "", Name);
}
}
public override string AsPhp()
{
return PhpHeader;
}
}
public class Keyword : Generic
{
public Keyword(Boolean isStatic = false)
{
this.Arguments = new Arguments();
this.IsStatic = isStatic;
}
public string Name { get { return Arguments.MakeFunctionName(); } }
public Arguments Arguments { get; set; }
public Boolean IsStatic { get; set; }
public string PhpHeader
{
get
{
return String.Format("public {0}function {1}({2})", IsStatic ? "static " : "", Name, Arguments.AsPhp());
}
}
public override string AsPhp()
{
return PhpHeader;
}
}
}
}
}
Писал конвертер Smalltalk -> PHP
Где-то еще валяется Smalltalk -> Erlang
−2
var indexes = T.Select((item, index) => new { Item = item, Index = index })
.Where(nitem => n.Item == 0).Select(nindex => n.Index).ToArray();
Console.WriteLine("Первый: {0}, последний: {1}", indexes.First(), indexes.Last());
Не слишком много item index? index item?
+2
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
public static bool IsNotNullOrEmpty(this string str)
{
return !string.IsNullOrEmpty(str);
}
экономия должна быть экономной
+1
langDict0.Add(eng , new string[] { ger, fre, spa, chi, rus, jap, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(ger , new string[] { eng, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(fre , new string[] { eng, ger, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(spa , new string[] { eng, ger, fre, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(chi , new string[] { eng });
langDict0.Add(rus , new string[] { eng });
langDict0.Add(jap , new string[] { eng });
langDict0.Add(por , new string[] { eng, ger, fre, spa, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(ita , new string[] { eng, ger, fre, spa, por, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(dut , new string[] { eng, ger, fre, spa, por, ita, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(pol , new string[] { eng, ger, fre, spa, por, ita, dut, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(swe , new string[] { eng, ger, fre, spa, por, ita, dut, pol, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(dan , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(fin , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(gre , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, cze, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(cze , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, rom, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(rom , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, hun, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(hun , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, slvk, bul, slvn, lit, lat, est, mal });
langDict0.Add(slvk, new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, bul, slvn, lit, lat, est, mal });
langDict0.Add(bul , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, slvn, lit, lat, est, mal });
langDict0.Add(slvn, new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, lit, lat, est, mal });
langDict0.Add(lit , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lat, est, mal });
langDict0.Add(lat , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, est, mal });
langDict0.Add(est , new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, mal });
langDict0.Add(mal, new string[] { eng, ger, fre, spa, por, ita, dut, pol, swe, dan, fin, gre, cze, rom, hun, slvk, bul, slvn, lit, lat, est });