system.reflection

Cannot loop through list A(icollection) of generic type B where A and B both implement same interface

元气小坏坏 提交于 2019-12-13 21:07:21
问题 The intro is a bit tedious, but is just for clearity! Some might even learn something from it or get some handy insights. My question is found at the bottom. I really hope someone can help me! I have this interface public interface IEFEntity { object GetPKValue(); bool PKHasNoValue(); } All my automatic genereted EF classes implement this interface and implement the 2 methods. This is done via a separate file using partial classes so the implementation is not gone when regenerating the EF

List (top-level) declared variables in a Windows Form

妖精的绣舞 提交于 2019-12-13 15:41:00
问题 I can easily list all controls in a Form, after creating an instance of it. Is there any mechanism to list all declared variables or such objects? Perhaps I shall call it declarations . Only top-level declarations are enough. Let's assume we have MyForm Form with such top-level declarations: Dim Town as String Dim ZIP as String Dim StreetName as String Dim StreetNo as String Public dtCountries as DataTable Public LstCities as List(Of String) ... Pseudo-code example: Dim MyForm as New MyForm '

Could not find or load assembly "tmpAssembly,

瘦欲@ 提交于 2019-12-13 15:26:59
问题 I am trying to use a dinamycally generated type as the source of one business rules editor called codeeffects (www.codeeffects.com), however I am getting this exception Could not find or load assembly "tmpAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null". Error message: Could not load file or assembly 'tmpAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. (Error S103) The index action in the

How to invoke a method using Reflection

穿精又带淫゛_ 提交于 2019-12-13 11:21:15
问题 for (int tsid = 1; tsid < controller.getRowCount(currentTest); tsid++) { // values from xls keyword = controller.getCellData(currentTest, "Keyword", tsid); //object=controller.getCellData(currentTest, "Object", tsid); currentTSID = controller.getCellData(currentTest, "TSID", tsid); stepDescription = controller.getCellData(currentTest, "Description", tsid); Console.WriteLine("Keyword is:" + keyword); try { // --this is equivalent java code //MethodInfo method= Keywords.class.getMethod(keyword)

Access VB property based on name as string - Fastest Option

百般思念 提交于 2019-12-13 07:37:00
问题 I'm developing an ASP.NET MVC web app in VB and I am required to output a set of data to a table format, and to allow the user to configure the order and presence of columns from an available set. The data set is stored as a list of the object type representing the row model. Currently, I implement this using CallByName. Iterating over an ordered list of property names and outputting the value from the instance of the row model. However, based on testing this seems to be a major bottleneck in

Dynamically loaded Assembly not loading in new AppDomain

与世无争的帅哥 提交于 2019-12-13 06:17:49
问题 This is not a duplicate - I have reviewed this related StackOverflow question with no luck: How to Load an Assembly to AppDomain with all references recursively? I have two console applications. AssemblyLoaderTest.exe and testapp.exe I am trying to use AssemblyLoaderTest.exe to dynamically load testapp.exe and call a method from a class within testapp.exe So far the code works - the method "TestWrite()" in testapp.exe is executed correctly (and outputsuccess.txt is written), however , testapp

how to cache reflection in C#

廉价感情. 提交于 2019-12-13 05:41:39
问题 Hello there I am familiar with reflection quite a bit, I have been through loads of examples and I know how it works and for what purpose we can use it. But I didn't get any examples of caching the reflection, neither do I know what does it mean. And somehow I have to use caching of reflection in of the projects that I am doing. Therefore, I would be obliged if some one can briefly explain this concept as well as give some examples of it, a link to existing examples would also be appreciated.

Entity Framework Get Table By Name

痴心易碎 提交于 2019-12-13 02:23:57
问题 I am looking for ways to do LINQ on a table selected in runtime via string variable. This is what I have so far using reflection: private Entities ctx = new Entities(); public List<AtsPlatform> GetAtsPlatformByName(string atsPlatformName) { List<AtsPlatform> atsPlatform = null; System.Reflection.PropertyInfo propertyInfo = ctx.GetType().GetProperty(atsPlatformName.ToLower()); var platform = propertyInfo.GetValue(ctx, null); // it fails here highlighting "platform" with error that reads "Error

Converting FieldInfo value to a List When List type not known

本秂侑毒 提交于 2019-12-12 22:12:31
问题 I have the following: [Serializable()] public struct ModuleStruct { public string moduleId; public bool isActive; public bool hasFrenchVersion; public string titleEn; public string titleFr; public string descriptionEn; public string descriptionFr; public bool isLoaded; public List<SectionStruct> sections; public List<QuestionStruct> questions; } I create an instance of this and populate it (contents not relevant for question). I have a function which takes the instantiated object as one

How to apply a filter on LINQtoSQL results?

限于喜欢 提交于 2019-12-12 18:34:34
问题 With the ListBox control it is possible to feed it a DataSource, name a DisplayMember and a ValueMember and through some magic it will display a field from the DataSource and return a selected ValueMember. It can work wit a linq-to-sql result without even knowing anyting specific about the table it is feed with. Isn't Reflection and Attributes doing some magic? How does it work! I have a need to do something similar but I do not know where to start. I'm a beginner for LINQtoSQL. This is what