Skip to content

Instantly share code, notes, and snippets.

View fmork's full-sized avatar

Fredrik Mörk fmork

View GitHub Profile
@fmork
fmork / delegate.combine.cs
Created December 13, 2017 18:21
Delegate.Combine with Action<string>
class Program
{
private static Action<string> stringAction;
static void Main(string[] args)
{
stringAction = new Action<string>(s => Console.WriteLine(s));
stringAction =(Action<string>) Delegate.Combine(stringAction, new Action<string>(s => Console.WriteLine(s)));
stringAction("Action called once"); // will be printed twice

Keybase proof

I hereby claim:

  • I am fmork on github.
  • I am fmork (https://keybase.io/fmork) on keybase.
  • I have a public key whose fingerprint is 4ECD 4DBA 2FE9 1795 9573 67C9 1EBC 7993 E16F E951

To claim this, I am signing this object:

@fmork
fmork / gist:4594951
Created January 22, 2013 14:18
I have this process which can be started and stopped. When started it will periodically perform some task, for which it will need to use an instance of another type that is created using some input, so it takes factory method as constructor input and it should invoke the factory each time it performs the task. In the test setting "periodically" …
public void Start_InvokesFactoryMethod()
{
// Arrange
// set up mocks and stuff needed (removed for brevity)
bool testTimedOut;
using (AutoResetEvent waitHandle = new AutoResetEvent(false))
{
Func<ISomeResource, IMyObject> myObjectProvider = resource =>
@fmork
fmork / gist:3508662
Created August 29, 2012 08:42
Structured search/replace problem
// going from this:
[DataMember]
public string SomeProperty { get; set; )
// ...should lead to this (adding Name property of attribute, using property name, but camel cased):
[DataMember(Name = "someProperty")]
public string SomeProperty { get; set; }
// This should not affect other attributes, so this: