diff --git a/CSharpTranslator/tests/Tester/AssemblyInfo.cs b/CSharpTranslator/tests/Tester/AssemblyInfo.cs new file mode 100644 index 0000000..a0047dc --- /dev/null +++ b/CSharpTranslator/tests/Tester/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Tester")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/CSharpTranslator/tests/Tester/DelegateUser.cs b/CSharpTranslator/tests/Tester/DelegateUser.cs new file mode 100644 index 0000000..6826a85 --- /dev/null +++ b/CSharpTranslator/tests/Tester/DelegateUser.cs @@ -0,0 +1,189 @@ +using System; +using System.Collections.Generic; + +namespace Tester.DelegateUser +{ + + public delegate void CompleteCallback (String name, bool result); + + public delegate bool Predicate (T value); + + public delegate void Del (T value); + + [Serializable] + public class DelegateTest + { + + public delegate void NodeSysLogHandler(string fname); + public static event NodeSysLogHandler OnNodeSysLogHandler; // Event handler is fired on change event + + public void EventLogger() { + + OnNodeSysLogHandler += fname => Console.WriteLine("Log:" + fname); + + + + if (OnNodeSysLogHandler != null) + { + OnNodeSysLogHandler("log"); + return; + } + } + + + private Predicate predDel = value => value == "Hello"; + //private event CompleteCallback cbackMember2 = null; + private event CompleteCallback cbackMember = null; + + public CompleteCallback cbackProperty { get; set; } + + public Del printProp { get; set; } + + delegate void TestDelegate (string s); + delegate void TestRefDelegate (string s, ref int cumul); + static void M (string s) + { + Console.WriteLine (s); + } + + public void Notify (string i) + { + Console.Out.WriteLine ("Notify: {0}", i); + } + + public void UserResponse (String nameParam, bool resultParam) + { + Console.Out.WriteLine ("{0} was {1}", nameParam, resultParam); + } + + public void Init (string[] args) + { + + cbackMember = UserResponse; + cbackProperty = new CompleteCallback (UserResponse); + } + + public void SwingIt () + { + CompleteCallback cback = new CompleteCallback (UserResponse); + CompleteCallback cback1 = null; + cback1 = UserResponse; + + CompleteCallback cback2 = new CompleteCallback (this.cbackProperty); + + cback ("kevin", true); + cback1 ("lizzie", true); + cback2 ("jessie", false); + + Del d1 = new Del (Notify); + + d1 ("456"); + + cbackMember ("fred", false); + this.cbackProperty ("thomas", true); + + + // Original delegate syntax required + // initialization with a named method. + TestDelegate testDelA = new TestDelegate (M); + + // C# 2.0: A delegate can be initialized with + // inline code, called an "anonymous method." This + // method takes a string as an input parameter. + TestDelegate testDelB = delegate(string s) { Console.WriteLine (s); }; + + // C# 3.0. A delegate can be initialized with + // a lambda expression. The lambda also takes a string + // as an input parameter (x). + TestDelegate testDelC = (string x) => { Console.WriteLine (x); }; + + // C# 3.0. A delegate can be initialized with + // a lambda expression. The lambda also takes a string + // as an input parameter (x). The type of x is inferred by the compiler. + TestDelegate testDelD = x => { Console.WriteLine (x); }; + + // Invoke the delegates. + testDelA ("Hello. My name is M and I write lines."); + testDelB ("That's nothing. I'm anonymous and "); + testDelC ("I'm a famous author."); + + TestRefDelegate testDela = delegate (string x, ref int cumul) { cumul += 1; Console.WriteLine (x); Console.WriteLine ("cumul is {0}", cumul); }; + TestRefDelegate testDelb = (string x, ref int cumul) => { cumul += 3; Console.WriteLine (x); Console.WriteLine ("cumul is {0}", cumul); }; + TestRefDelegate testDelc = (string x, ref int cumul) => { cumul += 2; Console.WriteLine (x); Console.WriteLine ("cumul is {0}", cumul); }; + TestRefDelegate testDeld = testDela + testDelb + testDelc; + int mycumulator = 0; + testDeld("RefAccumulator", ref mycumulator); + + } + + delegate void DelC (string s); + + static void Hello (string s) + { + System.Console.WriteLine (" Hello, {0}!", s); + } + + static void Goodbye (string s) + { + System.Console.WriteLine (" Goodbye, {0}!", s); + } + + void HelloGoodbye () + { + DelC a, b, c, d; + + // Create the delegate object a that references + // the method Hello: + a = Hello; + + // Create the delegate object b that references + // the method Goodbye: + b = Goodbye; + + // The two delegates, a and b, are composed to form c: + c = a + b; + + // Remove a from the composed delegate, leaving d, + // which calls only the method Goodbye: + d = c - a; + + System.Console.WriteLine ("Invoking delegate a:"); + a ("A"); + System.Console.WriteLine ("Invoking delegate b:"); + b ("B"); + System.Console.WriteLine ("Invoking delegate c:"); + c ("C"); + System.Console.WriteLine ("Invoking delegate d:"); + d ("D"); + + + d += c; + + d += c; + + d -= c; + + System.Console.WriteLine ("Invoking composed delegate d:"); + d ("DA"); + + Del myt = x => Console.WriteLine("And so goodbye from " + x); + this.printProp = x => Console.WriteLine("Hello from " + x); + this.printProp += myt; + printProp += x => Console.WriteLine("And goodbye from " + x); + printProp("kevin"); + this.printProp -= myt; + + printProp("des"); + } + + + public static void DelMain (string[] args) + { + DelegateTest myDel = new DelegateTest (); + myDel.Init (args); + myDel.SwingIt (); + myDel.HelloGoodbye (); + myDel.EventLogger(); + } + } +} diff --git a/CSharpTranslator/tests/Tester/FullOuterPartialInner.cs b/CSharpTranslator/tests/Tester/FullOuterPartialInner.cs new file mode 100644 index 0000000..68476ef --- /dev/null +++ b/CSharpTranslator/tests/Tester/FullOuterPartialInner.cs @@ -0,0 +1,50 @@ +using System; +namespace Tester +{ + // ordinary outer class + public class FullOuterPartialInner + { + public FullOuterPartialInner () + { + } + + public partial class PartialMiddle { + // First part of inner + public partial class PartialInner { + + // interface + public partial interface PartialIF { + int metha(int fred); + } + + // member a + public int a = 0; + } + + // middlea member + public int middlea = 0; + + } + + // a outer member + public int outera = 0; + + + public partial class PartialMiddle { + + // middle b member + public int middleb = 0; + + // Second part of inner + public partial class PartialInner { + // member b + public int b = 0; + + public partial interface PartialIF { + int methb(char fred); + } + } + } + } +} + diff --git a/CSharpTranslator/tests/Tester/Generics.cs b/CSharpTranslator/tests/Tester/Generics.cs new file mode 100644 index 0000000..d5ba1d5 --- /dev/null +++ b/CSharpTranslator/tests/Tester/Generics.cs @@ -0,0 +1,130 @@ +using System; + +namespace Tester.Generics +{ + + class Factory6 where U : new() { + public static U GetNew() { return new U(); } + } + class Program6 { + static void Main6(){ + int i = Factory6.GetNew(); + object obj = Factory6.GetNew(); + // Here, 'i' is equal to 0 and 'obj' references + // an instance of the class 'object'. + } + } + + // Derivation constraint + + // If you wish to use certain members of the instances of a parameter type in a generic, you must apply a derivation constraint. Here is an example which illustrates the syntax: + // + // + // Example 7 + + interface ICustomInterface7 { int Fct(); } + class C7 where U : ICustomInterface7 { + public int AnotherFct(U u) { return u.Fct(); } + } + + // You can apply several interface implementation constraints and one base class inheritance constraint on a same type parameter. In this case, the base class must appear in the list of types. You can also use this constraint conjointly with the default constructor constraint. In this case, the default constructor constraint must appear last: + // + // + // Example 8 + + interface ICustomInterface18 { int Fct1(); } + interface ICustomInterface28 { string Fct2(); } + class BaseClass8{} + class C8 + where U : BaseClass8, ICustomInterface18, ICustomInterface28, new() { + public string Fct(U u) { return u.Fct2(); } + } + + // You cannot use a sealed class or a one of the System.Object, System.Array, System.Delegate, System.Enum or System.ValueType class as the base class of a type parameter. + // + // + // You also cannot use the static members of T like this: + // + // + // Example 9 + + class BaseClass9 { public static void Fct(){} } + class C9 where T : BaseClass9 { + void F(){ + /* commented out to build + // Compilation Error: 'T' is a 'type parameter', + // which is not valid in the given context. + T.Fct(); + */ + // Here is the right syntax to call Fct(). + BaseClass9.Fct(); + } + } + + // A type used in a derivation constraint can be an open or closed generic type. Let's illustrate this using the System.IComparable interface. Remember that the types which implement this interface can see their instances compared to an instance of type T. + // + // + // Example 10 + + class C1A where U : IComparable { + public int Compare( U u, int i ) { return u.CompareTo( i ); } + } + class C2A where U : IComparable { + public int Compare( U u1, U u2 ) { return u1.CompareTo( u2 ); } + } + class C3A where U : IComparable { + public int Compare( U u, V v ) { return u.CompareTo( v ); } + } + class C4A where U : IComparable, IComparable { + public int Compare( U u, int i ) { return u.CompareTo( i ); } + } + + // Note that a type used in a derivation constraint must have a visibility greater or equal to the one of the generic type which contains this parameter type. For example: + // + // + // Example 11 + + /* commented out to build + internal class BaseClassB{} + // Compilation Error: Inconsistent accessibility: + // constraint type 'BaseClass' is less accessible than 'C' + public class CB where T : BaseClassB{} + */ + // To be used in a generic type, certain functionalities can force you to impose certain derivation constraints. For example, if you wish to use a T type parameter in a catch clause, you must constrain T to derive from System.Exception or of one of its derived classes. Also, if you wish to use the using keyword to automatically dispose of an instance of the type parameter, it must be constraint to use the System.IDisposable interface. Finally, if you wish to use the foreach keyword to enumerate the elements of an instance of the parameter type, it must be constraint to implement the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable interface. + // + // + // Take note that in the special case where T is constrained to implement an interface and T is a value type, the call to a member of the interface on an instance of T will not cause a boxing operation. The following example puts this into evidence: + // + // + // Example 12 + // + interface ICounterC{ + void Increment(); + int Val{get;} + } + struct CounterC : ICounterC { + private int i; + public void Increment() { i++; } + public int Val { get { return i; } } + } + class CC where T : ICounterC, new() { + public void Fct(){ + T t = new T(); + System.Console.WriteLine( t.Val.ToString() ); + t.Increment(); // Modify the state of 't'. + System.Console.WriteLine( t.Val.ToString() ); + + // Modify the state of a boxed copy of 't'. + (t as ICounterC).Increment(); + System.Console.WriteLine( t.Val.ToString() ); + } + } + class ProgramC { + static void CMain() { + /* commented out to build + CC c = new CC(); + c.Fct(); + */ + } + } +} \ No newline at end of file diff --git a/CSharpTranslator/tests/Tester/Main.cs b/CSharpTranslator/tests/Tester/Main.cs new file mode 100644 index 0000000..f2ae5d6 --- /dev/null +++ b/CSharpTranslator/tests/Tester/Main.cs @@ -0,0 +1,18 @@ +using System; +namespace Tester +{ + public class MainClass + { + public static void Main (string[] args) + { + + //Tester.DelegateUser.DelegateTest.DelMain(args); + + //Tester.RefOut.RefOutTest.RefOutMain(args); + + Tester.PartialUser.PartialMain(args); + + } + } +} + diff --git a/CSharpTranslator/tests/Tester/Misc.cs b/CSharpTranslator/tests/Tester/Misc.cs new file mode 100644 index 0000000..0a3030c --- /dev/null +++ b/CSharpTranslator/tests/Tester/Misc.cs @@ -0,0 +1,23 @@ +using System; +namespace Tester.Misc +{ + public class Misc + { + public Misc () + { + } + + private int TestProperty + { + get;set; + } + + public void Init (string[] args) + { + // Test incrementing a property + TestProperty = 0; + TestProperty++; + } + } +} + diff --git a/CSharpTranslator/tests/Tester/PartialInner.cs b/CSharpTranslator/tests/Tester/PartialInner.cs new file mode 100644 index 0000000..971dfd9 --- /dev/null +++ b/CSharpTranslator/tests/Tester/PartialInner.cs @@ -0,0 +1,16 @@ +using System; +namespace Tester +{ + + public partial class PartialUser { + public partial class PartialInner + { + private int a = 0; + + public PartialInner () + { + } + } + } +} + diff --git a/CSharpTranslator/tests/Tester/PartialOuterPartialInner.cs b/CSharpTranslator/tests/Tester/PartialOuterPartialInner.cs new file mode 100644 index 0000000..3f6ae2d --- /dev/null +++ b/CSharpTranslator/tests/Tester/PartialOuterPartialInner.cs @@ -0,0 +1,41 @@ +using System; +namespace Tester +{ + // ordinary outer class + public partial class PartialOuterPartialInner + { + public PartialOuterPartialInner () + { + } + + public partial class PartialMiddle { + // First part of inner + public partial class PartialInner { + + // member a + public int a = 0; + } + + // middlea member + public int middlea = 0; + + } + + // a outer member + public int outera = 0; + + + public partial class PartialMiddle { + + // middle b member + public int middleb = 0; + + // Second part of inner + public partial class PartialInner { + // member b + public int b = 0; + } + } + } +} + diff --git a/CSharpTranslator/tests/Tester/PartialOuterPartialInnerB.cs b/CSharpTranslator/tests/Tester/PartialOuterPartialInnerB.cs new file mode 100644 index 0000000..7418246 --- /dev/null +++ b/CSharpTranslator/tests/Tester/PartialOuterPartialInnerB.cs @@ -0,0 +1,38 @@ +using System; +namespace Tester +{ + // ordinary outer class + public partial class PartialOuterPartialInner + { + + public partial class PartialMiddle { + // First part of inner + public partial class PartialInner { + + // member ab + public int ab = 0; + } + + // middlea member + public int middleab = 0; + + } + + // b outer member + public int outerb = 0; + + + public partial class PartialMiddle { + + // middle b member + public int middlebb = 0; + + // Second part of inner + public partial class PartialInner { + // member b + public int bb = 0; + } + } + } +} + diff --git a/CSharpTranslator/tests/Tester/PartialUser.cs b/CSharpTranslator/tests/Tester/PartialUser.cs new file mode 100644 index 0000000..0a9fdc9 --- /dev/null +++ b/CSharpTranslator/tests/Tester/PartialUser.cs @@ -0,0 +1,30 @@ +#define INFILE + +using System; +namespace Tester +{ + public partial class PartialUser + { + public PartialUser () + { + } + + partial void doPart(String[] args) + { + Console.WriteLine("Hello from doPart()" + msg); + } + + partial void doNothingPart(String[] args) + ; + + public partial class PartInner { + } + +#if MONO && (LINUX || INFILE) + public String ToString() { + return "PartialUser"; + } +#endif + } +} + diff --git a/CSharpTranslator/tests/Tester/PartialUserTwo.cs b/CSharpTranslator/tests/Tester/PartialUserTwo.cs new file mode 100644 index 0000000..120445d --- /dev/null +++ b/CSharpTranslator/tests/Tester/PartialUserTwo.cs @@ -0,0 +1,30 @@ +#define INFILE + +using System; +namespace Tester +{ + public partial class PartialUser + { + + string msg = "hello"; + + public bool doIt(String[] args) { + doNothingPart(args); + doPart(args); + return true; + } + + partial void doPart(String[] args) + ; + + public static void PartialMain(String[] args) { + PartialUser part = new PartialUser(); + part.doIt(args); + } + } + + + + +} + diff --git a/CSharpTranslator/tests/Tester/RefOut.cs b/CSharpTranslator/tests/Tester/RefOut.cs new file mode 100644 index 0000000..69584e0 --- /dev/null +++ b/CSharpTranslator/tests/Tester/RefOut.cs @@ -0,0 +1,59 @@ +using System; +namespace Tester.RefOut +{ + public class RefOutTest + { + public RefOutTest () + { + } + + public void testref (ref int xarg) + { + int x = xarg; + x++; + xarg = 23; + throw new Exception(); + } + + void FillArray(out int[] arr) + { + // Initialize the array: + arr = new int[5] { 1, 2, 3, 4, 5 }; + } + + public void Init (string[] args) + { + + int localx = 5; + try { + + if(true) + testref (ref localx); + } catch (Exception) { + // + } + finally { + Console.Out.WriteLine ("The x is {0}", localx); + } + + int[] theArray; // Initialization is not required + + // Pass the array to the callee using out: + FillArray(out theArray); + + // Display the array elements: + System.Console.WriteLine("Array elements are:"); + for (int i = 0; i < theArray.Length; i++) + { + System.Console.Write(theArray[i] + " "); + } + + } + + public static void RefOutMain (string[] args) + { + new RefOutTest ().Init (args); + } + } +} + diff --git a/CSharpTranslator/tests/Tester/Tester.csproj b/CSharpTranslator/tests/Tester/Tester.csproj new file mode 100644 index 0000000..575cf0c --- /dev/null +++ b/CSharpTranslator/tests/Tester/Tester.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + 9.0.21022 + 2.0 + {DFD1D658-C3A4-4AE6-8E34-195F09575AE5} + Exe + Tester + Tester + v4.0 + + + + + 3.5 + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + x86 + true + + + none + false + bin\Release + prompt + 4 + x86 + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharpTranslator/tests/Tester/Tester.sln b/CSharpTranslator/tests/Tester/Tester.sln new file mode 100644 index 0000000..fea8cb7 --- /dev/null +++ b/CSharpTranslator/tests/Tester/Tester.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester", "Tester.csproj", "{DFD1D658-C3A4-4AE6-8E34-195F09575AE5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DFD1D658-C3A4-4AE6-8E34-195F09575AE5}.Debug|x86.ActiveCfg = Debug|x86 + {DFD1D658-C3A4-4AE6-8E34-195F09575AE5}.Debug|x86.Build.0 = Debug|x86 + {DFD1D658-C3A4-4AE6-8E34-195F09575AE5}.Release|x86.ActiveCfg = Release|x86 + {DFD1D658-C3A4-4AE6-8E34-195F09575AE5}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Tester.csproj + EndGlobalSection +EndGlobal