This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using System.Windows.Media.Imaging; | |
/// <summary> | |
/// Edit Exif metadata. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const int countThreshold = 64; | |
public static IEnumerable<TSource> MergeSort<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) | |
{ | |
if (source == null) | |
throw new ArgumentNullException("source"); | |
var countFull = source.Count(); | |
if (countFull < countThreshold) | |
return source.OrderBy(keySelector); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Windows.Media; | |
public static class WindowsEightChromeColor | |
{ | |
public static Color? GetChromeColor() | |
{ | |
bool isEnabled; | |
var hr1 = DwmIsCompositionEnabled(out isEnabled); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class VisualTreeHelperAddition | |
{ | |
public static IEnumerable<T> GetDescendents<T>(this DependencyObject parent) where T : DependencyObject | |
{ | |
if (parent == null) | |
yield break; | |
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) | |
{ | |
var child = VisualTreeHelper.GetChild(parent, i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Windows; | |
using System.Windows.Interop; | |
using System.Windows.Media; | |
public class PerMonitorDpiProperty : DependencyObject | |
{ | |
public static PerMonitorDpiProperty GetAttachedProperty(DependencyObject obj) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void TestMethod(IEnumerable<string> names) | |
{ | |
List<string> nameList = names as List<string> ?? names.ToList(); //OK | |
int nameCount = (names as List<string> ?? names.ToList()).Count; //OK | |
//Case 1 | |
nameList.ForEach(x => Console.WriteLine(x)); //OK | |
//Case 2 | |
(names as List<string> ?? names.ToList()).ForEach(x => Console.WriteLine(x)); //OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Runtime.CompilerServices | |
{ | |
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] | |
public class CallerMemberNameAttribute : Attribute | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using System.Windows.Forms; | |
public class BatteryStatus : INotifyPropertyChanged | |
{ | |
public BatteryChargeStatus BatteryChargeStatus => SystemInformation.PowerStatus.BatteryChargeStatus; // Flag | |
public int BatteryFullLifetime => SystemInformation.PowerStatus.BatteryFullLifetime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public class StreamCopy | |
{ | |
private const int bufferSize = 1024 * 1024; // 1MiB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
public static class BytesExtension | |
{ | |
public static byte[] SequenceReplace(this byte[] source, byte[] oldValue, byte[] newValue, int maxCount = -1) | |
{ | |
var sourceIndices = SequenceIndicesOf(source, oldValue, maxCount).ToArray(); |
OlderNewer