每个methodname值对应于c#类中的图像过滤器方法,每个方法参数是以逗号分隔的数值列表.
我想使用反射来调用methodname及其相应的方法参数列表.
以下是图像过滤器类的一部分:
namespace ImageFilters{ public class Filters { private static Bitmap mBMP; public Bitmap BMP { get { return mBMP; } set { mBMP = value; } } public static voID Filtercolors(string[] paramList) { mBMP = Filtercolors(mBMP,Convert.ToInt16(paramList[0].ToString()),Convert.ToInt16(paramList[1].ToString()),Convert.ToInt16(paramList[2].ToString()),Convert.ToInt16(paramList[3].ToString()),Convert.ToInt16(paramList[4].ToString()),Convert.ToInt16(paramList[5].ToString()) ); } public static Bitmap Filtercolors(Bitmap bmp,int RedFrom,int RedTo,int GreenFrom,int GreenTo,int BlueFrom,int Blueto,byte RedFill = 255,byte GreenFill = 255,byte BlueFill = 255,bool FillOutsIDe = true) { AForge.Imaging.Filters.colorFiltering f = new AForge.Imaging.Filters.colorFiltering(); f.FillOutsIDeRange = FillOutsIDe; f.Fillcolor = new AForge.Imaging.RGB(RedFill,GreenFill,BlueFill); f.Red = new AForge.IntRange(RedFrom,RedTo); f.Green = new AForge.IntRange(GreenFrom,GreenTo); f.Blue = new AForge.IntRange(BlueFrom,Blueto); return f.Apply(bmp); }
这是我使用的代码使用Reflection:
private static voID ApplyFilters(ref Bitmap bmp,dictionarIEs.FilterFIElds pFilters) { for(int i = 0; i < pFilters.Detail.Length; i++) { Type t = typeof(ImageFilters.Filters); MethodInfo mi = t.getmethod(pFilters.Detail[i].Methodname); ImageFilters.Filters f = new ImageFilters.Filters(); f.BMP = bmp; string[] parameters = pFilters.Detail[i].MethodParameters.Split(','); mi.Invoke(f,parameters); } }
每个图像都不使用过滤器处理,并使用两组不同的过滤器(来自数据库).以下循环处理过滤器:
foreach (keyvaluePair<string,dictionarIEs.FilterFIElds> item in dictionarIEs.Filters) { bmp = OriginalBMP; ApplyFilters(ref bmp,item.Value); }
我的问题是,当它在循环中遇到ApplyFilters时,它会给我以下错误:
“找不到方法:’VoID ImageFilters.Filters.set_BMP(System.Drawing.Bitmap)’.它甚至不允许我进入ApplyFilters方法.
我绝对没有在我的数据库表中有一个名为“set_BMP”的方法.
有任何想法吗?
解决方法 您得到的错误是JIT错误.在运行时,您尝试调用ApplyFilters.然后,运行时尝试将ApplyFilters方法从MSIL编译为机器代码.在那个时间点,它看到你在Filters类上使用了一个名为BMP的属性,但它找不到它(或者找不到setter).因此它无法编译该方法而无法调用它,这就是您的断点未被命中的原因.看来BMP属性(或其setter)在运行时不存在.这通常是因为在运行时加载了不同版本的程序集 – 您使用具有此属性的一个版本对其进行编译,但在运行它时,引用的程序集不包含该属性.
仔细检查目录中存在的程序集是否是最新的,并且是您期望的正确版本.
总结以上是内存溢出为你收集整理的c# – 具有多个参数类型的反射全部内容,希望文章能够帮你解决c# – 具有多个参数类型的反射所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)