system.reflection

Mono.Cecil - simple example how to get method body

爱⌒轻易说出口 提交于 2020-08-05 06:36:29
问题 I have been searching for a newbie question, but can't find a simple example. Can anyone give me a simple example how to get MethodBody into most available string result? Like: using Mono.Cecil; using Mono.Cecil.Cil; namespace my { public class Main { public Main() { // phseudo code, but doesnt work Console.Write( getMethod("HelloWorld").GetMethodBody().ToString() ); } public void HelloWorld(){ MessageBox.Show("Hiiiiiiiiii"); } } } 回答1: Start with reading your assembly: var path = "... path

Refer to a property name by variable

让人想犯罪 __ 提交于 2020-06-08 02:39:48
问题 Is there a way to refer to a property name with a variable? Scenario: Object A have public integer property X an Z, so... public void setProperty(int index, int value) { string property = ""; if (index == 1) { // set the property X with 'value' property = "X"; } else { // set the property Z with 'value' property = "Z"; } A.{property} = value; } This is a silly example so please believe, I have an use for this. 回答1: Easy: a.GetType().GetProperty("X").SetValue(a, value); Note that GetProperty(

Refer to a property name by variable

僤鯓⒐⒋嵵緔 提交于 2020-06-08 02:37:07
问题 Is there a way to refer to a property name with a variable? Scenario: Object A have public integer property X an Z, so... public void setProperty(int index, int value) { string property = ""; if (index == 1) { // set the property X with 'value' property = "X"; } else { // set the property Z with 'value' property = "Z"; } A.{property} = value; } This is a silly example so please believe, I have an use for this. 回答1: Easy: a.GetType().GetProperty("X").SetValue(a, value); Note that GetProperty(

Why does Assembly.GetTypes() require references?

别说谁变了你拦得住时间么 提交于 2020-03-14 11:08:30
问题 I want to get all of the types from my assembly, but I don't have the references, nor do I care about them. What does finding the interface types have to do with the references? and is there a way for me to get around this? Assembly assembly = Assembly.LoadFrom(myAssemblyPath); Type[] typeArray = assembly.GetTypes(); Throws: FileNotFoundException Could not load file or assembly 'Some referenced assembly' or one of its dependencies. The system cannot find the file specified. 回答1: Loading an

Why does Assembly.GetTypes() require references?

醉酒当歌 提交于 2020-03-14 11:07:02
问题 I want to get all of the types from my assembly, but I don't have the references, nor do I care about them. What does finding the interface types have to do with the references? and is there a way for me to get around this? Assembly assembly = Assembly.LoadFrom(myAssemblyPath); Type[] typeArray = assembly.GetTypes(); Throws: FileNotFoundException Could not load file or assembly 'Some referenced assembly' or one of its dependencies. The system cannot find the file specified. 回答1: Loading an

Why does Assembly.GetTypes() require references?

随声附和 提交于 2020-03-14 11:06:05
问题 I want to get all of the types from my assembly, but I don't have the references, nor do I care about them. What does finding the interface types have to do with the references? and is there a way for me to get around this? Assembly assembly = Assembly.LoadFrom(myAssemblyPath); Type[] typeArray = assembly.GetTypes(); Throws: FileNotFoundException Could not load file or assembly 'Some referenced assembly' or one of its dependencies. The system cannot find the file specified. 回答1: Loading an

Dynamically get a DbSet<T> by Entity class name

你说的曾经没有我的故事 提交于 2020-03-03 01:14:45
问题 I'm trying to use System.Reflections to get a DbSet<T> dynamically from its name. What I've got right now is: The DbSet name The DbSet 's Type stored on a variable The issue I'm facing comes out when trying to use the dbcontext.Set<T>() method, since (these are my tries so far): When I try to assign to <T> my DbSet Type , it throws me the following compilation error: "XXX is a variable but is used like a type" If I try with using both the Extension methods that you will find below in my code

Dynamically get a DbSet<T> by Entity class name

牧云@^-^@ 提交于 2020-03-03 01:12:30
问题 I'm trying to use System.Reflections to get a DbSet<T> dynamically from its name. What I've got right now is: The DbSet name The DbSet 's Type stored on a variable The issue I'm facing comes out when trying to use the dbcontext.Set<T>() method, since (these are my tries so far): When I try to assign to <T> my DbSet Type , it throws me the following compilation error: "XXX is a variable but is used like a type" If I try with using both the Extension methods that you will find below in my code

Entity Framework : Why this code doesn't work

﹥>﹥吖頭↗ 提交于 2020-02-08 09:39:45
问题 I'm using Entity Framework 6.0, DbContext. I'm using this method to copy an object and some related children: Imports System.Data.Objects Imports System.Data.Objects.DataClasses Imports System.Runtime.CompilerServices Public Module Entities <Extension()> Public Function CloneEntity(Of T As Class)(entity As T, context As ObjectContext, Optional include As List(Of IncludeEntity) = Nothing, Optional copyKeys As Boolean = False) As T Return CloneEntityHelper(entity, context, include, copyKeys)