Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonPersistor.Retrieve: maybe u got a bug #3

Open
reader-man opened this issue Oct 31, 2018 · 0 comments
Open

JsonPersistor.Retrieve: maybe u got a bug #3

reader-man opened this issue Oct 31, 2018 · 0 comments

Comments

@reader-man
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant