Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codeportingcpp-Csharp
namespace TypesPorting
{
public abstract class AbstractClassWithoutMethods
{
}
public abstract class AbstractClassWithMethods
{
public abstract void SomeAbstractMethod();
public virtual void SomeVirtualMethod()
{
}
public void SomeMethod()
{
}
}
}
namespace MembersPorting
{
public class ClassAutoProperties
{
public int PublicProperty { get; set; }
internal string InternalProperty { get; set; }
protected bool ProtectedProperty { get; set; }
private double PrivateProperty { get; set; }
}
}
using System;
namespace StatementsPorting
{
public class BreakStatements
{
public void BreakForeach(int[] values, int max)
{
foreach (int value in values)
{
Console.WriteLine(value);
if (value > max)
break;
}
}
public void BreakEnclosedForeach(int[][] values, int max)
{
foreach (int[] row in values)
{
if (row.Length == 0)
break;
foreach (int value in row)
{
Console.WriteLine(value);
if (value > max)
break;
}
}
}
public void BreakFor(int max)
{
for (int index = 0; index < max; ++index)
{
Console.WriteLine(index);
if (index % 5 == 4)
break;
}
}
public void BreakEnclosedFor(int max1, int max2)
{
for (int index1 = 0; index1 < max1; ++index1)
{
if (index1 % 14 == 11)
break;
for (int index2 = 0; index2 < max2; ++index2)
{
Console.WriteLine(index1 + index2);
if (index2 % 13 == 7)
break;
}
}
}
public void BreakWhile(int max)
{
int number = 0;
while (number < max)
{
Console.WriteLine(number);
if (number % 5 == 4)
break;
++number;
}
}
public void BreakEnclosedWhile(int max1, int max2)
{
int number1 = 0;
while (number1 < max1)
{
if (number1 % 14 == 11)
break;
int number2 = 0;
while (number2 < max2)
{
Console.WriteLine(number1 + number2);
if (number2 % 5 == 4)
break;
++number2;
}
++number1;
}
}
public void BreakDoWhile(int max)
{
int number = 0;
do
{
Console.WriteLine(number);
if (number % 5 == 4)
break;
++number;
} while (number < max);
}
public void BreakEnclosedDoWhile(int max1, int max2)
{
int number1 = 0;
do
{
if (number1 % 14 == 11)
break;
int number2 = 0;
do
{
Console.WriteLine(number1 + number2);
if (number2 % 5 == 4)
break;
++number2;
} while (number2 < max2);
++number1;
} while (number1 < max1);
}
}
namespace MembersPorting
{
public class ClassConstructors
{
public ClassConstructors()
{
}
public ClassConstructors(string value)
{
}
internal ClassConstructors(int value)
{
}
protected ClassConstructors(bool value)
{
}
private ClassConstructors(double value)
{
}
}
}
using System;
namespace StatementsPorting
{
public class ContinueStatements
{
public void ContinueForeach(int[] values, int max)
{
foreach (int value in values)
{
if (value > max)
continue;
Console.WriteLine(value);
}
}
public void ContinueEnclosedForeach(int[][] values, int max)
{
foreach (int[] row in values)
{
if (row.Length == 0)
continue;
foreach (int value in row)
{
if (value > max)
continue;
Console.WriteLine(value);
}
}
}
public void ContinueFor(int max)
{
for (int index = 0; index < max; ++index)
{
if (index % 5 == 4)
continue;
Console.WriteLine(index);
}
}
public void ContinueEnclosedFor(int max1, int max2)
{
for (int index1 = 0; index1 < max1; ++index1)
{
if (index1 % 14 == 11)
continue;
for (int index2 = 0; index2 < max2; ++index2)
{
if (index2 % 13 == 7)
continue;
Console.WriteLine(index1 + index2);
}
}
}
public void ContinueWhile(int max)
{
int number = 0;
while (number < max)
{
if (number % 5 == 4)
continue;
Console.WriteLine(number);
++number;
}
}
public void ContinueEnclosedWhile(int max1, int max2)
{
int number1 = 0;
while (number1 < max1)
{
if (number1 % 14 == 11)
continue;
int number2 = 0;
while (number2 < max2)
{
if (number2 % 5 == 4)
continue;
Console.WriteLine(number1 + number2);
++number2;
}
++number1;
}
}
public void ContinueDoWhile(int max)
{
int number = 0;
do
{
if (number % 5 == 4)
continue;
Console.WriteLine(number);
++number;
} while (number < max);
}
public void ContinueEnclosedDoWhile(int max1, int max2)
{
int number1 = 0;
do
{
if (number1 % 14 == 11)
continue;
int number2 = 0;
do
{
if (number2 % 5 == 4)
continue;
Console.WriteLine(number1 + number2);
++number2;
} while (number2 < max2);
++number1;
} while (number1 < max1);
}
}
}
namespace TypesPorting
{
public delegate void Delegate1();
public delegate int Delegate2();
public delegate void Delegate3(string arg1, int arg2);
public delegate int Delegate4(string arg1, int arg2);
}
using System;
namespace StatementsPorting
{
public class DoWhileStatements
{
public void DoWhile(int max)
{
int number = 0;
do
{
Console.WriteLine(number);
++number;
} while (number < max);
}
public void EnclosedDoWhile(int max1, int max2)
{
int number1 = 0;
do
{
int number2 = 0;
do
{
Console.WriteLine(number1 + number2);
++number2;
} while (number2 < max2);
++number1;
} while (number1 < max1);
}
public void InfiniteDoWhile()
{
do
{
Console.WriteLine("iteration");
} while (true);
}
}
}
using System;
namespace TypesPorting
{
public enum SimpleEnum
{
Value1 = 1,
Value2,
Value3 = 100,
Value4 = -1,
Value5 = -Value3,
Value6 = -5,
Value7 = 7
}
public enum EnumWithType : uint
{
Value1 = 1,
Value2,
Value3 = 100,
Value4 = SimpleEnum.Value7
}
[Flags]
public enum SimpleFlags
{
Value1 = 1,
Value2 = 2,
Value3 = 4,
Value4 = 8
}
[Flags]
public enum FlagsWithType : uint
{
Value1 = 1,
Value2 = 2,
Value3 = 4,
Value4 = 8
}
}
namespace StatementsPorting
{
public enum SomeEnum
{
Value1 = 1,
Value3 = 3,
Value13 = 13
}
public class EnumTypeCast
{
public void EnumToNumberCasts()
{
SomeEnum source = SomeEnum.Value13;
sbyte dest1 = (sbyte) source;
byte dest2 = (byte) source;
short dest3 = (short) source;
ushort dest4 = (ushort) source;
int dest5 = (int) source;
uint dest6 = (uint) source;
long dest7 = (long) source;
ulong dest8 = (ulong) source;
float dest9 = (float) source;
double dest10 = (double) source;
char dest11 = (char) source;
}
public void NumberEnumToCasts()
{
sbyte source1 = -11;
byte source2 = 13;
short source3 = -333;
ushort source4 = 666;
int source5 = -333333;
uint source6 = 666666;
long source7 = -333333333;
ulong source8 = 666666666;
float source9 = 3.1415926f;
double source10 = 3.1415926;
char source11 = 'X';
SomeEnum dest1 = (SomeEnum) source1;
SomeEnum dest2 = (SomeEnum) source2;
SomeEnum dest3 = (SomeEnum) source3;
SomeEnum dest4 = (SomeEnum) source4;
SomeEnum dest5 = (SomeEnum) source5;
SomeEnum dest6 = (SomeEnum) source6;
SomeEnum dest7 = (SomeEnum) source7;
SomeEnum dest8 = (SomeEnum) source8;
SomeEnum dest9 = (SomeEnum) source9;
SomeEnum dest10 = (SomeEnum) source10;
SomeEnum dest11 = (SomeEnum) source11;
}
}
}
namespace MembersPorting
{
public delegate void SomeDelegate();
public class ClassEvents
{
public event SomeDelegate PublicEvent;
internal event SomeDelegate InternalEvent;
protected event SomeDelegate ProtectedEvent;
private event SomeDelegate PrivateEvent;
}
}
using System;
namespace TypesPorting
{
public class SimpleCustomException : Exception
{
}
public class CustomMessageException : Exception
{
public CustomMessageException()
{
}
public CustomMessageException(string message) : base(message)
{
}
}
public class CustomMessageInnerException : Exception
{
public CustomMessageInnerException()
{
}
public CustomMessageInnerException(string message) : base(message)
{
}
public CustomMessageInnerException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
using System;
using NUnit.Framework;
namespace NUnitTestsPorting
{
[TestFixture]
public class ExpectedException
{
[Test]
[ExpectedException]
public void TestMethod1()
{
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void TestMethod2()
{
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestMethod3()
{
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "expected message")]
public void TestMethod4()
{
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "expected message", MatchType = MessageMatch.Contains)]
public void TestMethod5()
{
}
[Test]
[ExpectedException(typeof(InvalidOperationException), UserMessage = "user message")]
public void TestMethod6()
{
}
[Test]
[ExpectedException(typeof(InvalidOperationException), Handler = "HandleException")]
public void TestMethod7()
{
}
public void HandleException(Exception e)
{
}
}
}
namespace MembersPorting
{
public class ClassFinalizers
{
~ClassFinalizers()
{
/* do nothing */
}
}
}
using System;
namespace StatementsPorting
{
public class ForeachStatements
{
public void Foreach(string[] values)
{
foreach (string value in values)
{
Console.WriteLine(value);
}
}
public void EnclosedForeach(string[][] values)
{
foreach (string[] row in values)
foreach (string value in row)
{
Console.WriteLine(value);
}
}
}
}
namespace StatementsPorting
{
public class ForStatements
{
public void For(int count)
{
for (int index = 0; index < count; ++index)
{
Console.WriteLine(index);
}
}
public void ForWithSeveralCounter(int count1, int count2)
{
for (int index1 = 0, index2 = 0; index1 < count1 && index2 < count2; ++index1, ++index2)
{
Console.WriteLine(index1 + index2);
}
}
public void EnclosedFor(int count1, int count2)
{
for (int index1 = 0; index1 < count1; ++index1)
for (int index2 = 0; index2 < count2; ++index2)
{
Console.WriteLine(index1 + index2);
}
}
public void CustomizedFor(int max)
{
int prev = 1;
int current = 1;
for (; current <= max;)
{
Console.WriteLine(current);
int next = current + prev;
prev = current;
current = next;
}
}
public void InfiniteFor()
{
for (;;)
{
Console.WriteLine("iteration");
}
}
}
}
using System;
namespace TypesPorting
{
public class GenericClass<TInner>
{
}
public class GenericClassWithTypeConstraint<TInner> where TInner : ICloneable
{
}
public class GenericClassWithClassConstraint<TInner> where TInner : class
{
}
public class GenericClassWithStructConstraint<TInner> where TInner : struct
{
}
public class GenericClassWithNewConstraint<TInner> where TInner : new()
{
}
public class GenericClassWithSeveralConstraints<TInner> where TInner : class, ICloneable, new()
{
}
}
using System;
namespace TypesPorting
{
public delegate TOut GenericDelegate<TIn, TOut>(TIn value);
public delegate TOut GenericDelegateWithTypeConstraint<TIn, TOut>(TIn value) where TIn : ICloneable where TOut : IConvertible;
public delegate TOut GenericDelegateWithClassConstraint<TIn, TOut>(TIn value) where TIn : class where TOut : class;
public delegate TOut GenericDelegateWithStructConstraint<TIn, TOut>(TIn value) where TIn : struct where TOut : struct;
public delegate TOut GenericDelegateWithNewConstraint<TIn, TOut>(TIn value) where TIn : new() where TOut : new();
public delegate TOut GenericDelegateWithSeveralConstraints<TIn, TOut>(TIn value) where TIn : class, ICloneable, new() where TOut : struct, IConvertible;
}
using System;
namespace TypesPorting
{
public interface IGenericInterface<TInner>
{
}
public interface IGenericInterfaceWithTypeConstraint<TInner> where TInner : ICloneable
{
}
public interface IGenericInterfaceWithClassConstraint<TInner> where TInner : class
{
}
public interface IGenericInterfaceWithStructConstraint<TInner> where TInner : struct
{
}
public interface IGenericInterfaceWithNewConstraint<TInner> where TInner : new()
{
}
public interface IGenericInterfaceWithSeveralConstraints<TInner> where TInner : class, ICloneable, new()
{
}
}
using System;
namespace MembersPorting
{
public class ClassGenericMethods
{
public void NongenericMethod()
{
}
public void GenericMethod<T>(T value)
{
}
public void GenericMethodWithTypeConstraint<T>(T value) where T : ICloneable
{
}
public void GenericMethodWithClassConstraint<T>(T value) where T : class
{
}
public void GenericMethodWithStructConstraint<T>(T value) where T : struct
{
}
public void GenericMethodWithNewConstraint<T>(T value) where T : new()
{
}
public void GenericMethodWithSeveralConstraint<T>(T value) where T : class, ICloneable, new()
{
}
}
}
using System;
namespace TypesPorting
{
public struct GenericStruct<TInner>
{
}
public struct GenericStructWithTypeConstraint<TInner> where TInner : ICloneable
{
}
public struct GenericStructWithClassConstraint<TInner> where TInner : class
{
}
public struct GenericStructWithStructConstraint<TInner> where TInner : struct
{
}
public struct GenericStructWithNewConstraint<TInner> where TInner : new()
{
}
public struct GenericStructWithSeveralConstraints<TInner> where TInner : class, ICloneable, new()
{
}
}
using System;
namespace StatementsPorting
{
public class IfStatements
{
public void If(int value)
{
if (value >= 666)
Console.WriteLine("iddqd");
}
public void IfElse(int value)
{
if (value <= 666)
Console.WriteLine("iddqd");
else
Console.WriteLine("idkfa");
}
public void SeveralIfElse(int value)
{
if (value < 3)
Console.WriteLine("iddqd");
else if (value < 13)
Console.WriteLine("idkfa");
else if (value < 33)
Console.WriteLine("idclip");
else if (value < 666)
Console.WriteLine("impulse 666");
else
Console.WriteLine("duke nukem must die");
}
}
}
namespace MembersPorting
{
public class ClassIndexers
{
public int this[int index]
{
get { return 0; }
set { /* do nothing */ }
}
internal string this[string index]
{
get { return "iddqd"; }
set { /* do nothing */ }
}
protected bool this[bool index]
{
get { return true; }
set { /* do nothing */ }
}
private object this[object index]
{
get { return new object(); }
set { /* do nothing */ }
}
}
}
using System;
namespace StatementsPorting
{
public class LambdaExpressions
{
public void LambdaWithReturnValueExpressions()
{
int delta = 767;
SomeCalculation(SomeSelector);
SomeCalculation(value => value + 2);
SomeCalculation(value => value + delta);
SomeCalculation(value => value + mSomeDelta);
SomeCalculation(_ => 777);
Func<int, int> selector1 = SomeSelector;
SomeCalculation(selector1);
Func<int, int> selector2 = value => value + 2;
SomeCalculation(selector2);
Func<int, int> selector3 = value => value + delta;
SomeCalculation(selector3);
Func<int, int> selector4 = value => value + mSomeDelta;
SomeCalculation(selector4);
Func<int, int> selector5 = _ => 777;
SomeCalculation(selector5);
}
public void LambdaWithoutReturnValueExpressions()
{
int delta = 767;
SomeProcessor(SomeAction);
SomeProcessor(value => Console.WriteLine(value + 2));
SomeProcessor(value => Console.WriteLine(value + delta));
SomeProcessor(value => Console.WriteLine(value + mSomeDelta));
SomeProcessor(_ => Console.WriteLine(777));
Action<int> action1 = SomeAction;
SomeProcessor(action1);
Action<int> action2 = value => Console.WriteLine(value + 2);
SomeProcessor(action2);
Action<int> action3 = value => Console.WriteLine(value + delta);
SomeProcessor(action3);
Action<int> action4 = value => Console.WriteLine(value + mSomeDelta);
SomeProcessor(action4);
Action<int> action5 = _ => Console.WriteLine(777);
SomeProcessor(action5);
}
public void LambdaCurrying()
{
Func<int, int, int> someFun = (value1, value2) => value1 + value2;
Func<int, int> simpleFun1 = value => someFun(value, 666);
Func<int, int> simpleFun2 = value => someFun(777, value);
Action<int, int> someAction = (value1, value2) => Console.WriteLine(value1 + value2);
Action<int> simpleAction1 = value => someAction(value, 666);
Action<int> simpleAction2 = value => someAction(777, value);
}
public void LambdaReturnedFromFunctionExpressions()
{
Func<int, int> lambda1 = CreateFun(666);
Func<int, int> lambda2 = CreateFun(-13);
}
private void SomeCalculation(Func<int, int> selector)
{
}
private int SomeSelector(int value)
{
return 777;
}
private void SomeProcessor(Action<int> action)
{
}
private void SomeAction(int value)
{
}
private Func<int, int> CreateFun(int delta)
{
return value => value + delta;
}
private int mSomeDelta = 3343;
}
}
namespace MembersPorting
{
public class ClassMethods
{
public void PublicMethod()
{
}
internal void InternalMethod()
{
}
protected void ProtectedMethod()
{
}
private void PrivateMethod()
{
}
}
}
namespace TypesPorting
{
public class OuterClass
{
public class PublicNestedClass
{
}
internal class InternalNestedClass
{
}
protected class ProtectedNestedClass
{
}
private class PrivateNestedClass
{
}
}
}
namespace MembersPorting
{
public class ClassProperties
{
public int PublicProperty
{
get { return mPublicPropertyField; }
set { mPublicPropertyField = value; }
}
public int PublicPropertyWithoutSetter
{
get { return mPublicPropertyField; }
}
public int PublicPropertyWithoutGetter
{
set { mPublicPropertyWithoutGetterField = value; }
}
internal string InternalProperty
{
get { return mInternalPropertyField; }
set { mInternalPropertyField = value; }
}
protected bool ProtectedProperty
{
get { return mProtectedPropertyField; }
set { mProtectedPropertyField = value; }
}
private double PrivateProperty
{
get { return mPrivatePropertyField; }
set { mPrivatePropertyField = value; }
}
private int mPublicPropertyField;
private int mPublicPropertyWithoutSetterField;
private int mPublicPropertyWithoutGetterField;
private string mInternalPropertyField;
private bool mProtectedPropertyField;
private double mPrivatePropertyField;
}
}
using System;
namespace StatementsPorting
{
public class ReturnStatements
{
public void ReturnVoid(int value)
{
if (value < 10)
return;
Console.WriteLine(value);
}
public int ReturnValue(int value)
{
if (value < 10)
return 666;
Console.WriteLine(value);
return 13;
}
}
}
namespace TypesPorting
{
public class SimpleClass
{
}
}
namespace TypesPorting
{
public interface ISimpleInterface
{
}
}
namespace TypesPorting
{
public struct SimpleStruct
{
}
}
using NUnit.Framework;
namespace NUnitTestsPorting
{
[TestFixture]
public class SimpleTest
{
[Test]
public void T1()
{
}
}
}
namespace StatementsPorting
{
public class StandardTypeCast
{
public void SByteTypeCasts()
{
sbyte source = -11;
// implicit casts
short dest1 = source;
int dest2 = source;
long dest3 = source;
float dest4 = source;
double dest5 = source;
// explicit casts
byte dest6 = (byte) source;
ushort dest7 = (ushort) source;
uint dest8 = (uint) source;
ulong dest9 = (ulong) source;
char dest10 = (char) source;
}
public void ByteTypeCasts()
{
byte source = 13;
// implicit casts
short dest1 = source;
ushort dest2 = source;
int dest3 = source;
uint dest4 = source;
long dest5 = source;
ulong dest6 = source;
float dest7 = source;
double dest8 = source;
// explicit casts
sbyte dest9 = (sbyte) source;
char dest10 = (char) source;
}
public void ShortTypeCasts()
{
short source = -333;
// implicit casts
int dest1 = source;
long dest2 = source;
float dest3 = source;
double dest4 = source;
// explicit casts
sbyte dest5 = (sbyte) source;
byte dest6 = (byte) source;
ushort dest7 = (ushort) source;
uint dest8 = (uint) source;
ulong dest9 = (ulong) source;
char dest10 = (char) source;
}
public void UShortTypeCasts()
{
ushort source = 666;
// implicit casts
int dest1 = source;
uint dest2 = source;
long dest3 = source;
ulong dest4 = source;
float dest5 = source;
double dest6 = source;
// explicit casts
sbyte dest7 = (sbyte) source;
byte dest8 = (byte) source;
short dest9 = (short) source;
char dest10 = (char) source;
}
public void IntTypeCasts()
{
int source = -333333;
// implicit casts
long dest1 = source;
float dest2 = source;
double dest3 = source;
// explicit casts
sbyte dest4 = (sbyte) source;
byte dest5 = (byte) source;
short dest6 = (short) source;
ushort dest7 = (ushort) source;
uint dest8 = (uint) source;
ulong dest9 = (ulong) source;
char dest10 = (char) source;
}
public void UIntTypeCasts()
{
uint source = 666666;
// implicit casts;
long dest1 = source;
ulong dest2 = source;
float dest3 = source;
double dest4 = source;
// explicit casts
sbyte dest5 = (sbyte) source;
byte dest6 = (byte) source;
short dest7 = (short) source;
ushort dest8 = (ushort) source;
int dest9 = (int) source;
char dest10 = (char)source;
}
public void LongTypeCasts()
{
long source = -333333333;
// implicit casts
float dest1 = source;
double dest2 = source;
// explicit casts
sbyte dest3 = (sbyte) source;
byte dest4 = (byte) source;
short dest5 = (short) source;
ushort dest6 = (ushort) source;
int dest7 = (int) source;
uint dest8 = (uint) source;
ulong dest9 = (ulong) source;
char dest10 = (char) source;
}
public void ULongTypeCasts()
{
ulong source = 666666666;
// implicit casts;
float dest1 = source;
double dest2 = source;
// explicit casts
sbyte dest3 = (sbyte) source;
byte dest4 = (byte) source;
short dest5 = (short) source;
ushort dest6 = (ushort) source;
int dest7 = (int) source;
uint dest8 = (uint) source;
long dest9 = (long) source;
char dest10 = (char)source;
}
public void FloatTypeCasts()
{
float source = 3.1415926f;
// implicit casts
double dest1 = source;
// explicit casts
sbyte dest2 = (sbyte) source;
byte dest3 = (byte) source;
short dest4 = (short) source;
ushort dest5 = (ushort) source;
int dest6 = (int) source;
uint dest7 = (uint) source;
long dest8 = (long) source;
ulong dest9 = (ulong) source;
char dest10 = (char) source;
}
public void DoubleTypeCasts()
{
double source = 3.1415926;
// explicit casts
sbyte dest1 = (sbyte) source;
byte dest2 = (byte) source;
short dest3 = (short) source;
ushort dest4 = (ushort) source;
int dest5 = (int) source;
uint dest6 = (uint) source;
long dest7 = (long) source;
ulong dest8 = (ulong) source;
float dest9 = (float) source;
char dest10 = (char)source;
}
public void CharTypeCasts()
{
char source = 'A';
// implicit casts
ushort dest1 = source;
int dest2 = source;
uint dest3 = source;
long dest4 = source;
ulong dest5 = source;
float dest6 = source;
double dest7 = source;
// explicit casts
sbyte dest8 = (sbyte) source;
byte dest9 = (byte) source;
short dest10 = (short) source;
}
}
}
namespace TypesPorting
{
public static class StaticClass
{
public static void StaticMethod()
{
}
}
}
namespace MembersPorting
{
public class ClassStaticConstructor
{
static ClassStaticConstructor()
{
}
}
}
namespace MembersPorting
{
public class ClassStaticMethods
{
public static void PublicMethod()
{
}
internal static void InternalMethod()
{
}
protected static void ProtectedMethod()
{
}
private static void PrivateMethod()
{
}
}
}
namespace MembersPorting
{
public class ClassStaticProperties
{
public static int PublicProperty { get; set; }
internal static string InternalProperty { get; set; }
protected static int ProtectedProperty { get; set; }
private static int PrivateProperty { get; set; }
}
}
using System;
namespace StatementsPorting
{
public enum SomeEnum
{
InitValue = 0,
Value = 1,
SomeValue =2,
OtherValue = 3,
YetOneValue = 4,
AnotherValue = 5
}
public class SwitchStatements
{
public void IntSwitch(int value)
{
switch (value)
{
case 3:
Console.WriteLine("3 branch");
break;
case 4:
case 5:
Console.WriteLine("4-5 branch");
break;
case 6:
Console.WriteLine("6 branch with return");
return;
case 7:
Console.WriteLine("7 branch");
break;
default:
Console.WriteLine("default branch");
break;
}
}
public void EnumSwitch(SomeEnum value)
{
switch (value)
{
case SomeEnum.InitValue:
Console.WriteLine("SomeEnum.InitValue branch");
break;
case SomeEnum.Value:
case SomeEnum.SomeValue:
Console.WriteLine("SomeEnum.Value-SomeEnum.SomeValue branch");
break;
case SomeEnum.OtherValue:
Console.WriteLine("SomeEnum.OtherValue branch with return");
return;
case SomeEnum.YetOneValue:
Console.WriteLine("SomeEnum.YetOneValue branch");
break;
default:
Console.WriteLine("default branch");
break;
}
}
public void StringSwitch(string value)
{
switch (value)
{
default:
Console.WriteLine("default branch");
break;
case "iddqd":
Console.WriteLine("iddqd branch");
break;
case "idkfa":
case "idkfa2":
Console.WriteLine("idkfa-idkfa2 branch");
break;
case "idclip":
Console.WriteLine("idclip branch with return");
return;
case "quicken":
Console.WriteLine("quicken branch");
break;
}
}
}
}
using NUnit.Framework;
namespace NUnitTestsPorting
{
[TestFixture]
public class TestWithSetupMethods
{
[SetUp]
public void Setup()
{
mValue += 1;
}
[TearDown]
public void TearDown()
{
mValue -= 1;
}
[TestFixtureSetUp]
public void GlobalSetup()
{
mValue += 10;
}
[TestFixtureTearDown]
public void GlobalTearDown()
{
mValue -= 10;
}
[Test]
public void TestMethod()
{
}
private int mValue = 0;
}
}
using System;
namespace StatementsPorting
{
public class SomeException : Exception
{
}
public class OtherException : Exception
{
}
public class ThrowStatements
{
public void Throw(int value)
{
if (value < 10)
{
Console.WriteLine("Too small value");
throw new SomeException();
}
if (value > 20)
{
Console.WriteLine("Too big value");
throw new OtherException();
}
}
public void RethrowSame()
{
try
{
InnerMethod();
}
catch (SomeException)
{
Console.WriteLine("Catch SomeException");
throw;
}
}
public void RethrowOther()
{
try
{
InnerMethod();
}
catch (SomeException)
{
Console.WriteLine("Catch SomeException");
throw new OtherException();
}
}
private void InnerMethod()
{
}
}
}
using System;
namespace StatementsPorting
{
public class GrandParentException : Exception
{
}
public class ParentException : GrandParentException
{
}
public class ChildException : ParentException
{
}
public class TryCatchFinallyStatements
{
public void TryCatchFinally()
{
try
{
InnerMethod();
}
catch (ChildException)
{
Console.WriteLine("Catch ChildException");
}
catch (ParentException)
{
Console.WriteLine("Catch ParentException");
}
catch (GrandParentException)
{
Console.WriteLine("Catch GrandParentException");
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
}
public void EnclosedTryCatchFinally()
{
try
{
InnerMethod();
try
{
InnerMethod();
}
catch (InvalidOperationException)
{
Console.WriteLine("Catch InvalidOperationException");
}
finally
{
Console.WriteLine("Finally");
}
}
catch (ChildException)
{
Console.WriteLine("Catch ChildException");
}
catch (ParentException)
{
Console.WriteLine("Catch ParentException");
}
catch (GrandParentException)
{
Console.WriteLine("Catch GrandParentException");
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
}
public void EnclosedTryCatchFinallyWithException()
{
try
{
InnerMethod();
try
{
InnerMethod();
}
catch (InvalidOperationException)
{
Console.WriteLine("Catch InvalidOperationException");
}
finally
{
Console.WriteLine("Finally");
throw new Exception();
}
}
catch (ChildException)
{
Console.WriteLine("Catch ChildException");
}
catch (ParentException)
{
Console.WriteLine("Catch ParentException");
}
catch (GrandParentException)
{
Console.WriteLine("Catch GrandParentException");
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
// do something
try
{
//do something
}
catch (Exception e)
{
//do something
}
finally
{
//do something
}
try
{
}
catch (Exception e)
{
}
finally
{
}
}
public void VoidReturnTryCatchFinally()
{
try
{
InnerMethod();
return;
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
}
public int ValueReturnTryCatchFinally()
{
try
{
InnerMethod();
return 1;
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
}
public object ObjReturnTryCatchFinally()
{
try
{
InnerMethod();
return null;
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
finally
{
Console.WriteLine("Finally");
}
}
private void InnerMethod()
{
}
}
}
using System;
namespace StatementsPorting
{
public class GrandParentException : Exception
{
}
public class ParentException : GrandParentException
{
}
public class ChildException : ParentException
{
}
public class TryCatchStatements
{
public void TryCatch()
{
try
{
InnerMethod();
}
catch (ChildException)
{
Console.WriteLine("Catch ChildException");
}
catch (ParentException)
{
Console.WriteLine("Catch ParentException");
}
catch (GrandParentException)
{
Console.WriteLine("Catch GrandParentException");
}
catch (Exception)
{
Console.WriteLine("Catch Exception");
}
}
private void InnerMethod()
{
}
}
}
using System;
namespace StatementsPorting
{
public class TryFinallyStatements
{
public void TryFinally()
{
try
{
InnerMethod();
}
finally
{
Console.WriteLine("Finally");
}
}
public void TryFinallyWithException()
{
try
{
InnerMethod();
}
finally
{
Console.WriteLine("Finally");
throw new Exception();
}
}
public void EnclosedTryFinally()
{
try
{
try
{
InnerMethod();
}
finally
{
Console.WriteLine("Inner finally");
}
}
finally
{
Console.WriteLine("Outer finally");
}
}
public void EnclosedTryFinallyWithException()
{
try
{
try
{
InnerMethod();
}
finally
{
Console.WriteLine("Inner finally");
throw new Exception();
}
}
finally
{
Console.WriteLine("Outer finally");
}
}
public int ValueReturnTry()
{
try
{
return 1;
}
finally
{
Console.WriteLine("finally");
}
}
public void VoidReturnTry()
{
try
{
return;
}
finally
{
Console.WriteLine("finally");
}
}
private void InnerMethod()
{
}
}
}
namespace StatementsPorting
{
public class SomeClass
{
}
public class VarExpressions
{
public void Expressions()
{
var value1 = 666;
var value2 = 666U;
var value3 = 666L;
var value4 = 666LU;
var value5 = 1.2345f;
var value6 = 1.2345;
var value7 = 'X';
var value8 = "iddqd";
var value9 = new SomeClass();
}
}
}
namespace MembersPorting
{
public class ClassVirtualMethods
{
public virtual void VirtualMethod()
{
}
public virtual void OtherVirtualMethod(int value)
{
}
}
}
using System;
namespace StatementsPorting
{
public class WhileStatements
{
public void While(int max)
{
int number = 0;
while (number < max)
{
Console.WriteLine(number);
++number;
}
}
public void EnclosedWhile(int max1, int max2)
{
int number1 = 0;
while (number1 < max1)
{
int number2 = 0;
while (number2 < max2)
{
Console.WriteLine(number1 + number2);
++ number2;
}
++number1;
}
}
public void InfiniteWhile()
{
while (true)
{
Console.WriteLine("iteration");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.