DataContractSerializer and Constructors in Silverlight [duplicate] - silverlight

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How does WCF deserialization instantiate objects without calling a constructor?
If I use a DataContract attribute it doesn't call my constructor, but if I skip it then it will. Why does this happen?

The purpose of serializing/deserializing is to recreate the object in its original state. The object has already been constructed so we don't need to call the constructor. It is like raising an object from the dead rather than giving birth. :)
If you need some code to happen when an object is deserialized just decorate a method with the OnDeserialized attribute and call the code you need to execute from there.

Related

Need help on what to use for CefSharp Ajax Handler [duplicate]

This question already has answers here:
What does $(selector)[0] mean in jQuery?
(4 answers)
Closed 5 years ago.
I have a button called search, when I click it it will make an AJAX request and it will fetch me some data,
How can I write an event handler function that will run when AJAX is loaded completely? i.e For example once all the search result is displayed I need to do something in that handler function.
This is just accessing an array (or an object) by index (or key). Nothing specific to jQuery.
In your case, you get a list of DOM elements from your selector, so [0] gives you the first one.

Angular operator :: - what does it do? [duplicate]

This question already has answers here:
What does :: mean in angularJS
(3 answers)
Closed 6 years ago.
Today I was looking at some angular code and was surprised to see this operator. Not sure what this operator does? Could somebody provide more information on the special operator :: ? I have neither encountered this operator before nor seen it in AngularJS docs.
project-id="{{::vm.projectId}}"
Using that syntax will save on resources by not spawning a watcher for the variable.
When you put a variable in a template using the double-curly syntax ({{...}}) Angular will generally spawn a watcher for that variable. This means that whenever changes are made to that variable in your Angular code the front-end will reflect that change.
Sometimes this over-eager watcher syntax isn't what you want, though. For instance, you may have a variable that you know will not change, or a variable that will change, but you don't want that change reflected immediately. This is why you will sometimes see the {{::my-var}} syntax, as it doesn't spawn a watcher.

Is there non static function in Elixir?

I am newbie in Elixir, coming from java background. I saw Elixir's function as static methods in java. So I wonder, is there any non-static method / function in Elixir?
Thank you
Nope - all functions belong to a module. Elixir is not an class-oriented language, so the concept of "instance methods vs. class methods" is not applicable.
Aside from typical named functions which belong to a module, there are anonymous functions, similar to lambdas in Java.
The accepted answer is correct and I upvoted it. The basic building blocks in OOP are objects. On the BEAM (Erlang VM), the basic building blocks are processes. So, the distinction between static/instance methods just doesn't make sense.
However, when thinking about what instance methods do in an object oriented language, there is something that does a similar thing in Elixir.
Instance methods, when contrasted with class methods, are the ones that work with internal object state. Elixir doesn't have classes or objects, but it does have processes. A GenServer process instance maintains state and passes it into each callback function. So, when you're looking for something that will have state and functions to modify it or return some piece of it, then you want to reach for a GenServer in Elixir.
All the functions will still belong to the Module. They aren't a unique type of function, but they do allow you to manipulate the state of a given instance of the process because the state gets passed in as a parameter and returned within the function's result.
In response to the comment by #ibgib, yes, when compared with an object oriented language like Java or C#, you can think of all modules and functions in Elixir/Erlang as being static. This is comparing apples to oranges, but if it helps when learning to think of them that way, I think that's OK. Just realize that there isn't any such thing as instance methods here.

What is the best way to get specific object inside array of objects in AngularJS?

I'm creating inside a service array of dynamic objects. I would like any controller to use that service and get a specific object inside that array.
I must run a for loop in order to find that object?
Any better and fast way?
The question is pretty vague, but in the service you could create a map of (id -> object) instead of an array. Then getting an object with a specific id becomes simple.

singleton patterns VS static types [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Advantage of Static class over use of Singleton
Usually, everytime I needed a single systemwide object I used the singleton pattern.
M question is, why shouldn't i just implement the object as static and get the single object behaviour naturally ? Are there any cons to use static types over singleton factored object?
A static type is a lot less (unit) testable.
Singletons can be passed around (as parameters) and inherited.
For examples etc see this article:
http://dotnetperls.com/singleton-static
In general you should avoid systemwide objects, as these suggest you have global state. Singleton's are ofter used to manage access to a shared resource (rather than state).
I believe at lest one of the GoF is on record as saying that including singleton's in their book was a mistake and in many cases it's used as an anti-pattern.
depends on what you want to do with the object. if it's just calling methods on it then just use a static. if you want to pass the object around, and do object oriented stuff with it, i.e polymorphism then do it the object way.

Resources