reflection

Assign any IEnumerable to object property

谁说胖子不能爱 提交于 2020-01-24 14:28:52
问题 I have a list of objects created using reflection, they are all the same type, however the type is unknown at compile time. I'm trying to figure out the best way of assigning this list (also using reflection) to an object property which could be any IEnumerable. List<object> ArrayList Custom : List<object> The only approach I have is to assume the property is an ICollection then loop through the IEnumerable and add each item. (See below, where list is the IEnumerable source, key is the string

Assign any IEnumerable to object property

本小妞迷上赌 提交于 2020-01-24 14:28:04
问题 I have a list of objects created using reflection, they are all the same type, however the type is unknown at compile time. I'm trying to figure out the best way of assigning this list (also using reflection) to an object property which could be any IEnumerable. List<object> ArrayList Custom : List<object> The only approach I have is to assume the property is an ICollection then loop through the IEnumerable and add each item. (See below, where list is the IEnumerable source, key is the string

InstantiationException while instantiating inner class using reflection. Why?

不羁岁月 提交于 2020-01-24 11:07:36
问题 i cant create B-Object, but why? public class AFactory { public int currentRange; private abstract class A { protected final Object range = currentRange; public int congreteRange = 28; } public class B extends A { public int congreteRange = 42; } synchronized A createNew(Class<? extends A> clazz) throws Exception { // EDIT: there is accessible default constructor currentRange = clazz.newInstance().congreteRange; return clazz.newInstance(); } public static void main(String[] args) throws

MissingMethodException thrown by GetExportedTypes

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 10:13:44
问题 I'm getting a MissingMethodException thrown when I call GetExportedTypes, the code: Assembly.LoadFrom(assemblyPath).GetExportedTypes(); The exception (names obfuscated): System.MissingMethodException was unhandled Message="Method not found: 'Void Namespace.IMyMethod.MyMethod(UInt32, Namespace.IMyOtherMethod ByRef, UInt32 ByRef)'." Source="mscorlib" StackTrace: at System.Reflection.Assembly._GetExportedTypes() at System.Reflection.Assembly.GetExportedTypes() at ConsoleApplication1.Program.Main

MissingMethodException thrown by GetExportedTypes

戏子无情 提交于 2020-01-24 10:13:01
问题 I'm getting a MissingMethodException thrown when I call GetExportedTypes, the code: Assembly.LoadFrom(assemblyPath).GetExportedTypes(); The exception (names obfuscated): System.MissingMethodException was unhandled Message="Method not found: 'Void Namespace.IMyMethod.MyMethod(UInt32, Namespace.IMyOtherMethod ByRef, UInt32 ByRef)'." Source="mscorlib" StackTrace: at System.Reflection.Assembly._GetExportedTypes() at System.Reflection.Assembly.GetExportedTypes() at ConsoleApplication1.Program.Main

getting a method object for a class with compile time checking (in java)

我只是一个虾纸丫 提交于 2020-01-24 08:21:30
问题 I would like to get a Method object similar to this: Method myMethod = MyClass.class.getDeclaredMethod("myDeclaredMethod",Arg1Class.class); But! I would like compile time checking of the existence of the method "myDeclaredMethod". I don't actually need to dynamically choose the method, I just need a reference to it so I can pass it to another method... similar to the way C has function pointers. I'd like to do something like this: #include <stdio.h> void helloWorld() { printf("hello\n"); }

Does the Entity Framework DbEntityEntry.Property method use reflection?

自作多情 提交于 2020-01-24 04:31:05
问题 This question is about this code: entityEntry.Property("WhateverProperty").CurrentValue = 1; I answered this question yesterday and if you notice in the comments to the question (not the answer), one of the members @gertarnold said this: entityEntry.Property("InsertedBy") doesn't use reflection, it reads the EF metadata. Sure it uses the EF metadata to figure out if the entity has that property but I am pretty sure somewhere down the line they would have to use reflection to set the property

Type constraints in Attributes

*爱你&永不变心* 提交于 2020-01-24 03:20:08
问题 I want to write my enum with custom attributes, for example: public enum SomeEnum: long { [SomeAttribute<MyClass1>] Sms = 1, [SomeAttribute<MyClass2>] Email = 2 } but attributes doesn't support generics. Well, the most similar solution is: public enum SomeEnum: long { [SomeAttribute(typeof(MyClass1))] Sms = 1, [SomeAttribute(typeof(MyClass2))] Email = 2 } And here is problem: I want Class1 to be inherited from ICustomInterface , so with generics I can write constraint: [AttributeUsage

Reflection & Application Design

久未见 提交于 2020-01-23 18:51:26
问题 Let me describe the problem and the solution i currently have and maybe you can help enlighten me on why it's a bad idea (assuming it is) and what i can do to make it a better system. right now i have 600 "rippers" that parse files and rip them to csv or other formats. the rippers all implement a common interface and base class. At the moment when a job is queued up depending on the configuration of that job a specific ripper is called using reflection. foreach (var stream in streams) { try {

Using Expression.Call with Queryable.Select with a type known only at runtime

本秂侑毒 提交于 2020-01-23 17:49:07
问题 I am trying to select a column from an IEnumerable collection that has a type known only to me at runtime. The only way I can think of using this is using LINQ expressions to build a dynamic call to Queryable.Select . However, I'm having a lot of trouble figuring out the proper syntax to accomplish this. An example of how I would do this in the happy-go-lucky world of knowing everything I need at compile time, my code would look like this: ' Create an IEnumerable(Of String) Dim strings = {