Example #1
0
 public PengObjectInfo()
 {
     Arguments = new PengObjectArgumentInfo[0];
     Content = "";
     TypeName = typeof(PengObject).FullName;
     Name = "";
     Properties = new PengPropertyInfo[0];
 }
        public void TestToObjectArg()
        {
            PengXmlWorldLoader_Accessor loader = new PengXmlWorldLoader_Accessor();
            var argInfo1 = new PengObjectArgumentInfo();
            argInfo1.Type = "System.Int32";
            argInfo1.Value = "45";
            var arg1 = loader.ToObjectArg(argInfo1, x => Type.GetType(x));
            Assert.AreEqual(typeof(int), arg1.Type);
            Assert.AreEqual(45, arg1.Value);

            var argInfo2 = new PengObjectArgumentInfo();
            argInfo2.Type = "System.Single";
            argInfo2.Value = "36.36";
            var arg2 = loader.ToObjectArg(argInfo2, x => Type.GetType(x));
            Assert.AreEqual(typeof(float), arg2.Type);
            Assert.AreEqual(36.36f, arg2.Value);
        }
Example #3
0
 private ObjectArg ToObjectArg(PengObjectArgumentInfo argInfo, Func<string, Type> typeProvider)
 {
     var argType = typeProvider(argInfo.Type);
     object argValue;
     if (argType == typeof(string))
         argValue = argInfo.Value;
     else if (argType == typeof(int))
         argValue = int.Parse(argInfo.Value);
     else if (argType == typeof(Vector2))
         argValue = ParseVector2(argInfo.Value);
     else if (argType == typeof(float))
         argValue = float.Parse(argInfo.Value, System.Globalization.CultureInfo.InvariantCulture);
     else if (argType.IsEnum)
         argValue = Enum.Parse(argType, argInfo.Value);
     else
         throw new ArgumentException("argInfo");
     return new ObjectArg(argType, argValue);
 }