C# Reflection and Getting Properties

Still not 100% sure of what you want, but this quick bit of code (untested) might get you on the right track (or at least help clarify what you want). void ReportValue(String propName, Object propValue); void ReadList<T>(List<T> list) { var props = typeof(T).GetProperties(); foreach(T item in list) { foreach(var prop in props) { ReportValue(prop.Name, prop.GetValue(item)); … Read more

What’s the difference between the HTML width / height attribute and the CSS width / height property on the img element?

A hot debate about the subject can be found here: Width attribute for image tag versus CSS To sum it up: The gain from declaring a width value and an height value (which may not be the original physical dimensions of the image) or from css declarations (like width: [valueX]; height: [valueY];) is that it … Read more

style.backgroundColor is an empty string in JavaScript

Unless you have directly defined the backgroundColor on the element itself, you have to use getComputedStyle() or currentStyle to get the value of a style property. A method that is compatible with multiple browsers would look like this: function getStyle(el,styleProp) { if (el.currentStyle) return el.currentStyle[styleProp]; return document.defaultView.getComputedStyle(el,null)[styleProp]; } You can see a working example on … Read more

What’s the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?

I ran into the same problem some time ago and found a document on the Apple Developer Connection recommending to provide your own implementation of the setter. Code sample form the linked document: @interface MyClass : NSObject { NSMutableArray *myArray; } @property (nonatomic, copy) NSMutableArray *myArray; @end @implementation MyClass @synthesize myArray; – (void)setMyArray:(NSMutableArray *)newArray { … Read more

Programmatic access to properties created by property-placeholder

No you can’t. PropertyPlaceholderConfigurer is a BeanFactoryPostProcessor, it is only “alive” during bean creation. When it encounters a ${property} notation, it tries to resolve that against its internal properties, but it does not make these properties available to the container. That said: similar questions have appeared again and again, the proposed solution is usually to … Read more

How to test Classes with @ConfigurationProperties and @Autowired

You need to annotate your TestConfiguration class with @EnableConfigurationProperties as follows: @EnableConfigurationProperties public class TestConfiguration { @Bean @ConfigurationProperties(prefix = “test”) public TestSettings settings (){ return new TestSettings(); } } Also you only need to include TestConfiguration.class in @ContextConfiguration of your SettingsTest class: @TestPropertySource(locations = “/SettingsTest.properties”) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = TestConfiguration.class) public class SettingsTest { …