strong-typing

Is there a way to make Strongly Typed Resource files public (as opposed to internal)?

China☆狼群 提交于 2019-12-03 23:51:11
问题 Here's what I'd like to do: I want to create a library project that contains my Resource files (ie, UI Labels and whatnot). I'd like to then use the resource library both in my UI and in my Tests. (Ie, basically have a common place for my resources that I reference from multiple projects.) Unfortunately, because the StronglyTypedResourceBuilder (the .Net class which generates the code for Resources) makes resource files internal by default, I can't reference my strongly typed resources in the

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

天大地大妈咪最大 提交于 2019-12-03 22:46:14
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 EmailAddress to be its own type, independent and not interchangeable with the string type that it shadows.

mvc4 bundling strongly typed bundles

℡╲_俬逩灬. 提交于 2019-12-03 15:12:00
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 thing. I would like to do something like this: (I know this won't compile this way, it's just an

When use a interface or class in Typescript [duplicate]

怎甘沉沦 提交于 2019-12-03 10:31:53
This question already has answers here : Difference between interfaces and classes in Typescript (5 answers) I have a simple scenario of a login that requires user's input a email and password in Typescript. I need to create some type to get this strong-typed and send it to the back-end. Should this be written as: export interface UserLogin { email: string; password: string; } //OR export class UserLogin { email: string; password: string; } And how to know when is the scenario to use any of these? At it's most basic, a class is essentially an object factory (ie. a blueprint of what an object

Why is tightly coupled bad but strongly typed good?

强颜欢笑 提交于 2019-12-03 09:41:23
问题 I am struggling to see the real-world benefits of loosely coupled code. Why spend so much effort making something flexible to work with a variety of other objects? If you know what you need to achieve, why not code specifically for that purpose? To me, this is similar to creating untyped variables: it makes it very flexible, but opens itself to problems because perhaps an unexpected value is passed in. It also makes it harder to read, because you do not explicitly know what is being passed in

When use a interface or class in Typescript [duplicate]

走远了吗. 提交于 2019-12-03 06:36:41
问题 This question already has answers here : Difference between interfaces and classes in Typescript (5 answers) Closed last year . I have a simple scenario of a login that requires user's input a email and password in Typescript. I need to create some type to get this strong-typed and send it to the back-end. Should this be written as: export interface UserLogin { email: string; password: string; } //OR export class UserLogin { email: string; password: string; } And how to know when is the

Difference between Strong vs Static Typing AND Weak vs Dynamic Typing

蓝咒 提交于 2019-12-03 01:37:52
问题 From What I understand, does is dynamic typing the same as weak typing and strong typing is the same as static typing. Whats the difference? Thanks 回答1: Static typing vs dynamic typing: Static typing is when your type checking occurs at compile time. You must define a type for your variables inside of your code and any operations you perform on your data would be checked by the compiler. Dynamic typing is when your type checking occurs at runtime. Instead of errors coming up when you compile

Q&A - How to get the name of Property / Function / Action / Method (of an Interface or Class), in a strongly type way?

情到浓时终转凉″ 提交于 2019-12-02 15:17:41
问题 Problem description Assuming you have an interface / class, and wish to get a Property/Func/Action name, how and what is the best practice to do so? e.g. given: public interface IConvertible { // ... bool ToBoolean(IFormatProvider provider); // ... } How to get the name of 'ToBoolean' method, in a strongly-typed way? Also, how to get the property name of IsValueCreated from Lazy<object>.IsValueCreated Motivation When you'll do reflection on an interface [method / property / etc], the compiler

Difference between Strong vs Static Typing AND Weak vs Dynamic Typing

左心房为你撑大大i 提交于 2019-12-02 15:06:53
From What I understand, does is dynamic typing the same as weak typing and strong typing is the same as static typing. Whats the difference? Thanks Boumbles Static typing vs dynamic typing: Static typing is when your type checking occurs at compile time. You must define a type for your variables inside of your code and any operations you perform on your data would be checked by the compiler. Dynamic typing is when your type checking occurs at runtime. Instead of errors coming up when you compile your code you will get runtime errors if you try performing operations on incompatible types.

Creating an array that contains only objects of a given class

笑着哭i 提交于 2019-12-02 08:28:24
问题 Ok, so I have the code below (Objective-C FYI) and I was wondering if I want to create an NSMutableArray of c_data objects, how would I go about doing that? It's sort of like declaring a List<c_data> cData in C#. @interface c_data : NSObject { double value; int label; int ID; } @property double value; @property int label; @property int ID; -(c_data*) init; -(c_data*) initWithValue:(double)value; @end @implementation c_data @synthesize value, label, ID; -(c_data*) init { return self; } -(c