Is it possible to deserialize a Field to a Property?
I want to change a Field to a Property, but this results in problems with deserializing.
Is it somehow possible to deserialize from a Field to a Property?
After changing the from a Field to Property the deserialzed value is null instead.
// Old Class
public class myClass
{
public string limits = "";
}
// New Class
public class myClass
{
public string limits { get; set; } = "";
}
// Code for deserializing byte array (arrBytes)
using (var memStream = new MemoryStream())
{
var binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
var obj = binForm.Deserialize(memStream);
return obj;
}
Is there any way to support the change from a Field to a Property?
c# deserialization
add a comment |
I want to change a Field to a Property, but this results in problems with deserializing.
Is it somehow possible to deserialize from a Field to a Property?
After changing the from a Field to Property the deserialzed value is null instead.
// Old Class
public class myClass
{
public string limits = "";
}
// New Class
public class myClass
{
public string limits { get; set; } = "";
}
// Code for deserializing byte array (arrBytes)
using (var memStream = new MemoryStream())
{
var binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
var obj = binForm.Deserialize(memStream);
return obj;
}
Is there any way to support the change from a Field to a Property?
c# deserialization
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
2
The fact that you require this means you're usingBinaryFormatter
to do the wrong thing.BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from usingBinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away fromBinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.
– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24
add a comment |
I want to change a Field to a Property, but this results in problems with deserializing.
Is it somehow possible to deserialize from a Field to a Property?
After changing the from a Field to Property the deserialzed value is null instead.
// Old Class
public class myClass
{
public string limits = "";
}
// New Class
public class myClass
{
public string limits { get; set; } = "";
}
// Code for deserializing byte array (arrBytes)
using (var memStream = new MemoryStream())
{
var binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
var obj = binForm.Deserialize(memStream);
return obj;
}
Is there any way to support the change from a Field to a Property?
c# deserialization
I want to change a Field to a Property, but this results in problems with deserializing.
Is it somehow possible to deserialize from a Field to a Property?
After changing the from a Field to Property the deserialzed value is null instead.
// Old Class
public class myClass
{
public string limits = "";
}
// New Class
public class myClass
{
public string limits { get; set; } = "";
}
// Code for deserializing byte array (arrBytes)
using (var memStream = new MemoryStream())
{
var binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
var obj = binForm.Deserialize(memStream);
return obj;
}
Is there any way to support the change from a Field to a Property?
c# deserialization
c# deserialization
asked Dec 29 '18 at 16:19
RayUpRayUp
404
404
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
2
The fact that you require this means you're usingBinaryFormatter
to do the wrong thing.BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from usingBinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away fromBinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.
– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24
add a comment |
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
2
The fact that you require this means you're usingBinaryFormatter
to do the wrong thing.BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from usingBinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away fromBinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.
– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
2
2
The fact that you require this means you're using
BinaryFormatter
to do the wrong thing. BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from using BinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away from BinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24
The fact that you require this means you're using
BinaryFormatter
to do the wrong thing. BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from using BinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away from BinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24
add a comment |
1 Answer
1
active
oldest
votes
You could leave the serialization as-is, and wrap a property round the field.
public class myClass
{
public string limits = "";
public string Limits {
get { return limits; }
set { limits = value; }
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971231%2fis-it-possible-to-deserialize-a-field-to-a-property%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could leave the serialization as-is, and wrap a property round the field.
public class myClass
{
public string limits = "";
public string Limits {
get { return limits; }
set { limits = value; }
}
}
add a comment |
You could leave the serialization as-is, and wrap a property round the field.
public class myClass
{
public string limits = "";
public string Limits {
get { return limits; }
set { limits = value; }
}
}
add a comment |
You could leave the serialization as-is, and wrap a property round the field.
public class myClass
{
public string limits = "";
public string Limits {
get { return limits; }
set { limits = value; }
}
}
You could leave the serialization as-is, and wrap a property round the field.
public class myClass
{
public string limits = "";
public string Limits {
get { return limits; }
set { limits = value; }
}
}
answered Dec 29 '18 at 17:04
Richard PetheramRichard Petheram
584712
584712
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971231%2fis-it-possible-to-deserialize-a-field-to-a-property%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This would require some form of custom serialization.
– Jeroen Mostert
Dec 29 '18 at 16:23
2
The fact that you require this means you're using
BinaryFormatter
to do the wrong thing.BinaryFormatter
is suitable for one thing only, and that is transport of objects between different parts of your program, usually between AppDomains. The needs you have now usually stems from usingBinaryFormatter
for storage, which is almost certainly going to cause you lots of grief over time. My advice would be to move away fromBinaryFormatter
completely and use one of the many alternatives more suited for long-term storage, where changes like this can occur.– Lasse Vågsæther Karlsen
Dec 29 '18 at 16:24