//Main Method static void Main(string[] args) { ParamArray app = new ParamArray(); int sum = app.AddElements(512, 780, 799, 90, 5); Console.WriteLine("The sum is: {0}", sum); Console.ReadKey(); }
public void AddPtrTest() { var p = new Param(); p.MbrParam = "A"; p.MbrData = "B"; var aP = new ParamArray(); aP.AddPtr(p); Assert.AreEqual(1, aP.Count()); Assert.AreEqual("A", aP.GetCurrent().MbrParam); Assert.AreEqual("B", aP.GetCurrent().MbrData); }
internal override void Emit(ILGenerator ilg) { if (Params != null) { foreach (var p in Params) { LocalSymbol ls = (LocalSymbol)p.Symbol; ls.Declare(ilg); var idx = Constant.Create(ls.Index); var skip = ilg.DefineLabel(); var lidx = Constant.Create(ls.Index); ParamArray.EmitGet(ilg); ilg.Emit(OpCodes.Ldlen); ilg.Emit(OpCodes.Conv_I4); lidx.EmitGet(ilg); ilg.Emit(OpCodes.Cgt); ilg.Emit(OpCodes.Brfalse, skip); ParamArray.EmitGet(ilg); lidx.EmitGet(ilg); if (ls.Type.IsReferenceType) { ilg.Emit(OpCodes.Ldelem_Ref); } else { ilg.Emit(OpCodes.Ldelem, ls.Type.Type); } ls.EmitSet(ilg); ilg.MarkLabel(skip); } } if (PCount != null) { PCount.Declare(ilg); ParamArray.EmitGet(ilg); ilg.Emit(OpCodes.Ldlen); ilg.Emit(OpCodes.Conv_I4); PCount.EmitSet(ilg); } Body.Codeblock = this; Body.Emit(ilg); if (Symbol != null) { Symbol.EmitGet(ilg); } ilg.Emit(OpCodes.Ret); }
public void SearchTest() { var aP = new ParamArray(); aP.AddRecord(new Param()); aP.GetCurrent().MbrParam = ("A"); aP.GetCurrent().MbrData = ("B"); aP.AddRecord(new Param()); aP.GetCurrent().MbrParam = ("C"); aP.GetCurrent().MbrData = ("D"); aP.AddRecord(new Param()); aP.GetCurrent().MbrParam = ("E"); aP.GetCurrent().MbrData = ("F"); Assert.AreEqual("D", aP.Search("C")); }
internal override void Emit(ILGenerator ilg) { if (Params != null) { foreach (var p in Params) { LocalSymbol ls = (LocalSymbol)p.Symbol; ls.Declare(ilg); var idx = Constant.Create(ls.Index); var skip = ilg.DefineLabel(); var lidx = Constant.Create(ls.Index); ParamArray.EmitGet(ilg); ilg.Emit(OpCodes.Ldlen); ilg.Emit(OpCodes.Conv_I4); lidx.EmitGet(ilg); ilg.Emit(OpCodes.Cgt); ilg.Emit(OpCodes.Brfalse, skip); ParamArray.EmitGet(ilg); lidx.EmitGet(ilg); ilg.Emit(OpCodes.Ldelem_Ref); ls.EmitSet(ilg); ilg.MarkLabel(skip); } } if (PCount != null) { PCount.Declare(ilg); ParamArray.EmitGet(ilg); ilg.Emit(OpCodes.Ldlen); ilg.Emit(OpCodes.Conv_I4); PCount.EmitSet(ilg); } bool isVoid = true; if (Body != null) { isVoid &= Body.Datatype.NativeType == NativeType.Void; Body.Emit(ilg, true); } if (isVoid) { EmitDefault(ilg, (TypeSymbol)Symbol); } ilg.Emit(OpCodes.Ret); }
internal override void Emit(ILGenerator ilg) { var result = ilg.DeclareLocal(((TypeSymbol)Symbol).Type); Symbol = new LocalSymbol((TypeSymbol)Symbol, result.LocalIndex); if (PCount != null) { PCount.Declare(ilg); ParamArray.EmitGet(ilg); ilg.Emit(OpCodes.Ldlen); ilg.Emit(OpCodes.Conv_I4); PCount.EmitSet(ilg); } Body.Emit(ilg); if (End != null) { ilg.MarkLabel(End.Value); } Symbol.EmitGet(ilg); ilg.Emit(OpCodes.Ret); }
public void ParseBlackWidowInputTest() { var aP = new ParamArray(); aP.ParseBlackWidowInput("A=B|C=D|E=F|", false, '|', false); Assert.AreEqual("D", aP.Search("C")); }
public void ReplaceTest() { var target = new ParamArray(); string cSearch = "XXX"; string cData = "YYY"; target.Replace(cSearch, cData); Assert.AreEqual("YYY", target.Search("XXX")); target.Replace(cSearch, "AAA"); Assert.AreEqual("AAA", target.Search("XXX")); }