Beispiel #1
0
 public PengObjectInfo()
 {
     Arguments = new PengObjectArgumentInfo[0];
     Content = "";
     TypeName = typeof(PengObject).FullName;
     Name = "";
     Properties = new PengPropertyInfo[0];
 }
Beispiel #2
0
        private void SetObjectPropertyValue(object obj, PengPropertyInfo prop, PengWorld world)
        {
            Contract.Requires(obj != null);
            Contract.Requires(prop != null);

            var propInfo = obj.GetType().GetProperty(prop.Name);
            object propValue;
            if (propInfo.PropertyType == typeof(int))
                propValue = int.Parse(prop.Value, System.Globalization.CultureInfo.InvariantCulture);
            else if (propInfo.PropertyType == typeof(float))
                propValue = float.Parse(prop.Value, System.Globalization.CultureInfo.InvariantCulture);
            else if (propInfo.PropertyType == typeof(string))
                propValue = prop.Value;
            else if (propInfo.PropertyType == typeof(Texture2D))
                propValue = world.LoadContent<Texture2D>(prop.Value);
            else if (propInfo.PropertyType == typeof(Vector2))
                propValue = ParseVector2(prop.Value);
            else if (propInfo.PropertyType.IsEnum)
                propValue = Enum.Parse(propInfo.PropertyType, prop.Value);
            else
                throw new Exception();
            propInfo.SetValue(obj, propValue, null);
        }
 public void TestSetObjectPropertyValue()
 {
     PengXmlWorldLoader_Accessor loader = new PengXmlWorldLoader_Accessor();
     PengObjectExample obj = new PengObjectExample("obj1", null, 0, 0, "");
     var prop = new PengPropertyInfo();
     prop.Name = "Test4";
     prop.Value = "Hi, Bill";
     loader.SetObjectPropertyValue(obj, prop, null);
     Assert.AreEqual("Hi, Bill", obj.Test4);
 }