Oxygene (znany również jako Chrome) – język programowania pod platformę .NET stworzony przez firmę RemObjects. Oxygene bazuje na języku programowania Object Pascal. Składnia Oxygene jest bardzo podobna do składni Delphi.NET. Kompilator Oxygene w pełni integruje się z Visual Studio 2003/2005/2008. Na chwilę obecną nie istnieją niezależne kompilatory Oxygene wraz z IDE.

Właściwości Język platformy .NET Bazuje na języku Object Pascal Typy anonimowe Anonimowe metody i delegaty Metody asynchroniczne Obsługa .NET 2.0 Obsługa LINQ Obsługa Windows Presentation Foundation. Obsługa Mono

Przykładowe programy Hello World namespace HelloWorld;

interface

type HelloClass = class public class method Main; end;

implementation

class method HelloClass.Main; begin System.Console.WriteLine('Hello World!'); end;

end.

Kontenery generyczne namespace GenericContainer;

interface

type TestApp = class public class method Main; end;

Person = class public property FirstName: String; property LastName: String; end;

implementation

uses System.Collections.Generic;

class method TestApp.Main; begin var myList := new List<Person>; //lista obiektów typu Person myList.Add(new Person(FirstName := 'Boryslaw', LastName := 'Bob')); myList.Add(new Person(FirstName := 'Borys', LastName := 'Bob')); myList.Add(new Person(FirstName := 'BWB', LastName := 'Bob')); Console.WriteLine(myList.FirstName); Console.ReadLine; end;

end.

Metody generyczne namespace GenericMethodTest;

interface

type GenericMethodTest = static class public class method Main; private class method Swap<T>(var left, right : T); class method DoSwap<T>(left, right : T); end;

implementation

class method GenericMethodTest.DoSwap<T>(left, right : T); begin var a := left; var b := right; Console.WriteLine('Type: {0}', typeof(T)); Console.WriteLine('-> a = {0}, b = {1}', a , b); Swap<T>(var a, var b); Console.WriteLine('-> a = {0}, b = {1}', a , b); end;

class method GenericMethodTest.Main; begin var a := 23; //brak deklaracji typu! var b := 15; DoSwap<Integer>(a, b); //bez rzutowania uszczegóławiającego (ang. downcasting) //czyli bez rzutowania zmiennej do pewnego typu pochodnego

var aa := 'abc'; //brak deklaracji typu! var bb := 'def'; DoSwap<String>(aa, bb); //bez rzutowania uszczegóławiającego w tej metodzie

DoSwap(1.1, 1.2); //brak deklaracji typu dla parametrów Console.ReadLine(); end;

class method GenericMethodTest.Swap<T>(var left, right : T); begin var temp := left; left:= right; right := temp; end;

end.

Wyniki:

Typ: System.Int32 -> a = 23, b = 15 -> a = 15, b = 23 Typ: System.String -> a = abc, b = def -> a = def, b = abc Typ: System.Double -> a = 1,1, b = 1,2 -> a = 1,2, b = 1,1

Obsługa typu string w instrukcji case (odpowiednika switch w języku C) case aClassID.ToUpper of 'XYZ': result := TMyXYZClass; 'ABC': result := TMyOtherClass; else raise new Exception('Invalid Class ID'); end;

Rozróżnianie typów klasy w instrukcji case case aClass type of TMyXYZClass: TMyXYZClass(aClass). DoSomething; TMyOtherClass: TMyOtherClass(aClass). DoSomethingElse; else raise new Exception('Invalid Class Reference'); end;

Quine (program generujący swój własny kod źródłowy) unit; interface implementation const a='unit; interface implementation const a='; method Main;const c='const ';const l=#13#10;const p=''''; const b='{0}{1}{0}{1};{3}method Main;{2}c={1}{2}{1};{2}l=#13#10;{2}p={1}{1}{1}{1};{3}'; const d='{2}b={1}{4}{1};{3}{2}d={1}{5}{1};{3}{2}e={1}{6}{1};{3}'; const e='begin System.Console.WriteLine(b+d+e,a,p,c,l,b,d,e);end;end.'; begin System.Console.WriteLine(b+d+e,a,p,c,l,b,d,e);end;end.

Zobacz też (inne języki platformy .NET) C# C++/CLI Delphi / Delphi.NET Delphi Prism Nemerle Visual Basic .NET

(platforma .NET) .NET Mono DotGNU ROTOR MonoDevelop SharpDevelop

Linki zewnętrzne Oxygene Chrome Wiki Oxygene Homepage

Kategoria:Pascal Kategoria:.NET