Exception System.InvalidCastException when calling a method bound with btouch that returns an object. MonoTouch bug?
Date : March 29 2020, 07:55 AM
hope this fix your issue I have managed to work around this issue and it does indeed seem to be a bug in MonoTouch. My workaround was to call btouch with the outdir parameter set and then include the generated C# files in my project. So, instead of doing this: btouch ultralite.cs enum.cs
|
How to prevent selected index from changing when bound data changes?
Date : March 29 2020, 07:55 AM
it should still fix some issue The reason the selection is lost is because the selected value is matched directly to the name property, which changes. As a result, the selected value no longer exists in the data source (allNames). If you want to retain the selection, you have a couple of options: <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="http://knockoutjs.com/downloads/knockout-2.2.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
var data =
{
people: ko.observableArray(
[
{ id: 1, name: ko.observable("Jim") },
{ id: 2, name: ko.observable("Jane") },
{
id: 3, name: ko.observable("Sam"),
subordinates: ko.observableArray(
[
{
id: 4, name: ko.observable("Tambone"),
subordinates: ko.observableArray(
[
{ id: 5, name: ko.observable("Edward") },
{ id: 6, name: ko.observable("Kristy") },
{ id: 7, name: ko.observable("Thomas") },
{ id: 8, name: ko.observable("Andy") }
])
},
{ id: 9, name: ko.observable("Jules") }
])
}
])
};
var allNames = ko.computed(function ()
{
var names = [];
var selector = function (id, name, indent)
{
var option =
{
value: id,
text: (indent || "") + name
};
return option;
};
for (var i = 0; i < data.people().length; i++)
{
names.push(selector(data.people()[i].id, data.people()[i].name()));
addSubordinates(names, 1, data.people()[i].subordinates, selector);
}
return names;
});
function addSubordinates(names, depth, subordinates, selector)
{
if (subordinates != null)
{
var indentText = "";
for (var i = 0; i < depth; i++)
indentText += ". . ";
for (var i = 0; i < subordinates().length; i++)
{
names.push(selector(subordinates()[i].id,subordinates()[i].name(), indentText));
addSubordinates(names, depth + 1, subordinates()[i].subordinates, selector);
}
}
}
</script>
</head>
<body>
<div data-bind="foreach: data.people">
<input type="text" data-bind="value: name" /><br />
</div>
<a href="JavaScript:data.people.push({ name: ko.observable('New Person') });">Add Person</a>
<br /><br /><br />
<select data-bind="options: allNames, optionsValue: 'value', optionsText: 'text', optionsCaption: 'All Names...'" />
<script type="text/javascript">
ko.applyBindings();
</script>
</body>
</html>
var allNames = ko.computed(function ()
{
var names = [];
var selector = function (item, name, indent)
{
var option =
{
value: ko.computed(function(){ return data.people().indexOf(item);}),
text: (indent || "") + name
};
return option;
};
for (var i = 0; i < data.people().length; i++)
{
names.push(selector(data.people()[i], data.people()[i].name()));
addSubordinates(names, 1, data.people()[i].subordinates, selector);
}
return names;
});
function addSubordinates(names, depth, subordinates, selector)
{
if (subordinates != null)
{
var indentText = "";
for (var i = 0; i < depth; i++)
indentText += ". . ";
for (var i = 0; i < subordinates().length; i++)
{
names.push(selector(subordinates()[i],subordinates()[i].name(), indentText));
addSubordinates(names, depth + 1, subordinates()[i].subordinates, selector);
}
}
}
|
Changing object that is calling a method pass as delegate in C#
Tag : chash , By : delphiace
Date : March 29 2020, 07:55 AM
I wish this help you Here is my case, I have a Library that have many methodes and have one entry point. I do not have acces to library source code. , Define your method as so: T CallSomethingInLibrary<T>(Func<A, T> funcLib)
{
if(DosomeValidation())
{
A available=GetAvailableInstance();
funcLib(available);
//Where is the return here??
}
else
{
return new List<int>()
}
}
CallSomethingInLibrary(instance => instance.methode1(8));
|
Prevent calling a static method from an instance object
Tag : php , By : Kaputnik
Date : March 29 2020, 07:55 AM
I hope this helps . $a::read() is just another way of writing Test::read();, it calls the static method on the class, not on the instance. You don't have to worry about someone using this different way of writing it, since it does the same thing. By the way, many languages allow that. even though it is not recommended. In Java for example you could do the following: public class Main {
public static void main(String[] args) {
Main m = new Main();
m.test(); // Static member accessed via instance reference
Main.test();
}
public static void test() { }
}
|
Is method reference calling constructor of ArrayNode class under the hood?
Tag : java , By : lonehunter01
Date : March 29 2020, 07:55 AM
Does that help The method evaluateArrayNode eventually calls the ArrayNode constructor, indirectly through a series of intermediate method calls. From my Debug view: // this.array = generator.apply((int) size);
Nodes$FixedNodeBuilder<T>(Nodes$ArrayNode<T>).<init>(long, IntFunction<T[]>) line: 646
Nodes$FixedNodeBuilder<T>.<init>(long, IntFunction<T[]>) line: 1199
Nodes.builder(long, IntFunction<T[]>) line: 167
ReferencePipeline$3(ReferencePipeline<P_IN,P_OUT>).makeNodeBuilder(long, IntFunction<P_OUT[]>) line: 131
ReferencePipeline$3(AbstractPipeline<E_IN,E_OUT,S>).evaluate(Spliterator<P_IN>, boolean, IntFunction<E_OUT[]>) line: 543
ReferencePipeline$3(AbstractPipeline<E_IN,E_OUT,S>).evaluateToArrayNode(IntFunction<E_OUT[]>) line: 260
ReferencePipeline$3(ReferencePipeline<P_IN,P_OUT>).toArray(IntFunction<A[]>) line: 438
// Arrays.stream(new int[] { }).toArray(Integer[]::new);
Test.main(String[]) line: 15
class Generator implements IntFunction<Integer[]> {
@Override
public Integer[] apply(int value) {
System.out.println(new Exception().getStackTrace()[2]);
return new Integer[value];
}
}
Arrays.stream(new int[] { }).toArray(new Generator());
java.util.stream.Nodes$ArrayNode.<init>(Nodes.java:646)
this.array = generator.apply((int) size);
|