Skip to content

Instantly share code, notes, and snippets.

@maryamariyan
Created September 12, 2018 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maryamariyan/ba630243a30bed874afe9dab59d4551d to your computer and use it in GitHub Desktop.
Save maryamariyan/ba630243a30bed874afe9dab59d4551d to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- NOTE: Leave this file here and keep it in sync with list in dir.props. -->
<!-- The command-line doesn't need it, but the IDE does. -->
<packageSources>
<clear/>
<add key="myget.org dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
using System;
using System.Reflection.Emit;
using System.Globalization;
using System.Reflection;
namespace testNca
{
class Program
{
static void Main(string[] args)
{
Type[] mathArgs = { typeof(double), typeof(double) };
var powerOf = new DynamicMethod("PowerOf",
typeof(double),
mathArgs,
typeof(double).Module);
ILGenerator il = powerOf.GetILGenerator(256);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, typeof(Math).GetMethod("Pow"));
il.Emit(OpCodes.Ret);
powerOf.DefineParameter(1, ParameterAttributes.In, "base");
powerOf.DefineParameter(2, ParameterAttributes.Out, "exponent");
object[] invokeArgs = { 2, 5 };
object objRet = powerOf.Invoke(null, BindingFlags.ExactBinding, null, invokeArgs, new CultureInfo("en-us"));
ParameterInfo[] parameters = powerOf.GetParameters();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>testNca3</RootNamespace>
<NETCoreAppMaximumVersion>3.0</NETCoreAppMaximumVersion>
<RuntimeFrameworkVersion>3.0.0-preview1-26912-03</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment