Skip to main content

Posts

Showing posts with the label dynamic

Windows 8 Metro App - How to debug JS that was loaded at runtime

In the last period of time I had to work a lot with JavaScript and not for the UI, but for an entire Metro application on Windows 8. One of the nice features of JavaScript is the ability to access any kind of function and defining or overriding functions at runtime. This feature is very powerful but also can create a lot of mess. In this moment if we would try to write a C# Metro Application we would not have the ability to load at runtime any kind of assembly or code. The “reflection” part on the .NET framework for Metro Application is not the one that we know from the normal .NET. In JavaScript if we have a script like this: (function(){ “use strict” WinJS.Namespace.define(“MyClass”,{ doSomeAction: function(){ console.warn(“doSomeAction was called”); } }); })(); we could evaluate the script at runtime and call or instanced the object and functions that were defined. The first step is to evaluate the script. Let assume that the definition of this script can be foun...

How to load a resouce dynamic

Mai mult ca sigur cu toti am folosit fisiere cu resurse (*.resx). Folosirea lor nu implica nici o problema, totul este destul de simplu, dar uneori apare nevoie sa accesam o resursa in mod dinamic. De exemplu daca avem fisierul de resurse "CarResources.resx" si vrem sa accesam resursa 'Power' avem nevoie de urmatorul cod: string powerLabel = CarResources.Power; Dar apare urmatoarea problema, daca resursa de care avem nevoie o putem determina doar la runtime? O solutie ar fi sa folosim ResourcesManager , care ne permite sa incarcam o anumita resursa in mod dinamic. Exemplul de mai sus ar trebuii rescris in felul urmator: var carResource = new ResourceManager("CarResource",Assembly.GetExecutingAssembly()); var powerLabel = carResource.GetString("Power"); Trebuie avut grija din ce assembly incarcati resursa.