Skip to content

Instantly share code, notes, and snippets.

Avatar

Fredrik Mörk fmork

View GitHub Profile
@fmork
fmork / delegate.combine.cs
Created Dec 13, 2017
Delegate.Combine with Action<string>
View delegate.combine.cs
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
View keybase.md

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 Jan 22, 2013
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" …
View gist:4594951
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 Aug 29, 2012
Structured search/replace problem
View gist:3508662
// 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: