- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public static bool MegaDispose(this IDisposable thіs)
{
if (thіs != null)
{
thіs.Dispose();
return true;
}
return false;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+976
public static bool MegaDispose(this IDisposable thіs)
{
if (thіs != null)
{
thіs.Dispose();
return true;
}
return false;
}
+972
str3 = "Insert Into orderList(OrderNo,Date,StoreName,TagCode,Size,Colour,TwoSidedEngraving,
EngravingOptions,PetsName,PetsNameTwoSide,Phone1,Phone1TwoSide,Phone2,Phone2TwoSide,
Phone3,Phone3TwoSide,OwnersFirstName,OwnersLastName,StreetAddress,Suburb,State,ZipCode,
Country,MStreetAddress,MSuburb,MState,MZipCode,MCountry,OwnersFirstNameTwoSide,
OwnersLastNameTwoSide,StreetAddressTwoSide,SuburbTwoSide,StateTwoSide,ZipCodeTwoSide,
flag,Other9,idcust,Receiver,demo,databasename,isonline,faxfile) values(N'" + this.Request.Form["Orderno"] +
"',Getdate(),N'" + Strings.Replace(this.Request.Form["storename"],"'", "''", 1, -1, CompareMethod.Binary) +
"',N'" + str + "',N'" + this.Request.Form["tagSize"] + "',N'" + this.Request.Form["tagcolor"] + "',N'" +
this.Request.Form["TwoSide"] + "',N'" + str2 + "',N'" +
Strings.Replace(Strings.Replace(this.Convert(this.Request.Form["PetsName"]), "'", "''", 1, -1,
CompareMethod.Binary), "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
this.Request.Form["chbPetsName"] + "',N'" +
Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone1"])), "'", "''",
1, -1, CompareMethod.Binary), "\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
this.Request.Form["chbPhone1"] + "',N'" +
Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone2"])),
"'", "''", 1, -1, CompareMethod.Binary),
"\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" + this.Request.Form["chbPhone2"] + "',N'" +
Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["Phone3"])),
"'", "''", 1, -1, CompareMethod.Binary),
"\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" + this.Request.Form["chbPhone3"] + "',N'" +
Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["FirstName"])),
"'", "''", 1, -1, CompareMethod.Binary),
"\"", "\"", 1, -1, CompareMethod.Binary) + "',N'" +
Strings.Replace(Strings.Replace(Strings.UCase(this.Convert(this.Request.Form["LastName"])),
"'", "''", 1, -1, CompareMethod.Binary),
<ну и так далее...>
this.Response.Write(function.ExecuteSql(str3));
+122
public class ASyncFileHashAlgorithm
{
protected HashAlgorithm hashAlgorithm;
protected byte[] hash;
protected bool cancel = false;
protected int bufferSize = 4096;
public delegate void FileHashingProgressHandler (object sender, FileHashingProgressArgs e);
public event FileHashingProgressHandler FileHashingProgress;
public ASyncFileHashAlgorithm(HashAlgorithm hashAlgorithm)
{
this.hashAlgorithm = hashAlgorithm;
}
public byte[] ComputeHash(Stream stream)
{
cancel = false;
hash = null;
int _bufferSize = bufferSize; // this makes it impossible to change the buffer size while computing
byte[] readAheadBuffer, buffer;
int readAheadBytesRead, bytesRead;
long size, totalBytesRead = 0;
size = stream.Length;
readAheadBuffer = new byte[_bufferSize];
readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
totalBytesRead += readAheadBytesRead;
do
{
bytesRead = readAheadBytesRead;
buffer = readAheadBuffer;
readAheadBuffer = new byte[_bufferSize];
readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
totalBytesRead += readAheadBytesRead;
if (readAheadBytesRead == 0)
hashAlgorithm.TransformFinalBlock(buffer, 0, bytesRead);
else
hashAlgorithm.TransformBlock(buffer, 0, bytesRead, buffer, 0);
FileHashingProgress(this, new FileHashingProgressArgs(totalBytesRead, size));
} while (readAheadBytesRead != 0 && !cancel);
if(cancel)
return hash = null;
return hash = hashAlgorithm.Hash;
}
public int BufferSize
{
get
{ return bufferSize; }
set
{ bufferSize = value; }
}
public byte[] Hash
{
get
{ return hash; }
}
public void Cancel()
{
cancel = true;
}
public override string ToString ()
{
string hex = "";
foreach(byte b in Hash)
hex += b.ToString("x2");
return hex;
}
}
Очень интересная реализация "асинхронного" хэширования.
+128
private static void ListXmlSerialize<T>(List<T> UserList, string Obj, string FileName)
{
object obj = new object();
lock (obj)
{
XmlSerializer UserXmlFormat = new XmlSerializer(typeof(List<T>), Obj);
Stream UserFileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write);
UserXmlFormat.Serialize(UserFileStream, UserList);
UserFileStream.Close();
}
}
+965
string[] val = ...;
if (val.Length > 0)
{
return val[1];
}
else
return string.Empty;
IndexOutOfRangeException
+963
private void SetStat(QALog stat, ArtIntLnkLog log)
{
stat.AllLinks += 1;
if (log.Command == 5)
stat.ErrLinks += 1;
if (log.Command == 1)
stat.SetLinks += 1;
if (log.Command == 2)
stat.ReSetLinks += 1;
}
Такое вот чудное обновление статистики, где константы, switch и инкрементация непонятно.
+133
if (ID_Pers == (decimal)r["Код_ФизЛица"])
query = new SqlCommand("UPDATE СписокФизическихЛиц SET ДатаРождения=CONVERT(DateTime,'" + Date + "',104) where ID='" + r["Код_ФизЛица"].ToString() + "'", conn);
else
query = new SqlCommand("UPDATE СписокФизическихЛиц SET ДатаРождения=CONVERT(DateTime,'" + Date + "',104) where ID='" + ID_Pers.ToString() + "'", conn);
Классический говнокод.
+116
repositoryBugzilla.Open();
repositoryBugzilla.Close();
Вот такой код я нашел у себя в проекте.
+137
xxx: Скажите пожалуйста нубоюзеру, как в сишарпе извлечь корень определённой степени?
yyy: http://msdn.microsoft.com/ru-ru/library/system.math.sqrt.aspx (Math.Sqrt, Возвращает квадратный корень из указанного числа.)
xxx: Спасибо, но желательно бы не только >квадратный< корень, но и заданной степени.
yyy: Делай через циклы или рекурсивно.
double SuperSquare(double number, int n)
{
double result = number;
for(int i = 0; i < n; i++)
{
result = Math.Sqrt(result)
}
return result;
}
// Както так
Инновационный способ вычислять корень заданной степени.
+123
public override void KeyUp(KeyboardEventArgs e)
{
if(subact.KeyUp(e)) return;
}
public override void KeyDown(KeyboardEventArgs e)
{
if(subact.KeyDown(e)) return;
}