23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public sealed class Tests<br />

{<br />

public static string TestMethod(Boolean throwAnException)<br />

{<br />

if (throwAnException)<br />

{<br />

throw new System.Exception("Tests.TestMethod was asked to throw an exception.");<br />

}<br />

}<br />

return "Tests.TestMethod succeeded";<br />

}<br />

public int TestProperty { get; set; }<br />

If you build the solution at this point (Build > Build Solution), you’ll see that the result of the<br />

PixelCruncherCS project is a file called PixelCruncher.winmd. The .winmd extension stands for Windows<br />

Metadata: a WinRT Component written in C# is a .NET assembly that includes extra metadata referred<br />

to as the component’s Application Binary Interface or ABI. This is what tells Windows about everything<br />

the component makes available to other languages (those public classes), and it’s also what provides<br />

IntelliSense for that component in Visual Studio and Blend.<br />

In the app you must add a reference to the component so that it becomes available in the JavaScript<br />

namespace, just like the WinRT APIs. To do this, right-click References within the JavaScript app project<br />

and select Add Reference. In the dialog that appears, select Solution on the side and then check the box<br />

for the WinRT component project as shown in Figure 16-2.<br />

FIGURE 16-2 Adding a reference to a WinRT component within the same solution as the app.<br />

When writing code that refers to the component, you always start with the namespace,<br />

PixelCruncherCS in our case. As soon as you enter that name and a dot, IntelliSense will appear for<br />

available classes in that namespace:<br />

722

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!