Exemplo n.º 1
0
        static void BarcodeData()
        {
            var qr = new BarcodeQR()
            {
                IsFixedAspectRatio = false,
                Width         = 5,
                Height        = 5,
                Align         = Alignment.LeftBottom,
                Location      = new System.Numerics.Vector2(0, 0),
                ShapeType     = BarcodeShapeType.Hatch,
                HatchInterval = 0.2f,
                HatchAngle    = 90,
            };

            qr.Data = "HELLO SPIRALLAB SIRIUS LIBRARY";
            qr.Regen();

            string lineOfCodes = @"
            using System; 
            namespace Test 
            {
                class MyClass
                {
                    public string BarcodeData
                    { 
                        get
                        {
                            return string.Format(""{0}-{1}-{2}"", this.Year, this.Month, this.Day);
                        }
                    }
                    public string Year { get; set; }
                    public string Month { get; set; }
                    public string Day { get; set; }
                }
            }";

            qr.ScriptInstanceName = "Test.MyClass";
            qr.ScriptPropertyName = "BarcodeData";
            qr.ScriptArguments    = new string[]
            {
                "Year=2021",
                "Month=08",
                "Day=31",
            };

            if (qr.ScriptCompile(lineOfCodes, out var errors))
            {
                Console.WriteLine("No error(s)");
            }
            else
            {
                foreach (var err in errors)
                {
                    Console.WriteLine(err.ToString());
                }
                Console.ReadKey();
                return;
            }
            qr.ScriptExecute(out var executeResult, true);
            var qrData = qr.TextData;

            Debug.Assert(0 == string.Compare(executeResult, qrData));
            Console.WriteLine($"Barcode entity has changed to {executeResult}");
        }