Last active
February 1, 2021 07:52
-
-
Save pishangujeniya/4398db8b9374b081b0670ce746f34cbc to your computer and use it in GitHub Desktop.
Inline Interface Implementation as Java in C#
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 MainClass : IMyInterface { | |
public void paymentProceed () { | |
MyClass MyClass = new MyClass (); | |
// Java Inline Style | |
MyClass.someMethod ("INPUT TEXT", new MyClassImplementor ( | |
(object resp) => { | |
Debug.WriteLine ("INTERNAL LAMBDA CALLBACK for " + resp.ToString ()); | |
} | |
)); | |
// C# Style | |
MyClass.someMethod ("PISHANG", this); | |
} | |
void IMyInterface.InterfaceResponse (object data) { | |
Debug.WriteLine ("As C# Style for "+ data.ToString ()); | |
//throw new NotImplementedException(); | |
} | |
} |
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 MyClass { | |
public void someMethod (string id, IMyInterface _iMyInterface) { | |
string someResponse = "RESPONSE FOR " + id; | |
_iMyInterface.InterfaceResponse (someResponse); | |
} | |
} | |
public interface IMyInterface { | |
void InterfaceResponse (object data); | |
void InterfaceResponse2 (object data, string x); | |
} | |
public class MyInterfaceImplementor : IMyInterface { | |
private readonly Action<object> actionname; | |
private readonly Action<object, string> actionInterfaceResponse2; | |
public MyInterfaceImplementor (Action<object> InterfaceResponse) { | |
this.actionname = InterfaceResponse; | |
} | |
public MyInterfaceImplementor(Action<object> interfaceResponseMethod, Action<object, string> interfaceResponseMethod1) { | |
this.actionname = interfaceResponseMethod ?? throw new ArgumentNullException(nameof(interfaceResponseMethod)); | |
this.actionInterfaceResponse2 = interfaceResponseMethod1 ?? throw new ArgumentNullException(nameof(interfaceResponseMethod1)); | |
} | |
public void InterfaceResponse (object data) { | |
this.actionname (data); | |
} | |
public void InterfaceResponse2(object data, string x) { | |
this.actionInterfaceResponse2(data, x); | |
} | |
} |
Author
pishangujeniya
commented
Jun 26, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment