IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Serialization d'un membre partagé "Shared"


Sujet :

VB.NET

  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Par défaut Serialization d'un membre partagé "Shared"
    Bonsoir à tous,
    J'arrive à serializer une classe sauf les membres déclarés "Shared" comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
        <Serializable()>
        Public Class clsVideoData
            <NonSerialized()> Private Shared _Container As PictureBox
            <NonSerialized()> Private Shared _ListBox As ListBox
            <NonSerialized()> Private Shared _ContainerVideo As PictureBox
            <NonSerialized()> Private Shared _ComboBoxLogo As ComboBox
            ' Informations generales sur la video
            Private Shared _NbFrames As Integer
            Private Shared _Fps As Integer
            Private Shared _Durée As Double
            Private Shared _AverageFrame As Double
            Private Shared _SARWidht As Integer
            Private Shared _SARHeight As Integer
            Private Shared _SCGx As Integer
            Private Shared _SCGy As Integer
            Private Shared _SCGxTl As Integer
            Private Shared _SCGyTl As Integer
            Private _Cuts As New clsCuts
            Private _Crops As New clsCrops
            Private _Logo As New clsLogo
            <NonSerialized()> Private Shared _Logos As New clsLogos
     
            Public Sub New()
     
            End Sub
     
            Public Sub Clear()
                _Container.Controls.Clear()
                _ListBox.Items.Clear()
                _Cuts.Clear()
                _Crops.Clear()
                _Logo.Clear()
            End Sub
            Public Shared Property Container As PictureBox
                Get
                    Return _Container
                End Get
                Set(ByVal value As PictureBox)
                    _Container = value
                    _SCGxTl = _Container.Width
                    _SCGyTl = _Container.Height
                End Set
            End Property
            Public Shared Property ListBox As ListBox
                Get
                    Return _ListBox
                End Get
                Set(ByVal value As ListBox)
                    _ListBox = value
                    '_SCGx = _ContainerVideo.Width
                    '_SCGy = _ContainerVideo.Height
                End Set
            End Property
            Public Shared Property ContainerVideo As PictureBox
                Get
                    Return _ContainerVideo
                End Get
                Set(ByVal value As PictureBox)
                    _ContainerVideo = value
                    _SCGx = _ContainerVideo.Width
                    _SCGy = _ContainerVideo.Height
                End Set
            End Property
            Public Shared Property ComboBoxLogo As ComboBox
                Get
                    Return _ComboBoxLogo
                End Get
                Set(ByVal value As ComboBox)
                    _ComboBoxLogo = value
                End Set
            End Property
            Public Shared Property NbFrames As Integer
                Get
                    Return _NbFrames
                End Get
                Set(ByVal value As Integer)
                    _NbFrames = value
                    If Not _NbFrames = 0 Then AverageFrame = _Durée / _NbFrames
                End Set
            End Property
    ......
    End Class
    Savez vous comment Serializer les membres partagés comme par exemple la propriété NbFrames ?

    En vous remerciant par avance.

  2. #2
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 197
    Par défaut
    ca me paraitrait étrange que ca soit faisable, shared veut dire partagé, et la sérialisation se fait sur des instances ...

    après tu peux bricoler à faire une propriété qui pointe vers la propriété shared ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre éclairé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Par défaut
    Bonsoir, merci de m'avoir répondu Pol63.
    J'ai du faire une serialization personnalisée comme ceci :
    (J'espère ne pas avoir fait une mauvaise utilisation des fonctionnalités du FrameWork VB.NET comme ça m'arrive parfois....mais apriori ça fonctionne très bien).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
        <Serializable()>
        Public Class clsVideoData
            Implements ISerializable, IDeserializationCallback
            <NonSerialized()> Private Shared _Container As PictureBox
            <NonSerialized()> Private Shared _ListBox As ListBox
            <NonSerialized()> Private Shared _ContainerVideo As PictureBox
            <NonSerialized()> Private Shared _ComboBoxLogo As ComboBox
            ' Informations generales sur la video
            Private Shared _NbFrames As Integer
            Private Shared _Fps As Integer
            Private Shared _Durée As Double
            Private Shared _AverageFrame As Double
            Private Shared _SARWidht As Integer
            Private Shared _SARHeight As Integer
            Private Shared _SCGx As Integer
            Private Shared _SCGy As Integer
            Private Shared _SCGxTl As Integer
            Private Shared _SCGyTl As Integer
            Private _Cuts As New clsCuts
            Private _Crops As New clsCrops
            Private _Logo As New clsLogo
            <NonSerialized()> Private Shared _Logos As New clsLogos
    #Region "ISerializable Members and déserialisable constructor"
            ' Serialisation et déserialisation personnalisée :
            Private Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
                ' propriétés a serializer
                info.AddValue("NbFrames", _NbFrames)
                info.AddValue("Fps", _Fps)
                info.AddValue("Durée", _Durée)
                info.AddValue("AverageFrame", _AverageFrame)
                info.AddValue("SARWidht", _SARWidht)
                info.AddValue("SARHeight", _SARHeight)
                info.AddValue("SCGXtl", _SCGxTl)
                info.AddValue("SCGYtl", _SCGyTl)
                info.AddValue("Cuts", _Cuts)
                info.AddValue("Crops", _Crops)
                info.AddValue("Logo", _Logo)
            End Sub
            Public Sub New(info As SerializationInfo, context As StreamingContext)
                ' Propriétés a deserializer
                _NbFrames = DirectCast(info.GetValue("NbFrames", GetType(Integer)), Integer)
                _Fps = DirectCast(info.GetValue("Fps", GetType(Integer)), Integer)
                _Durée = DirectCast(info.GetValue("Durée", GetType(Double)), Double)
                _AverageFrame = DirectCast(info.GetValue("AverageFrame", GetType(Double)), Double)
                _SARWidht = DirectCast(info.GetValue("SARWidht", GetType(Integer)), Integer)
                _SARHeight = DirectCast(info.GetValue("SARHeight", GetType(Integer)), Integer)
                _SCGxTl = DirectCast(info.GetValue("SCGXtl", GetType(Integer)), Integer)
                _SCGyTl = DirectCast(info.GetValue("SCGYtl", GetType(Integer)), Integer)
                _Cuts = DirectCast(info.GetValue("Cuts", GetType(clsCuts)), clsCuts)
                _Crops = DirectCast(info.GetValue("Crops", GetType(clsCrops)), clsCrops)
                _Logo = DirectCast(info.GetValue("Logo", GetType(clsLogo)), clsLogo)
            End Sub
            Private Sub OnDeserialization(ByVal sender As Object) Implements System.Runtime.Serialization.IDeserializationCallback.OnDeserialization
                ' Procedure pour restaurer les objets qui n'ont pas pu être sérializé
                ' ......
            End Sub
    #End Region
    .....
    End Class

+ Répondre à la discussion
Cette discussion est résolue.

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo