public byte[] ToByteArray() { using (var ms = new MemoryStream()) { using (var writer = new NearBinaryWriter(ms)) { switch (PermissionType) { case AccessKeyPermissionType.FullAccessPermission: { writer.Write((byte)AccessKeyPermissionType.FullAccessPermission); writer.Write(FullAccess.ToByteArray()); return(ms.ToArray()); } case AccessKeyPermissionType.FunctionCallPermission: { writer.Write((byte)AccessKeyPermissionType.FunctionCallPermission); writer.Write(FunctionCall.ToByteArray()); return(ms.ToArray()); } default: throw new NotSupportedException("Unsupported access key permission type"); } } } }