Enumerating through an object’s properties (string) in C#

Use reflection. It’s nowhere near as fast as hardcoded property access, but it does what you want. The following query generates an anonymous type with Name and Value properties for each string-typed property in the object ‘myObject’: var stringPropertyNamesAndValues = myObject.GetType() .GetProperties() .Where(pi => pi.PropertyType == typeof(string) && pi.GetGetMethod() != null) .Select(pi => new { … Read more

Autowired Environment is null

Autowiring happens later than load() is called (for some reason). A workaround is to implement EnvironmentAware and rely on Spring calling setEnvironment() method: @Configuration @ComponentScan(basePackages = “my.pack.offer.*”) @PropertySource(“classpath:OfferService.properties”) public class PropertiesUtil implements EnvironmentAware { private Environment environment; @Override public void setEnvironment(final Environment environment) { this.environment = environment; } @Bean public String load(String propertyName) { return … Read more

Using reserved words as property names, revisited

In ECMAScript, starting from ES5, reserved words may be used as object property names “in the buff”. This means that they don’t need to be “clothed” in quotes when defining object literals, and they can be dereferenced (for accessing, assigning, and deleting) on objects without having to use square bracket indexing notation. That said, reserved … Read more

Dumping a java object’s properties

You could try XStream. XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver(“utf-8”)); System.out.println(xstream.toXML(new Outer())); prints out: <foo.ToString_-Outer> <intValue>5</intValue> <innerValue> <stringValue>foo</stringValue> </innerValue> </foo.ToString_-Outer> You could also output in JSON And be careful of circular references 😉

Can a JavaScript object property refer to another property of the same object? [duplicate]

Not with object literals (this has the same value during constructing of the literal that it did before-hand). But you can do var carousel = new (function() { this.$slider = $(‘#carousel1 .slider’); this.panes = this.$slider.children().length; })(); This uses an object created from an anonymous function constructor. Note that $slider and panes are public, so can … Read more

Swift readonly external, readwrite internal property

Given a class property, you can specify a different access level by prefixing the property declaration with the access modifier followed by get or set between parenthesis. For example, a class property with a public getter and a private setter will be declared as: private(set) public var readonlyProperty: Int Suggested reading: Getters and Setters Martin’s … Read more