title: How to execute C# code at runtime in Xamarin Android?
body: <p>I have a android application in Xamarin Studio.
  I want to execute a code placed in the text (string).
  For example <a href="https://stackoverflow.com/questions/4181668/execute-c-sharp-code-at-runtime-from-code-file">this</a> question help me in Visual Studio Windows application. But I cannot use this answer in Xamarin Android.
  This is my example in C# Windows application:</p>
  
  <pre><code>public class CodeLuncher
  {
      public static void LunchCSCode(string site, string typeName, string methosName)
      {
          try
          {
              var provider = CSharpCodeProvider.CreateProvider("c#");
              var options = new CompilerParameters();
              string text = new System.Net.WebClient().DownloadString(site);
  
              foreach (var item in GetRefrences(text))
              {
                  options.ReferencedAssemblies.Add(item);
              }
              string code = GetCode(text);
              var results = provider.CompileAssemblyFromSource(options, new[] { code });
              if (results.Errors.Count &gt; 0)
              {
                  foreach (var error in results.Errors)
                  {
                      Console.WriteLine(error);
                  }
              }
              else
              {
                  var t = results.CompiledAssembly.GetType(typeName);
                  t.GetMethod(methosName).Invoke(null, null);
              }
          }
          catch
          {
  
          }
      }
  
  
      static string[] GetRefrences(string text)
      {
          Regex regExp = new Regex("&lt;Refrences&gt;(.*?)&lt;/Refrences&gt;", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
          string str = regExp.Match(text).Groups[1].Value;
          List&lt;string&gt; retText = new List&lt;string&gt;();
          foreach (var item in str.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
          {
              retText.Add(item);
          }
          return retText.ToArray();
      }
  
      static string GetCode(string text)
      {
          Regex regExp = new Regex("&lt;CSharpCode&gt;(.*?)&lt;/CSharpCode&gt;", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
          string str = regExp.Match(text).Groups[1].Value;
          return str.Trim();
      }
  }
  </code></pre>