Created
February 27, 2019 12:41
-
-
Save rodoufu/d1cc02e49b73133e11244e6ad8ddafb0 to your computer and use it in GitHub Desktop.
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 multi { | |
using System; | |
using System.Linq; | |
public class MultiEntryPointSmartContract : SmartContract { | |
public object Main (string name, params object[] parameters) { | |
if (name == null || name.Trim().Length == 0) { | |
throw new ArgumentNullException("The method name parameter can not be empty"); | |
} | |
var methods = this.GetType().GetMethods().Where(x => x.Name == name && x.GetParameters().Length == parameters.Length); | |
if (methods.Count() == 0) { | |
throw new ArgumentException(string.Format("No method found with the name '{0}' and {1} parameters", name, parameters.Count())); | |
} | |
if (methods.Count() > 1) { | |
throw new ArgumentException(string.Format("More than one method found with the name '{0}' and {1} parameters", name, parameters.Count())); | |
} | |
return methods.First().Invoke(null, parameters); | |
} | |
} | |
} |
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 multi { | |
using System; | |
using System.Linq; | |
// The usual way to do it | |
public class MultiOperationSmartContract : SmartContract { | |
public static object Main (string name, params object[] parameters) { | |
if (name == null || name.Trim().Length == 0) { | |
throw new ArgumentNullException("The method name parameter can not be empty"); | |
} | |
var methods = typeof(MultiOperationSmartContract).GetMethods().Where(x => x.Name == name && x.GetParameters().Length == parameters.Length); | |
if (methods.Count() == 0) { | |
throw new ArgumentException(string.Format("No method found with the name '{0}' and {1} parameters", name, parameters.Count())); | |
} | |
if (methods.Count() > 1) { | |
throw new ArgumentException(string.Format("More than one method found with the name '{0}' and {1} parameters", name, parameters.Count())); | |
} | |
return methods.First().Invoke(null, parameters); | |
} | |
public static int Teste () => 1; | |
public static int Teste1 (int v) => 2 + v; | |
public static int Teste1 () => 2; | |
public static void Hello(string a) => System.Console.WriteLine(a); | |
} | |
} |
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 multi { | |
using System; | |
using System.Linq; | |
public class MySmartContract : MultiEntryPointSmartContract { | |
public static int Teste () => 1; | |
public static int Teste1 (int v) => 2 + v; | |
public static int Teste1 () => 2; | |
public static void Hello(string a) => System.Console.WriteLine(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment