reflection

Filtering list of objects in datagridview based on cell value

喜夏-厌秋 提交于 2021-02-05 05:23:24
问题 I am currently unsure on the best way of going about getting a filter to work right on a datagridview that has its datasource set to a list of objects. So given an object of: public class DepositAccountBill { #region Properties public int AccountBillID { get; set; } public int AccountID { get; set; } public string AccountNumber { get; set; } public string ControlNumber { get; set; } public DateTime BillDate { get; set; } public decimal DepositAmount { get; set; } } I have a datagridview table

Filtering list of objects in datagridview based on cell value

廉价感情. 提交于 2021-02-05 05:22:05
问题 I am currently unsure on the best way of going about getting a filter to work right on a datagridview that has its datasource set to a list of objects. So given an object of: public class DepositAccountBill { #region Properties public int AccountBillID { get; set; } public int AccountID { get; set; } public string AccountNumber { get; set; } public string ControlNumber { get; set; } public DateTime BillDate { get; set; } public decimal DepositAmount { get; set; } } I have a datagridview table

Can I get the instance of the calling object in Java?

不打扰是莪最后的温柔 提交于 2021-02-04 17:59:05
问题 There's a library which calls my method with a few arguments. I'd like to receive another argument, but the library doesn't provide it to the method it calls. By decompiling the library, I can see that it has the argument, and it's assigned to an instance variable (not private, but not public either.) I know I can get at the variable using reflection if I have the instance, but I don't have the instance, either. Is there a way I can get at the instance? SecurityManager has getClassContext(),

Open generic interface types of open implementation don't equal interface type?

故事扮演 提交于 2021-02-04 17:17:49
问题 Here's a test that should, in my opinion be passing but is not. [TestMethod] public void can_get_open_generic_interface_off_of_implementor() { typeof(OpenGenericWithOpenService<>).GetInterfaces().First() .ShouldEqual(typeof(IGenericService<>)); } public interface IGenericService<T> { } public class OpenGenericWithOpenService<T> : IGenericService<T> { } Why does this not pass? Given Type t = typeof(OpenGenericWithOpenService<>) how do I get typeof(IGenericService<>)? I'm generally curious, but

Invoke Enumerable.Where (or other overloaded generic method) using reflection

守給你的承諾、 提交于 2021-02-04 15:47:20
问题 There are 2 overloads (or method signatures) of the "Where" method in Enumerable class: namespace System.Linq { public static class Enumerable { public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate); public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate); } So var where = typeof(Enumerable).GetMethod("Where") throws an exception stating an ambiguous match because, of

How to use method with generics and inheritance?

谁都会走 提交于 2021-02-04 08:21:20
问题 Having the following classes: public interface Step<C extends Config> { void setConfig(C config); } and public class ValidationStep implements Step<ValidationConf> { public void setConfig(ValidationConf conf) {} // implementation } and public class ProcessStep implements Step<ProcessConf> { public void setConfig(ProcessConf conf) {} // implementation } and public interface Config { Class<? extends Step> type(); } and public class ValidationConf implements Config { public Class<? extends Step>

Load Dataset from Dynamically generated Case Class

蹲街弑〆低调 提交于 2021-02-04 08:06:24
问题 What is Needed: number of tables in source database are changing rapidly and thus I don't want to edit case classes so I dynamically generate them through SCALA code and put in package. But now not able to read it dynamically. If this works than I would parse "com.example.datasources.fileSystemSource.schema.{}" as object schema members in loop What has already been Done: I have some case classes dynamically generated from schema of database tables as below: object schema{ case class Users

Accessing an instance variable by name (string), kinda like dynamic languages do, in C#

╄→尐↘猪︶ㄣ 提交于 2021-02-04 06:51:50
问题 i've got some C# code like this: string fieldName = ... string value = ... if (fieldName == "a") a = value; if (fieldName == "b") b = value; if (fieldName == "c") c = value; if (fieldName == "d") d = value; ... I want something like this: string fieldName = ... string value = ... SetMyInstanceVariable(fieldName, value); ... Is there a simple way to do it? I know that given a class's name in a string, you can instantiate it with System.Activator, and this is kindof similar so i was hoping....

How to call the overloaded method using reflection in c#. AmbiguousMatchException

℡╲_俬逩灬. 提交于 2021-01-29 19:45:16
问题 I try to call overloaded method using reflection. public void SomeMethod(string param) { param = param.Length > 0 ? param : null; Type thisType = this.GetType(); MethodInfo theMethod = thisType.GetMethod("methodName", BindingFlags.NonPublic | BindingFlags.Instance); theMethod.Invoke(this, param); } When I use one of both method all works well: //works well if param = "" (null) private void methodName(){ } //works well if param = "anystring" private void methodName(string parameter){ } I can

How can I reflect on a field annotation (Java) in a Scala program?

浪子不回头ぞ 提交于 2021-01-29 14:21:35
问题 I'm using Scala 2.13 and I know there's been a lot deprecated since older versions. I've got this annotation: @Inherited @Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface Foo { int index() default 0; } (I know... I've got lots of ElementTypes there, but I'm struggling to see where this pops up in reflection so wanted to maximize my chances of a hit!) Used like this: case class Person(name: String, @Foo(index = 3) age: