strong-typing

Polymorphism AND type safety in parallel inheritance chains

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:37:00
问题 I have two parallel inheritance chains: Chain1: Animal <- Lion <- Gazelle Chain2: Food <- Meat <- Grass I want to implement the "Eats" polymorphic property on Animal. This is how it looks like: public abstract class Animal { public abstract Food Eats { get; set;} } public class Lion : Animal { public override Food Eats { get { return new Meat();} set { if (value is Meat) DoSomething(value); else throw new Exception("Lions only eat meat. " + "You better learn that, dude!"); } } } However, this

Is Arraylist is typesafe or strongly typed?

筅森魡賤 提交于 2019-12-10 14:44:10
问题 I don't know what exactly the difference between "Strongly typed" and "Type safety" is! Could you please clarify this in a simple language? Suppose we are using Arraylist, but I am unable to conclude it is typesafe or strongly typed. or can we use it as both.? 回答1: An ArrayList is not typesafe. What this means is that ArrayList can be assigned a value of any type: ArrayList myList = new ArrayList(); myList.Add("this is a string"); myList.Add(19); //Notice that this is an int, but it doesn't

using a interface to type a anonymous object in typescript

旧城冷巷雨未停 提交于 2019-12-10 12:49:37
问题 I have a Interface IBase and a variable that contains a few other objects (in the sample i just added base for a better demonstration) interface IBase { height?:number; width?:number; } var element = { base: { } } How can I say that the object that the varable element.base has is from the type IBase? I know that I could create a type for the element variable that contains the types of base etc, but is that also a possibility to type that scenario without doing so. 回答1: Van den Brink's answer

Best way to create a strongly typed wrapper for Dictionary<string, string>

巧了我就是萌 提交于 2019-12-10 11:57:54
问题 I have a Dictionary containing configuration values for other classes (tasks which will be executed periodically performing assorted specialized logic) which are persisted in a database and then passed back in at execution time. I want to create a strongly typed wrapper for this Dictionary, both to allow easy access to the values and to cast them to the proper type. At the moment I have something like this: public class ConfigurationWrapper { Dictionary<string, string> _configuration; public

How much time to compile a view in ASP.NET?

∥☆過路亽.° 提交于 2019-12-10 11:47:10
问题 How much time is spent compiling a view in ASP.NET? Of course I don't expect anyone to give me a number, but I think it's interesting to have an idea of how much time this takes because it could influence the way we implement things. For example, if the time is significant , then I might try to put every result that I need to display in the view in a model class instance (created just to hold the values in such a way that I don't even have to test for objects with null value) and then

Is there a way to define C# strongly-typed aliases of existing primitive types like `string` or `int`?

拜拜、爱过 提交于 2019-12-09 14:12:56
问题 Perhaps I am demonstrating my ignorance of some oft-used feautre of C# or the .NET framework, but I would like to know if there is a natively-supported way to create a type alias like EmailAddress which aliases string but such that I can extend it with my own methods like bool Validate() ? I know of the using x = Some.Type; aliases but these are not global nor do they provide type safety, i.e. one could swap out an ordinary string for the using alias in the current file. I would like my

mvc4 bundling strongly typed bundles

心已入冬 提交于 2019-12-09 13:01:47
问题 So MVC 4 introduces script and style bundling. Which allows for this: public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/mobile").Include( "~/Scripts/jquery.mobile-*")); then used in a razor view like this: @Scripts.Render("~/bundles/mobile") My question is why do I have to type "~/bundles/mobile" ? Is there a way get intellisence to have a strongly typed object to pick up on? Otherwise I have to go look it up to make sure I call it the same

.NET Table Adapters: Get vs. Fill?

你。 提交于 2019-12-08 15:09:12
问题 I always seem to use Get when working with data (strongly typed or otherwise) from the database and I have never really needed to use Fill although I just as easily could use Fill instead of get when pulling out and updating data. Can anyone provide guidance as to the implications and gotchas of each method? In what situations is it preferable to use one or the other? Any performance implications? Thanks in advance for the answers! I love this community! 回答1: A particular gotcha of Fill, if

Why is constness not respected inside these julia functions?

柔情痞子 提交于 2019-12-07 17:40:38
问题 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

PHP 'instanceof' failing with class constant

陌路散爱 提交于 2019-12-07 07:19:23
问题 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