reflection

In Swift, how can I use setValueForKey to set the textAlignment property of an object?

拈花ヽ惹草 提交于 2020-01-06 14:41:08
问题 Let's say we define an object like this: let object: AnyObject = { var result = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 50)) result.text = "First Text" result.backgroundColor = UIColor.blueColor() return result }() For this example, I explicitly created a UILabel , but in my actual project I don't know what type of object is created, so I'm just treating the result as AnyObject for this example. The object is just a standard UILabel with text of "First Text" on a blue background

Loading library dynamically

可紊 提交于 2020-01-06 14:37:20
问题 I have the following project structure: Web API Class Library A Class Library B Class Library C These are the references between the projects Web API directly references A and B B directly references C C has a method which needs to ensure that A is loaded to use, by reflection, a type defined in it. My code actually is like the following public class C { public void MethodCallingBType( string fullClassName ) { //e.g. "MyNamespace.MyType, MyNamespace" string[] parts = fullClassName.Split( ','

Access non-public (java-native) classes from JDK (7)

可紊 提交于 2020-01-06 14:16:19
问题 I want to use the method MethodHandleNatives.getTargetMethod(MethodHandle)AccessibleObject. The class MethodHandleNatives is not public. So does anybody know how I can do that? I know that its possible to access private methods and fields via reflections, so I am asking, if this is also possible. Thanks. 回答1: I have found a solution. It is not straight forward but it works =) MethodHandle mh; // a MethodHandle Object Class<?> mhn; try { mhn = Class.forName("java.lang.invoke

how to create java file programmatically

梦想的初衷 提交于 2020-01-06 08:05:40
问题 I am creating a util-class which writes .java Files that act as coverter - generator. This util-class will generate AConverter.java' (refer below sample) I want know how to write the util-class. I googled, and found the recommendation to use apache bcel. But I couldn't find an example to write the .java File from a String and have it working in my program. The expectation is... class ADTO { private String empId; private String empName; private String dept; //setters and getters } class ABO {

reflection static method argument string

醉酒当歌 提交于 2020-01-06 07:21:12
问题 public class Star{ public static ArrayList initdata(String pattern) { ArrayList data = new ArrayList(); if (pattern != "") { ModelCollection mc = Star.find(pattern, 0); Iterator dataIterator = mc.iterator(); while (dataIterator.hasNext()) { Star star = (Star) dataIterator.next(); data.add(star.getName()); Debug.trace("StarName" + star.getName()); } } Collections.sort(data); return data; } } I want to invoke method initdata using reflection, I tried to write something like this , but it does

How to return List<dynamic> with Dapper.NET ORM that can bindable?

烈酒焚心 提交于 2020-01-06 07:09:52
问题 This question is old now, Dapper data-view binding are fixed as shown answer below :) 回答1: I've added TypeDescriptor -based bindings to DapperRow , which means that anything obtained via Query() (the dynamic API) should now bind to much common UI controls. Anything from 1.60.5 or above should work. Let me know! Caveat: it doesn't currently work for empty results (zero rows). I know how to implement that (see notes here), but that would require some additional changes to the query

How to return List<dynamic> with Dapper.NET ORM that can bindable?

て烟熏妆下的殇ゞ 提交于 2020-01-06 07:09:20
问题 This question is old now, Dapper data-view binding are fixed as shown answer below :) 回答1: I've added TypeDescriptor -based bindings to DapperRow , which means that anything obtained via Query() (the dynamic API) should now bind to much common UI controls. Anything from 1.60.5 or above should work. Let me know! Caveat: it doesn't currently work for empty results (zero rows). I know how to implement that (see notes here), but that would require some additional changes to the query

EntityFramework LINQ Order using string and nested reflection

怎甘沉沦 提交于 2020-01-06 06:30:37
问题 I saw already some of the similar questions, but cannot find an anwser how to solve this problem. I want to have a possibility to order collection using string as property name. Model: public sealed class User : IdentityUser { #region Constructors #endregion #region Properties [Required] [Display(Name = "First name")] public string FirstName { get; set; } [Required] [Display(Name = "Last name")] public string LastName { get; set; } [ForeignKey("Superior")] public string SuperiorId { get; set;

EntityFramework LINQ Order using string and nested reflection

别等时光非礼了梦想. 提交于 2020-01-06 06:29:39
问题 I saw already some of the similar questions, but cannot find an anwser how to solve this problem. I want to have a possibility to order collection using string as property name. Model: public sealed class User : IdentityUser { #region Constructors #endregion #region Properties [Required] [Display(Name = "First name")] public string FirstName { get; set; } [Required] [Display(Name = "Last name")] public string LastName { get; set; } [ForeignKey("Superior")] public string SuperiorId { get; set;

How to get this Method object via reflection?

删除回忆录丶 提交于 2020-01-06 05:48:07
问题 This is the class: public class Foo { public void bar(Integer[] b) { } } Now I'm trying to get this method via reflection: Class cls = Foo.class; Class[] types = { /* what is here */ }; cls.getMethod("bar", types); How to create this "type"? 回答1: Integer[].class - this is the class literal for the integer array. If you need it dynamically, you can use Class.forName("[Ljava.lang.Integer;") as David noted. If you don't know the exact types, you can call getMethods() , iterate the returned array