-
Notifications
You must be signed in to change notification settings - Fork 100
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
Avoid re-init properties #902
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need these or else you have to initialize
each one, because they will be null
or no instance
when you do new()
; ISerializable.Serialize
or ISerializable.Deserialize
will get exception
object not set to an instance of an object
. Also on some of them Size
won't work because of that reason.
Are always initialized, isn't it? |
No, you would have to do something like this: var obj = new AClass()
{
AProperty = new(),
} |
@@ -33,16 +33,16 @@ public class TransactionLogState : ISerializable, IEquatable<TransactionLogState | |||
public virtual void Deserialize(ref MemoryReader reader) | |||
{ | |||
// It should be safe because it filled from a transaction's notifications. | |||
uint aLen = reader.ReadUInt32(); | |||
var aLen = reader.ReadUInt32(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's just using dynamic type variable now; instead of being bound to a type specific variable.
It's currently done, otherwise you will have a default unused value, that will be changed in |
Yes, But if someone was do Lets have @superboyiii test 1st. before merge. |
Good point, but it call |
public Guid[] StackItemIds { get; protected set; } = []; | ||
public UInt160 ScriptHash { get; protected set; } | ||
public string EventName { get; protected set; } | ||
public Guid[] StackItemIds { get; protected set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
@@ -15,9 +15,9 @@ namespace Neo.Plugins.Store.States | |||
{ | |||
public class TransactionEngineLogState : ISerializable, IEquatable<TransactionEngineLogState> | |||
{ | |||
public Guid[] LogIds { get; private set; } = Array.Empty<Guid>(); | |||
public Guid[] LogIds { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then set can't be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have Create
method and that should be used. Plus you still run into the same problem with null
. So you need to add or remove changes on these files. I marked in review
.
@@ -16,9 +16,9 @@ namespace ApplicationLogs.Store.States | |||
{ | |||
public class TransactionLogState : ISerializable, IEquatable<TransactionLogState> | |||
{ | |||
public Guid[] NotifyLogIds { get; private set; } = Array.Empty<Guid>(); | |||
public Guid[] NotifyLogIds { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
public VMState VmState { get; private set; } | ||
public string Exception { get; private set; } | ||
public long GasConsumed { get; private set; } | ||
public Guid[] StackItemIds { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
public UInt160 ScriptHash { get; private set; } = new(); | ||
public string Message { get; private set; } = string.Empty; | ||
public UInt160 ScriptHash { get; private set; } | ||
public string Message { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
public UInt256 TransactionHash { get; private set; } = new(); | ||
public TriggerType Trigger { get; private set; } = TriggerType.All; | ||
public UInt256 TransactionHash { get; private set; } | ||
public TriggerType Trigger { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
@@ -16,9 +16,9 @@ namespace ApplicationLogs.Store.States | |||
{ | |||
public class BlockLogState : ISerializable, IEquatable<BlockLogState> | |||
{ | |||
public Guid[] NotifyLogIds { get; private set; } = []; | |||
public Guid[] NotifyLogIds { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this required
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this? Kinda ugly:
public virtual void Deserialize(ref MemoryReader reader)
{
// It should be safe because it filled from a block's notifications.
var aLen = reader.ReadUInt32();
var notifyLogIds = new Guid[aLen];
for (var i = 0; i < aLen; i++)
notifyLogIds[i] = new Guid(reader.ReadVarMemory().Span);
// Create a new instance of BlockLogState using the Create factory method
var blockLogState = Create(notifyLogIds);
// Assign the created instance to the current object
NotifyLogIds = blockLogState.NotifyLogIds;
}
Repository moved to neo, please re-open there |
Related to https://github.com/neo-project/neo-modules/pull/898/files#r1584389953