Questions tagged [object-initialization]

56 questions
2
votes
1 answer

Better way to Generalize Object Initialization?

I have the following code to generalize many very similar objects' initialization. I've generalized the c# code (as shown below). Anyone know a better way? This isn't too bad, but still involves some copy/paste, which I'd like to avoid. private…
HumbleWebDev
  • 555
  • 4
  • 20
2
votes
0 answers

Swift - How to initialize object of class created with NSClassFromString

In Objective-C we can create class from string and initialize its object to push on navigation stack like : Class myClass = NSClassFromString("ClassString"); id myObject = [[myClass alloc] initWithNibName:"ClassString"…
iAkshay
  • 1,143
  • 1
  • 13
  • 35
2
votes
2 answers

Objective-C call specific class method

I have a class that has this in the initializer: @implementation BaseFooClass -(id) init { if (self = [super init]) { // initialize instance variables that always need to start with this value } return self; } -(id)…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
2
votes
2 answers

Property assignments in object initializers not considered on the same level as auto-properties in C# 6

C#6 introduced the ability to initialize properties without a setter, so that one can now use this kind of syntax public class MyClass { public int Answer { get; } = 42; } or even this public class MyClass { public int Answer { get; } …
Phil Gref
  • 987
  • 8
  • 19
2
votes
2 answers

How to pass object/template as parameter in Javascript/jQuery

I'm attempting my first forray into jQuery. I'm trying to acheive the following, though I'm not sure of the terminology so will try to explain with an example using a kind of C#/pseudocode syntax. Say I want an (anonymous) object as parameter,…
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
2
votes
1 answer

initializing a object in an another class object .(after doing some operations on that constructor.)

I want to initialize a class member which is also another class object.The problem is that, I have to initialize the member with variables that I figure out after doing some operations on my constructor. Let me show the sample code. class…
Bambi
  • 33
  • 1
  • 6
2
votes
2 answers

What's the point of this in objective-c

SomeObject *temp = [[SomeObject alloc] init] self.theObject = temp; [temp release]; Why is it always done that way? Why not self.theObject = [[SomeObject alloc] init];
mk12
  • 25,873
  • 32
  • 98
  • 137
1
vote
0 answers

How to use Include in query expression with object initilazation using EF 4.1

I'm using Entity framework 4.1 code first and Here is a simplified version of my domain classes: public class Tour { public string TourName { get; set; } public virtual List Events { get; set; } } public class Event { public…
1
vote
2 answers

Get a instance of an type without calling constructors but still initialize fields/properties;

Basically what I want lies somewhere between FormatterServices.GetUninitializedObject() and Activator.CreateInstance(). This is for a plugin type of system so the type is variable, but I dont imagine that is an issue as both the above handle…
Wobbles
  • 3,033
  • 1
  • 25
  • 51
1
vote
1 answer

Should private methods check if object is properly initialized

Should the private methods of a class check if the object is properly initialized even if it's already done by the public methods? I have an class/object that represents real hardware. What the private methods do can be dangerous if object is not…
1
vote
2 answers

Java: Alternative to declaring empty constructor to initialize an object from another class

I am creating a simple, text-based interactive application, where the user is prompted for input. Each input corresponds to a specific command, which invokes a certain method. Because there are many methods, I have chosen to distribute them between…
1
vote
1 answer

How to fix IDE0017 when using File Dialogs

I am getting three "Suggestions" IDE0017 Object Initialization cab be simplified. private string dbSelect() { // This is the User File Name Selection OpenFileDialog openThis = new OpenFileDialog(); openThis.DefaultExt…
Mike Sr
  • 511
  • 1
  • 5
  • 15
1
vote
1 answer

Why does implement abstract method using val and call from superclass in val expression return NullPointerException

I have an abstract class with an unimplemented method numbers that returns a list of numbers, and this method is used in another val property initialization: abstract class Foo { val calcNumbers = numbers.map(calc) def numbers:…
SwiftMango
  • 15,092
  • 13
  • 71
  • 136
1
vote
1 answer

how to assign only on return value of a function to field of an struct in golang?

let's say we have a struct like this: type Data struct { a int } and we want to get a single return value of a function that returns multiple values and assign it to an object of Data, for example data := Data { a: strconv.Atoi("1000") } the…
sepisoad
  • 2,201
  • 5
  • 26
  • 37
1
vote
2 answers

How to Make Everything (Counters, Variables) to null of an Object?

I want to know that how can I make a an Object again go back to its initial stage. In my case I make a fragment and initialize it. I want that when it goes back to another fragment, and then back to first one, all values and variables of the first…
Abdur Rahman
  • 894
  • 1
  • 11
  • 27