martedì 15 dicembre 2009

Vb vs C# (implemetare un interfaccia.... )

A denti stretti .. molto molto stretti ...


Questa la non troppo diversa Interfaccia.....
Public Interface IPlugin

Property PluginName() As String
Property PluginLabel() As String
Property PluginCategory() As String

Sub Execute(ByVal params As Object())

End Interface

Questa la troppo diversa Implementazione dell' Interfaccia.....

Public Class SimpleCalculator
Implements IPlugin

Private _PluginName As String = "SimpleCalculator"
Private _PluginLabel As String = "Simple Calculator"
Private _PluginCategory As String = "Commons"

Public Property PluginName() As String Implements IPlugin.PluginName
Get
Return _PluginName
End Get
Set(ByVal value As String)
_PluginName = value
End Set
End Property

Public Property PluginLabel() As String Implements IPlugin.PluginLabel
Get
Return _PluginLabel
End Get
Set(ByVal value As String)
_PluginLabel = value
End Set
End Property

Public Property PluginCategory() As String Implements IPlugin.PluginCategory
Get
Return _PluginCategory
End Get
Set(ByVal value As String)
_PluginCategory = value
End Set
End Property


Public Sub Execute(ByVal params As Object()) _
Implements IPlugin.Execute

End Sub
End Class


Io io io io ... si ci vorrebbe una bella scarica di "io io io" non è semplice intuire come si fa cosa e perchè ....

Vi siete domandati come si ottiene una classe ASTRATTA.. o UNA STATICA... no ???
bhe la seconda vi posso dire che non esiste.. o quanto meno vi serve un modulo e dichiarare in esso la classe,

STATIC pictureManager AS New PictureManager()

La prima... vi posto l'esempio che forse fa meno male....

Public MustInherit Class FactoryCore

Public iPluginList As List(Of IPlugin)

Private Sub LoadItems()

End Sub

Public MustOverride Sub CreatePlugin()


End Class

La difficoltà sta nel comprendere che si Sottointende, e non che cosa realmente si intende...

MustInherit sottointende che si "deve necessariamente "ESTENDERE QUESTA CLASSE

E' questa è una buona grammatica....

lunedì 14 dicembre 2009

Vb vs C#

mamma mia... che cosa mi è venuto in mente...
Credo che a molti di noi sia capitato di dover passare a vb.net dopo aver lavorato in c# e credo e (anzi) ne sono sicuro che l'esclamazione iniziale sia più che dovuta....

questo esempio si basa sulla serializzazione / deserializzazione.. di un oggetto tramite xml serializer

c#

///
/// Serializza i campi
///

private void Serialize()
{
TextWriter tw = new StreamWriter(fileName);

XmlSerializer xmls = new XmlSerializer(typeof(FieldPrototypeCollection));
xmls.Serialize(tw, fieldDefinitions);

tw.Close();
xmls = null;
}

///
/// Serializza i campi
///

private FieldPrototypeCollection Deserialize()
{
TextReader tr = new StreamReader(fileName);

FieldPrototypeCollection fc = new FieldPrototypeCollection();
XmlSerializer xmls = new XmlSerializer(typeof(FieldPrototypeCollection));
fc = (FieldPrototypeCollection)xmls.Deserialize(tr);

tr.Close();
xmls = null;

return fc;
}


vb
'''
''' Legge il file e lo deserializza
'''

'''
Private sub Serialize()
''
'' serializza le proprietà in un file.
''
Dim xmls As New XmlSerializer(GetType(FieldPrototypeCollectione))
Dim tw As New StreamWriter(fileName)

xmls.Serialize(tw, px)

End Sub

'''
''' Legge il file e lo deserializza
'''

'''
'''
Private Function Deserialize() as FieldPrototypeCollection
''
'' deserializza l'oggetto nelle proprietà
''
Dim xmls As New XmlSerializer(GetType(FieldPrototypeCollection))
Dim tr As New StreamReader(fileName)

dim fc = CType(xmls.Deserialize(tr), FieldPrototypeCollection)

Deserialize = fc
End Function



un po maiuscolo .. un po minuscolo... sarà anche il fatto che poi è tutto disseminato di DIM AS
Non è cosa.. non è proprio cosa...

Rispetto al buon vecchio Vb questo è proprio un cesso di linguaggio .. credo che tutte le nonne di questo mondo
direbbero ...

SE USI QUESTO LINGUAGGIO TI LAVO LA BOCCA CON L'ACQUA BORICA...

Ma se proprio era necessario trasformarlo ad oggetti non si poteva fare qualcosa di utile anche per la sintassi ???

Va bhe sono di parte e questo è chiaro fin dal nome del blog.. però, però quando è troppo è troppo...