231 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
2
answers
147
views
Simulating (as far as possible) anonymous struct declaration + dynamic initialization
In some languages, we can declare and initialize an anonymous struct - or the equivalent thereof - seamlessly. Example from ECMAScript:
function foo_in_ecmascript(x) {
let computed = {
...
0
votes
3
answers
95
views
In C#, is it possible to get the owner object's properties from an anonymous function that is assigned outside?
Let's assume we have a class defined as:
class A
{
public int Param { get; set; }
public Action DoSomething { get; set; }
}
The DoSomething action is assigned in another class, but it needs ...
5
votes
3
answers
220
views
Is there a simpler way to have an ObservableCollection that can be modified only from within the same class?
Often I need a read-only ObservableCollection (so that it's reference or contents can be only modified from within this class). I need ObservableCollection because I will be binding to that property ...
0
votes
2
answers
76
views
How to initialize properties using Reflection?
Given the following sample POCO class:
public class TestClass
{
public int Id { get; init; }
public TestClass() {}
}
How can I initialize the Id property using Reflection?
The result should ...
1
vote
1
answer
113
views
Creation of an instance with `with` block causes a type issue
I am using Groovy to create a package that I use in ReadyApi.
In a Groovy script test step, I do the following:
class B {
String value
boolean isSomething
}
class A {
String name
B ...
2
votes
1
answer
64
views
Why does my array initializer not work unless I create a separate variable for it?
The following C++ code compiles with no errors or warnings, but for some reason when I print out the contents of foo.arr I just get junk values. It looks like the array member is not being properly ...
0
votes
1
answer
161
views
Multiple nested object initialisers with recursive constructor properties
Is there a way to pass default/constructed property vales in object initializers - to the constructors of nested object initializers?
e.g.
take these 3 classes Car, Part, Tool
Car
{
public Guid ...
0
votes
2
answers
801
views
Object initialization in Pythonnet
Let's assume I've the following C# class:
public class Test
{
public double X;
public double Y;
}
I want to use the above C# Test class from IronPython and as well from CPython (using ...
3
votes
2
answers
879
views
Object initialization syntax on get-only field [HttpsRequestMessage.Header]
While searching around for how to work with HTTP request headers, i've seen a ton of examples use this construct to initialize the HttpRequestMessage:
var request = new HttpRequestMessage()
{
...
0
votes
1
answer
421
views
Use Tuple values in Object initalizer syntax
I'm trying to initialize properties of an object I am creating with the values of a named tuple.
Something like this
public Person DoIt() {
return new Person {
(First, Last) = GetFirstAndLast(id)...
0
votes
2
answers
157
views
More concise way to pass, as constructor parameter, an Action that references private data?
This is stripped down from a more complex situation.
The goal is to construct several instances of class SubAction, each of which uses an action to alter how it uses its internal data.
Consider:
...
0
votes
0
answers
306
views
How to initialize a struct/class that has huge array members?
Is there a way to initialize a C++ struct/class with very large array members? I would like to initialize them by filling them with any kind of data besides an empty array. The following code is ...
0
votes
2
answers
3k
views
How to perform object initializer for a list property in VB.NET
I am trying to implement object initializer. All the classes are already created by someone else. I cannot change.
I have a class Ins.vb that has a list as a property
Partial Public Class Ins
...
1
vote
1
answer
201
views
Maximum call stack size exceeded - Object Initializer with reference to self
While playing around with a simple Javascript Object Initializer example, I could not find an explanation while the following code:
const obj = {
self: this
};
console.log(obj);
would ...
0
votes
0
answers
100
views
Default member initializer not being set C++
I have the following code:
class Foo
{
public:
enum class MyEnum
{
option1,
option2
}
"Some constructors"
private:
"Some members and the following member"
...