View gist:4707957
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
/// <summary> | |
/// Detect whether the context is dirty (i.e., there are changes in entities in memory that have | |
/// not yet been saved to the database). | |
/// </summary> | |
/// <param name="context">The database context to check.</param> | |
/// <returns>True if dirty (unsaved changes); false otherwise.</returns> | |
public static bool IsDirty(this DbContext context) | |
{ | |
Contract.Requires<ArgumentNullException>(context != null); |
View gist:4708009
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 int Exp(this int x, int y) | |
{ | |
int result = 1; | |
while (y > 0) | |
{ | |
if ((y & 1) != 0) | |
{ | |
result *= x; | |
} | |
y >>= 1; |
View gist:5030215
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 class SubtractConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, string language) | |
{ | |
return (double)value - System.Convert.ToDouble(parameter); | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, string language) | |
{ | |
return (double)value + System.Convert.ToDouble(parameter); |
View gist:5219157
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
BindingOperations.GetBindingExpressionBase(dependencyObject, dependencyProperty).UpdateTarget(); |
View CallMeMaybeAspect.cs
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
/// <summary> | |
/// An aspect for use in testing of variable-reliability conditions, by succeeding in calling the | |
/// underlying method only part of the time, returning an exception the rest of the time. | |
/// </summary> | |
[Serializable] | |
public class CallMeMaybeAspect : MethodInterceptionAspect | |
{ | |
private readonly Type exceptionType; | |
private readonly double probability; |
View SingletonConstraint.cs
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 ArkaneSystems.Arkane.Aspects | |
{ | |
/// <summary> | |
/// A constraint which verifies that the class to which it is applied obeys the Singleton pattern | |
/// we use. | |
/// </summary> | |
/// <remarks> | |
/// The singleton pattern is as follows: | |
/// private static readonly Lazy{$CLASS$} lazy = new Lazy{$CLASS$} (() => new $CLASS$()); | |
/// public static $CLASS$ Instance { get { return lazy.Value; } } |
View gist:6695088
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
<xctk:EditorDefinitionCollection x:Key="StandardPropertyEditors" x:Shared="False"> | |
<xctk:EditorTemplateDefinition TargetProperties="{arkane:Nullable TypeName=system:Boolean}" > | |
<xctk:EditorTemplateDefinition.EditingTemplate> | |
<DataTemplate> | |
<CheckBox IsChecked="{Binding Value}" IsThreeState="True" /> | |
</DataTemplate> | |
</xctk:EditorTemplateDefinition.EditingTemplate> | |
</xctk:EditorTemplateDefinition> | |
<xctk:EditorTemplateDefinition TargetProperties="{arkane:Nullable system:DateTime}"> | |
<xctk:EditorTemplateDefinition.EditingTemplate> |
View gist:6695095
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
/// <summary> | |
/// XAML markup extension to make it possible to reference nullable types. | |
/// </summary> | |
[MarkupExtensionReturnType (typeof (Type))] | |
public class NullableExtension : TypeExtension | |
{ | |
/// <summary> | |
/// Initializes a new instance of the NullableExtension class. | |
/// </summary> | |
public NullableExtension () |
View ApartmentAspect.cs
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 ArkaneSystems.Arkane.Aspects | |
{ | |
/// <summary> | |
/// An aspect to execute a function on a thread in the given COM apartment state. | |
/// </summary> | |
[Serializable] | |
public sealed class ApartmentAspect : MethodInterceptionAspect | |
{ | |
private readonly ApartmentState desiredState; | |
private Exception returnException; |
View UnlessDisposed
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 ArkaneSystems.Arkane.Aspects | |
{ | |
/// <summary> | |
/// An aspect which blocks calls to all public methods of a class implementing <see cref="IDisposable"/> once the class has | |
/// been disposed, instead throwing <see cref="ObjectDisposedException"/>. The class upon which this aspect is placed must | |
/// use the common pattern in which a private boolean field named 'disposed' is used to hold the disposed state. | |
/// </summary> | |
/// <remarks> | |
/// Private methods, static methods, and finalizers can still run when the class is disposed, as they may | |
/// be required for cleanup. |
OlderNewer