Ejemplo n.º 1
0
    private static void SetProperty(object obj, string property, string value, string typeOverride = "NullType")
    {
        /*Debug.Log("Properties found for " + obj.GetType().ToString() + ":");
         * foreach (PropertyInfo p in obj.GetType().GetProperties())
         * {
         * Debug.Log(p.Name);
         * }*/

        if (property == "Value")
        {
            Debug.Log("Working With Value");
        }

        PropertyInfo pInfo = obj.GetType().GetProperty(PP.GetParameterLiteralName(property));

        if (pInfo == null)
        {
            Debug.LogError(property + " was not found in type " + obj.GetType().ToString());
        }
        else
        {
            object val;
            if (typeOverride == "NullType")
            {
                val = TypeConversion.Convert(PP.GetParameterType(property), value);
            }
            else
            {
                val = TypeConversion.Convert(Type.GetType(typeOverride), value);
            }

            pInfo.SetValue(obj, val, null);
            try
            {
                Debug.Log("Successfully set " + property + " for " + obj.GetType().ToString() + " as " + pInfo.GetValue(obj, null).ToString());
            }
            catch { Debug.LogWarning("If not \"Path\", report to programmer: " + pInfo.Name); } // SoundObjs should be the only thing to cause this
        }
    }