Archive for the ‘.NET’ Category
-
Hello, Silverlight World!
Posted on 3月 1st, 2012 by cx20
Silverlight
Silverlight はマイクロソフトが開発したブラウザ用プラグインである。名前の由来は「Flash(一瞬の輝き)」に対して「銀は輝き続ける」という意味との説がある。プラグインは Firefox や Safari と言った Internet Explorer 以外のブラウザにも提供されている。.NET Framework をベースとした技術で WPF(Windows Presentation Foundation)のサブセットである。
ソースコード(XAML)
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <TextBlock Text="Hello, Silverlight World!" /> </Canvas>
ソースコード(HTML)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Hello, World!</title> </head> <body> <object type="application/x-silverlight" width="400" height="300"> <param name="source" value="hello.xaml" /> </object> </body> </html>
実行方法
1. Web サーバの公開フォルダ に配置 2. ブラウザで表示 http://localhost/doc/hello.html
実行結果
Hello, Silverlight World!
-
Hello, ASP.NET Razor World!
Posted on 2月 11th, 2012 by cx20
ASP.NET Razor
Razor は ASP.NET の新しい Web ページ記述構文である。
ASP や PHP のように HTML の中にスクリプトを埋め込むように記述できるという特徴がある。
実際の記述コードの言語としては、C# や Visual Basic(VB.NET)が用いられる。
実行環境として ASP.NET MVC 3 もしくは WebMatrix が必要。ソースコード(C# による Razor 記法)
@{ var msg = "ASP.NET Razor"; } <html> <head> <title>Hello, World!</title> </head> <body> <p>Hello, @msg World!</p> </body> </html>
ソースコード(Visual Basic による Razor 記法)
@Code Dim msg = "ASP.NET Razor" End Code <html> <head> <title>Hello, World!</title> </head> <body> <p>Hello, @msg World!</p> </body> </html>
上記 Razor 記法のコードは、以下の .NET のコードに相当する。実行時に .NET アセンブリにコンパイルされ実行される。
ソースコード(C#)
namespace ASP { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Web; using System.Web.Helpers; using System.Web.Security; using System.Web.UI; using System.Web.WebPages; using System.Web.WebPages.Html; using WebMatrix.WebData; using WebMatrix.Data; public class _Page_hello_cshtml : System.Web.WebPages.WebPage { public _Page_hello_cshtml() { } protected System.Web.HttpApplication ApplicationInstance { get { return ((System.Web.HttpApplication)(Context.ApplicationInstance)); } } public override void Execute() { var msg = "ASP.NET Razor"; WriteLiteral("<html>rn<head>rn<title>Hello, World!</title>rn</body>rn<body>rn<p>Hello, "); Write(msg); WriteLiteral(" World!</p>rn</body>rn</html> "); } } }
実行方法
1. IIS の公開フォルダ に配置 2. ブラウザで表示 http://localhost/doc/hello.cshtml … C# の場合 http://localhost/doc/hello.vbhtml … VB の場合
実行結果
Hello, ASP.NET Razor World!
-
Hello, ASP.NET World!
Posted on 2月 10th, 2012 by cx20
ASP.NET
ASP.NET は、ASP の後継でマイクロソフトの Web サーバー(IIS)でプログラムを動作させる技術の一つである。
既定の言語として Visual Basic(VB.NET)や C# が用いられるが、実際にはコンパイルされた .NET アセンブリが使用される為、JScript.NET や C++/CLI など .NET に対応した他の言語でも記述が可能である。
ソースコード(Visual Basic)
<%@ Page Language="VB" %> <html> <head> <title>Hello, World!</title> </head> <body> <p><% Response.Write( "Hello, ASP.NET World!" ) %></p> </body> </html>
ソースコード(C#)
<%@ Page Language="C#" %> <html> <head> <title>Hello, World!</title> </head> <body> <p><% Response.Write( "Hello, ASP.NET World!" ); %></p> </body> </html>
ソースコード(JScript.NET)
<%@ Page Language="JScript" %> <html> <head> <title>Hello, World!</title> </head> <body> <p><% Response.Write( "Hello, ASP.NET World!" ); %></p> </body> </html>
上記コードは、以下の .NET のコードに相当する(以下の例は C# のケース)。実行時に .NET アセンブリにコンパイルされ実行される。
ソースコード
namespace ASP { using System.Web; using System.Text.RegularExpressions; using System.Web.Profile; using System.Web.UI.WebControls; using System.Web.Security; using System.Collections.Generic; using System.Collections.Specialized; using System; using System.Xml.Linq; using System.Collections; using System.Linq; using System.Web.UI; using System.Web.DynamicData; using System.Text; using System.Web.Caching; using System.Web.UI.HtmlControls; using System.Configuration; using System.Web.UI.WebControls.WebParts; using System.Web.SessionState; using System.ComponentModel.DataAnnotations; [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] public class hello_aspx : global::System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler { private static bool @__initialized; private static object @__fileDependencies; [System.Diagnostics.DebuggerNonUserCodeAttribute()] public hello_aspx() { string[] dependencies; ((global::System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/hello.aspx"; if ((global::ASP.hello_aspx.@__initialized == false)) { dependencies = new string[1]; dependencies[0] = "~/hello.aspx"; global::ASP.hello_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies); global::ASP.hello_aspx.@__initialized = true; } this.Server.ScriptTimeout = 30000000; } protected System.Web.Profile.DefaultProfile Profile { get { return ((System.Web.Profile.DefaultProfile)(this.Context.Profile)); } } protected override bool SupportAutoEvents { get { return false; } } protected System.Web.HttpApplication ApplicationInstance { get { return ((System.Web.HttpApplication)(this.Context.ApplicationInstance)); } } [System.Diagnostics.DebuggerNonUserCodeAttribute()] private void @__BuildControlTree(hello_aspx @__ctrl) { this.InitializeCulture(); @__ctrl.SetRenderMethodDelegate(new System.Web.UI.RenderMethod(this.@__Render__control1)); } private void @__Render__control1(System.Web.UI.HtmlTextWriter @__w, System.Web.UI.Control parameterContainer) { @__w.Write("rn<html>rn<head>rn<title>Hello, World!</title>rn</head>rn<body>rn<p>"); Response.Write( "Hello, ASP.NET World!" ); @__w.Write("</p>rn</body>rn</html> "); } [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override void FrameworkInitialize() { base.FrameworkInitialize(); this.@__BuildControlTree(this); this.AddWrappedFileDependencies(global::ASP.hello_aspx.@__fileDependencies); this.Request.ValidateInput(); } } }
実行方法
1. IIS の公開フォルダ に配置 2. ブラウザで表示 http://localhost/doc/hello.aspx
実行結果
Hello, ASP.NET World!
-
Hello, Nemerle World!
Posted on 1月 28th, 2012 by cx20
Nemerle
Nemerle はオブジェクト指向言語と関数型言語の特徴をあわせ持ったハイブリッド言語である。構文は C# に似ており .NET Framework で動作する。名前の由来はゲド戦記の大賢人ネマール(Nemmerle)から。
C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作させることができる。
ソースコード
using System; class Hello { static Main() : void { Console.WriteLine("Hello, Nemerle World!"); } }
コンパイル&実行方法(Mono)
$ mono ncc.exe -o hello hello.n $ mono ./hello.exe
コンパイル&実行方法(.NET Framework)
C:¥> ncc -o hello hello.n C:¥> hello
実行結果
Hello, Nemerle World!
-
Hello, Fantom World!
Posted on 1月 27th, 2012 by cx20
Fantom
Fantom は Java VM もしくは .NET 共通言語ランタイム上で動作するオブジェクト指向言語である。構文は Java や C# に似ている。
言語の名前は当初、作者が住んでいる住所にちなんで「Fan」と付けられたが、検索しやすいように「Fantom」に変更された。
ソースコード
#!/usr/bin/env fan class Hello { static Void main() { echo("Hello, Fantom World!") } }
実行方法(スクリプトファイルを指定して実行)
$ fan hello.fan
実行方法(実行権限を付与して実行)
$ chmod +x hello.fan $ ./hello.fan
実行方法(Java VM で実行)
$ fan -version --Druntime=java Fantom Launcher Copyright (c) 2006-2011, Brian Frank and Andy Frank Licensed under the Academic Free License version 3.0 Java Runtime: java.version: 1.6.0_29 java.vm.name: Java HotSpot(TM) 64-Bit Server VM java.vm.vendor: Apple Inc. java.vm.version: 20.4-b02-402 java.home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home fan.platform: macosx-x86_64 fan.version: 1.0.61 fan.env: sys::BootEnv fan.home: /usr/local/Cellar/fantom/1.0.61/libexec $ fan --Druntime=java hello.fan
実行方法(.NET Framework で実行)
C:¥> fan -version --Druntime=dotnet Fantom Launcher Copyright (c) 2006-2011, Brian Frank and Andy Frank Licensed under the Academic Free License version 3.0 .NET Runtime: clr.version: 2.0.50727.5448 sys.platform: win32-x86 sys.version: 1.0.61 C:¥> fan --Druntime=dotnet hello.fan
実行結果
Hello, Fantom World!
-
Hello, Boo World!
Posted on 1月 26th, 2012 by cx20
Boo
Booは .NET Framework 向けのオブジェクト指向言語である。構文は Python に近い。名前の由来は不明だがロゴ(パックマンの敵キャラに似ている)からお化けのことと思われる。
C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作させることができる。
ソースコード
ソースコード(.NET ライブラリを使用した場合)
実行方法(スクリプトファイルを指定して実行)
$ booi hello.boo
実行方法(実行権限を付与して実行)
$ chmod +x hello.boo $ ./hello.boo
コンパイル&実行方法(Mono)
$ booc hello.boo $ mono ./hello.exe
コンパイル&実行方法(.NET Framework)
C:¥> booc hello.boo C:¥> hello
実行結果
Hello, Boo World!
-
Hello, Cobra World!
Posted on 1月 25th, 2012 by cx20
Cobra
Cobra は .NET Framework 向けのオブジェクト指向言語である。名前の由来は Python(ニシキヘビ)に対するものと思われる。構文は Python の特徴を引き継いでいる。
C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作させることができる。
ソースコード
#!/usr/bin/env cobra class Program def main is shared print 'Hello, Cobra World!'
ソースコード(.NET ライブラリを使用した場合)
#!/usr/bin/env cobra use System class Program def main is shared Console.writeLine('Hello, Cobra World!')
実行方法(スクリプトファイルを指定して実行)
実際には、コンパイルされた後に実行される。
$ cobra hello.cobra
実行方法(実行権限を付与して実行)
$ chmod +x ./hello.cobra $ ./hello.cobra
コンパイル&実行方法(Mono)
$ cobra -c hello.cobra $ mono ./hello.exe
コンパイル&実行方法(.NET Framework)
C:¥> cobra -c hello.cobra C:¥> hello
実行結果
Hello, Cobra World!
-
Hello, Oxygene World!
Posted on 1月 24th, 2012 by cx20
Oxygene
Oxygene は RemObjects Software 社による .NET または Java 環境向けのプログラミング言語である。
Embarcadero 社の Delphi Prism のプログラミング言語として採用されている。
コンパイラ単体は「Command Line Compiler」として無償提供されている。
C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作させることができる。ソースコード(.NET ライブラリを使用した場合)
namespace hello; interface type Hello = class public class method Main(args: array of String): Integer; end; implementation class method Hello.Main(args: array of String): Integer; begin System.Console.WriteLine('Hello, Oxygene World!'); end; end.
ソースコード(Java ライブラリを使用した場合)
namespace hello; interface type Hello = class public class method Main(args: array of String): Integer; end; implementation class method Hello.Main(args: array of String): Integer; begin System.out.println('Hello, Oxygene World!'); end; end.
コンパイル&実行方法(.NET プログラムとしてコンパイル&実行)
C:¥> oxygene HelloDotNet.pas -type:exe -mode:Net C:¥> HelloDotNet
コンパイル&実行方法(Java プログラムとしてコンパイル&実行)
C:¥> oxygene HelloJava.pas -mode:Java C:¥> java -jar hellojava.jar
実行結果
Hello, Oxygene World!
-
Hello, Phalanger World!
Posted on 1月 24th, 2012 by cx20
Phalanger
Phalanger は .NET 環境向けの PHP コンパイラである。名前は「PHP language compiler」の略。
PHP の構文が使える他、.NET Framework のライブラリが使用できる。
C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作できるようになってきている。
ソースコード
ソースコード(.NET ライブラリを使用した場合)
コンパイル方法
C:¥> phpc hello.php
コンパイル方法(.NET Framework を使用する場合)
C:¥> phpc /lang:clr /r:mscorlib hello.php
実行結果
Hello, Phalanger World!
-
Hello, ClojureCLR World!
Posted on 1月 23rd, 2012 by cx20
ClojureCLR
ClojureCLR は Lisp の方言の一つ Clojure の .NET 実装である。
Clojure の構文が使える他、.NET のライブラリが利用できる。
ソースコード
ソースコード(.NET ライブラリを使用した場合)
実行方法(.NET Framework)
C:¥> Clojure.Main hello.clj
実行結果
Hello, ClojureCLR World!