All Questions

334
votes
26answers
181040 views

What should my Objective-C singleton look like?

My singleton accessor method is usually some variant of: static MyClass *gInstance = NULL; + (MyClass *)instance { @synchronized(self) { if (gInstance == NULL) gInstance ...
89
votes
8answers
18032 views

Best practice to implement a failable initializer in Swift

With the following code I try to define a simple model class and it's failable initializer, which takes a (json-) dictionary as parameter. The initializer should return nil if the user name is not def...
29
votes
2answers
2759 views

Initializer syntax

I like the C# 3 initializer syntax and use it a lot, but today while looking in Reflector, the following came up: var binding = new WSHttpBinding { ReaderQuotas = { MaxArrayLength = 100000 }, Max...
22
votes
1answers
1943 views

Order of operations using Object Initializer Syntax

Does the order in which I set properties using the object initializer syntax get executed in the exact same order? For instance if I do this: var s = new Person { FirstName = "Micah", ...
21
votes
1answers
5409 views

Nested object initializer syntax

Resharper has just suggested the following refactoring to me: // Constructor initializes InitializedProperty but // the UninitializedSubproperty is uninitialized. var myInstance = new MyClass(); myIn...
28
votes
4answers
19697 views

Initial capacity of collection types, e.g. Dictionary, List

Certain collection types in .Net have an optional "Initial Capacity" constructor parameter. For example: Dictionary<string, string> something = new Dictionary<string,string>(20); List&l...
17
votes
3answers
4082 views

Assigning events in object initializer

Why isn't it possible to assign events along with properties in object initializers in C#? It seems to be so natural to do so. var myObject = new MyClass() { Property = value, Ev...
79
votes
2answers
11921 views

Object initialization syntax

I'm just starting out with F# and I can't find the syntax to do object initialization like in C# 3. I.e. given this: public class Person { public DateTime BirthDate { get; set; } public string ...
5
votes
3answers
2628 views

Can properties inside an object initializer reference each other?

Is it somehow possible for properties to reference each other during the creation of a dynamic object an anonymously-typed object (i.e. inside the object initializer)? My simplified example below need...
8
votes
5answers
14197 views

Can you Instantiate an Object Instance from JSON in .NET?

Since Object Initializers are very similar to JSON, and now there are Anonymous Types in .NET. It would be cool to be able to take a string, such as JSON, and create an Anonymous Object that represent...

Previous Next