- 1
labelViewData.CreateTextPainterAccordingAllowedBoundsForLabels
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−2
labelViewData.CreateTextPainterAccordingAllowedBoundsForLabels
По Макконнеллу. Название метода должно отражать всю его суть и даже немножко деталей реализации. Ну как немножко, почти все.
0
internal static object CreateDefaultEqualityComparer(Type type)
{
Debug.Assert(type != null && type is RuntimeType);
object result = null;
var runtimeType = (RuntimeType)type;
// Specialize for byte so Array.IndexOf is faster.
if (type == typeof(byte))
{
result = new ByteEqualityComparer();
}
// If T implements IEquatable<T> return a GenericEqualityComparer<T>
else if (typeof(IEquatable<>).MakeGenericType(type).IsAssignableFrom(type))
{
result = CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericEqualityComparer<int>), runtimeType);
}
// Nullable does not implement IEquatable<T?> directly because that would add an extra interface call per comparison.
// Instead, it relies on EqualityComparer<T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.
else if (type.IsGenericType)
{
if (type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
result = TryCreateNullableEqualityComparer(runtimeType);
}
}
// The equality comparer for enums is specialized to avoid boxing.
else if (type.IsEnum)
{
result = TryCreateEnumEqualityComparer(runtimeType);
}
return result ?? CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(ObjectEqualityComparer<object>), runtimeType);
}
Код взят из CoreCLR mscorlib сырцов.
Внимание вопрос. Нахерна было писать эту обосгость когда данный метод легко делается генериком без какого либо вызова "невидимого" кода?
вот пример как все должно было быть
```
internal static object CreateDefaultEqualityComparer<T>()
{
// Specialize for byte so Array.IndexOf is faster.
if (typeof(T) == typeof(byte))
{
result = new ByteEqualityComparer();
}
// If T implements IEquatable<T> return a GenericEqualityComparer<T>
else if (typeof(IEquatable<T>).IsAssignableFrom( typeof(T)))
{
result new GenericEqualityComparer<T>();
}
// Nullable does not implement IEquatable<T?> directly because that would add an extra interface call per comparison.
// Instead, it relies on EqualityComparer<T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.
else if (typeof(T).IsGenericType)
{
if (typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>))
{
result = new NullableEqualityComparer<T>();
}
}
// The equality comparer for enums is specialized to avoid boxing.
else if (typeof(T).IsEnum)
{
result = TryCreateEnumEqualityComparer<T>();
}
return result ?? new ObjectEqualityComparer<T>();
}
```
−1
internal static object CopyImmutableSortedDictionary<K, V>(object original, ICopyContext context)
{
return original;
}
Microsoft Orleans https://github.com/dotnet/orleans
Копирование объекта в 2к17
0
public void GetMapping(DbObject obj, IEnumerable<DbObject> map = null, params string[] additional)
{
Mapper m = Mapper.Get(obj.DialectType);
switch (m.MapperType)
{
case MapperType.SST:
m.Initialize(null, additional);
break;
case MapperType.SSM:
m.Initialize(null, additional);
break;
default:
throw new ArgumentException();
}
// применение: этот метод возвращает List<Tupple<DbObject, DbObject>>
m.GetMappingByDialect(obj, map);
}
public enum MapperType
{
SST,
SSM,
}
Во-вторник - этот код, выбил меня из рабочего процесса на весь день ...
0
private void button1_Click(object sender, EventArgs e)
{
short number = 34;
folderBrowserDialog1.ShowDialog();
//fileListBox1.FileName = folderBrowserDialog1.SelectedPath;
DirectoryInfo myFolder = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
foreach (FileInfo T in myFolder.GetFiles())
{
number++;
string filename = T.Name;
File.Move(folderBrowserDialog1.SelectedPath + "" + filename, folderBrowserDialog1.SelectedPath + "" + number.ToString());
}
}
}
}
Решил я тут старые проекты копнуть...
0
public bool CheckBool(string value)
{
value = value.ToLower();
return !string.IsNullOrEmpty(value) && (value == "on" || value == "yes" || value == "1") ? true : false;
}
another variant ;D
−1
static string[] nums = new string[60] {
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59"
};
/// <summary>
/// Форматирует дату в dd.MM.yyyy
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static string ShortRuDateStr(ref DateTime date)
{
return string.Concat(nums[date.Day], ".", nums[date.Month], ".", YearToString(date.Year));
}
/// <summary>
/// Возвращает текущую дату в формате yyyyMMddHHmmss
/// </summary>
/// <returns></returns>
public static string Timestamp(ref DateTime date)
{
return string.Concat(YearToString(date.Year), nums[date.Month], nums[date.Day], nums[date.Hour], nums[date.Minute], nums[date.Second]);
}
public static string YearToString(int year)
{
return year.ToString().PadLeft(4, '0');
}
−1
private bool CheckBool(string value)
{
if (value == "on")
return true;
else
return false;
}
////
0
public static int[] GetRandomComStats(int level)
{
int[] stats = new int[3] { -1, -1, -1 };
int summ = (int)(1.2f * level);
int minStat = level / 3f - (level+ 1) / 10 < 0 ? 0 : (int)(level / 3f - (level + 1) / 10);
int maxStat = (int)(level / 3f + (level + 1) / 10);
Debug.Log("level: " + level + " min stat: " + minStat + " max stat: " + maxStat + " summ: " + summ);
int fr = Random.Range(0, 2);
int f2 = Random.Range(0, 3);
int f1 = 0;
stats[f2] = Random.Range(minStat, maxStat + 1);
for (int i = 0; i < 3; i++)
{
if (fr == 1 && stats[i] == -1)
{
if (summ - stats[f2] > maxStat) stats[i] = Random.Range(minStat, maxStat + 1);
else if (summ - stats[f2] < 0) stats[i] = 0;
else stats[i] = Random.Range(minStat, summ - stats[f2] + 1);
f1 = i;
goto label;
}
fr = 1;
}
label:
for (int i = 0; i < 3; i++)
{
if (stats[i] == -1)
{
if (summ < stats[f1] + stats[f2]) stats[i] = 0;
else if (summ - stats[f1] - stats[f2] > maxStat) stats[i] = maxStat;
else stats[i] = summ - stats[f1] - stats[f2];
Debug.Log(f1 + ": " + stats[f1]+ " " + f2 + ": " + stats[f2] + " " + i + ": " + stats[i]);
}
}
return stats;
}
Генерация рандомных стат персонажей в зависимости от уровня.
0
public bool isUnderpayment(double paymentValue)
{
if (paymentValue > 0)
return true;
return false;
}
Пятница, смеркалось.