strong-typing

JSON.NET cannot handle simple array deserialization?

拥有回忆 提交于 2019-12-06 01:45:48
问题 I created a simple class with one field. class Test{int value;} If I use the "preserve references" feature and set it to "all" (i.e. both objects and arrays), then when I simply serialize an array of Test objects, it gets serialized as a JSON object with a special "$values" member with the array values, along with the expected "$id" property to preserve the array reference. That much is fine, but once again the whole thing breaks on deserialization. Stepping through the source code, I

How do I initialize a vector with an array of values?

徘徊边缘 提交于 2019-12-06 00:46:16
问题 How do I initialize a vector with an array of values? I tried this and it complies fine, but does not work! langs = new Vector.<String>(["en","fr"]); I also need to load an arbitrary array into a vector, like this: langlist = ["en","fr"]; langs = new Vector.<String>(langlist); Is there a way to do this? Edit: How do I initialize a 2D vector with a 2D array of values? numbers = [[10,20,30], [10,20,30]]; nums = Vector.<Vector.<Number>>(numbers); I tried this but it gives me the error: TypeError

Why is constness not respected inside these julia functions?

匆匆过客 提交于 2019-12-05 21:37:52
Prompted by Lyndon's question earlier today: a. julia> function f1(x::Float64) const y = x; y = "This should throw an error since y is of constant type"; return y; end f1 (generic function with 1 method) julia> f1(1.0) "This should throw an error since y is of constant type" Why does the const keyword not work as expected here? (i.e., disallow assigning a string to y which has been declared as const ). b. julia> function f2(x::Float64) show(x); const x = 1.; end f2 (generic function with 1 method) julia> f2(1.0) ERROR: UndefVarError: x not defined Stacktrace: [1] f2(::Float64) at ./REPL[1]:2

Strongly-typed languages for web programming

允我心安 提交于 2019-12-05 19:15:19
问题 Are there any strongly-typed programming languages for the Web? I program in PHP now, but often I wish it yelled at me when I tried to compare a number to a string. Functions in the standard library that can return either a bool or an integer don't make anything easier either. I know there's .NET, but is it my only choice? 回答1: You can develop Java web-applications. See JSPs. 回答2: Java? C++? Any language can be a web language... More details on your requirements would be needed to make a

PHP 'instanceof' failing with class constant

只愿长相守 提交于 2019-12-05 10:18:26
I'm working on a framework that I'm trying to type as strongly as I possibly can. (I'm working within PHP and taking some of the ideas that I like from C# and trying to utilize them within this framework.) I'm creating a Collection class that is a collection of domain entities/objects. It's kinda modeled after the List<T> object in .Net. I've run into an obstacle that is preventing me from typing this class. If I have a UserCollection, it should only allow User objects into it. If I have a PostCollection, it should only allow Post objects. All Collections in this framework need to have certain

Linq to Entities Filtering an Entity Dynamic/Strongly Typed

夙愿已清 提交于 2019-12-05 06:32:49
问题 I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows: grid.DataSource = myEntities.entityName.Where("it.field = " & field) It works, but it obviously isn't strongly typed. Is there a way to define the Where clause of an entity using a strongly typed notation? 回答1: Have you tried to use a lambda expression? grid.DataSource = myEntities.Customers.Where(c => c.Name == "Bob"); or in VB: grid

How do I initialize a vector with an array of values?

断了今生、忘了曾经 提交于 2019-12-04 06:22:44
How do I initialize a vector with an array of values? I tried this and it complies fine, but does not work! langs = new Vector.<String>(["en","fr"]); I also need to load an arbitrary array into a vector, like this: langlist = ["en","fr"]; langs = new Vector.<String>(langlist); Is there a way to do this? Edit: How do I initialize a 2D vector with a 2D array of values? numbers = [[10,20,30], [10,20,30]]; nums = Vector.<Vector.<Number>>(numbers); I tried this but it gives me the error: TypeError: Error #1034: Type Coercion failed I don't think that you can pass in an array of arrays into the

JSON.NET cannot handle simple array deserialization?

北城以北 提交于 2019-12-04 05:43:49
I created a simple class with one field. class Test{int value;} If I use the "preserve references" feature and set it to "all" (i.e. both objects and arrays), then when I simply serialize an array of Test objects, it gets serialized as a JSON object with a special "$values" member with the array values, along with the expected "$id" property to preserve the array reference. That much is fine, but once again the whole thing breaks on deserialization. Stepping through the source code, I discovered that simply because the test for " IsReadOnlyOrFixedSize " is true, it sets a flag "

Why aren't typedefs strongly typed?

半城伤御伤魂 提交于 2019-12-04 05:38:26
What's the reason for typedefs not being strongly typed? Is there any benefit I can't see or is it due to backward compatibility? See this example: typedef int Velocity; void foo(Velocity v) { //do anything; } int main() { int i=4; foo(i); //Should result in compile error if strongly typed. return 0; } I am not asking for workarounds to get a strong typed datatype but only want to know why the standard isn't requiring typedefs to be strongly typed? Thank you. Because C is not strongly typed and typedef has its origin in that thinking typedef is just for convenience and readability, it doesn't

ASP.NET MVC Two Way Data Binding of Model to Radio Button List using Typed Model

試著忘記壹切 提交于 2019-12-04 05:37:01
I have a mvc view made up of a matrix of radio buttons. Each row of radio buttons is in a group and represents a typed object from the model. Using the guidance of various blogs and postings I have successfully bound the posted form results to the typed model array in the controller action, however cannot seem to successfully reverse the effect and bind an existing model to the radio buttons while preserving their selected or unselected state. My model contains a property called "AnswerValue" which is between 0 and 4 and should match up with the radiobutton names. I tried changing the index