Skip to content

JsonPersistor.Retrieve: maybe u got a bug #3

@reader-man

Description

@reader-man

in the public static bool Retrieve(out TSettings result, string namePreFix = null, string nameMarker = null) function

                if (File.Exists(fileName))
                {
                    result = new TSettings();

                    string text = null;
                    text = File.ReadAllText(fileName);
                    result = JsonConvert.DeserializeObject(text,
                        new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.Auto,
                            TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
                            PreserveReferencesHandling = PreserveReferencesHandling.All,
                            CheckAdditionalContent = false
                        }) as TSettings;

                    if (result == null)
                        result = new TSettings();
                    return true;
                }
  1. i think having:
    result = new TSettings();
    at the first line of the if, will lead to un-used object, as it will go to garbage collector if the 'DeserializeObject' works, and its enough to have the lines:
                    if (result == null)
                        result = new TSettings();
  1. I think that the line:
    result = JsonConvert.DeserializeObject(text,
    should be:
    result = JsonConvert.DeserializeObject**<TSettings>**(text,

Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions