dimanche 13 octobre 2019

C# Reflection not changing struct

i have a config file that i have as a struct, im trying to modify it with reflection, am i doing it correctly because it doesnt seem to work

here is my method

        internal JsonItems modifyJsonData(JsonItems data, string iName, string iValue)
        {
            try
            {
                var prop = data.GetType().GetProperty(iName);
                if(prop != null)
                {
                    Type t = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                    object safeValue = (iValue == null) ? null : Convert.ChangeType(iValue, t);
                    prop.SetValue(data, safeValue, null);
                    return data;
                }
                return data;

            }
            catch (Exception ex)
            {
                EmbedBuilder b = new EmbedBuilder()
                {
                    Color = Color.Red,
                    Title = "Exeption!",
                    Description = $"**{ex}**"
                };
                Context.Channel.SendMessageAsync("", false, b.Build());
                return data;
            }

and i want it to return the type JsonItems





Aucun commentaire:

Enregistrer un commentaire