Hi Everyone How are things?
I for the life of me haven't been able to figure this out. I have been converting a GIS application. What I have is basically a collection in VB and I need to convert it to a linkedlist in c#.
Any help getting started is appreciated.
VB code is below
Imports ESRI.ArcGIS.esriSystem
Public Class clsFeature
Private m_OID As Integer
Private m_Geometry As ESRI.ArcGIS.Geometry.IGeometry
Public Sub New(ByRef iOID As Integer, ByRef pGeometry As ESRI.ArcGIS.Geometry.IGeometry)
m_OID = iOID
m_Geometry = pGeometry
End Sub
Public ReadOnly Property OID() As Integer
Get
OID = m_OID
End Get
End Property
Public ReadOnly Property Geometry() As ESRI.ArcGIS.Geometry.IGeometry
Get
Geometry = m_Geometry
End Get
End Property
End Class
Friend Class clsFeatureCollection
Implements System.Collections.IEnumerable
' linkedlist???????????????????????????????????????
Private m_oCol As Collection
Private m_oColReverse As Collection
Public Sub New()
MyBase.New()
m_oCol = New Collection
m_oColReverse = New Collection
End Sub
Public Sub Add(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, Optional ByRef strBefore As String = "", Optional ByRef strAfter As String = "", Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strBefore <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), strBefore)
ElseIf strAfter <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public Sub AddBefore(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef strBefore As String, Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strBefore <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), strBefore)
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public Sub AddAfter(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef strAfter As String, Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strAfter <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), , strAfter)
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public ReadOnly Property Count() As Short
Get
'Return the number of objects in m_oCol
Count = m_oCol.Count()
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
GetEnumerator = m_oCol.GetEnumerator
End Function
Public Sub Remove(ByRef vIndex As Object)
'Remove the specified object. Note here
'that this method will operate on either
'the index of the object we want removed
'or the key of the object we want removed
m_oCol.Remove(vIndex)
End Sub
Public Function Item(ByRef vIndex As Object) As clsFeature
'Retrieve the specified object. Note here
'that this method will operate on either
'the index of the object we want
'or the key of the object we want
Item = m_oCol.Item(vIndex)
End Function
Public Sub Clear()
'remove all objects from the private collection
m_oCol = New Collection
m_oColReverse = New Collection
End Sub
Public Function Reverse(ByRef val_Renamed As Object) As Boolean
Try
If m_oColReverse.Contains(val_Renamed) Then
Return True
Else
Return False
End If
Catch ex As Exception
If TypeOf ex Is ArgumentException Or TypeOf ex Is IndexOutOfRangeException Then
Reverse = False
End If
End Try
End Function
Public Function ContainsItem(ByRef val_Renamed As Object) As Boolean
Try
If m_oCol.Contains(val_Renamed) Then
Return True
Else
Return False
End If
Catch ex As Exception
If TypeOf ex Is ArgumentException Or TypeOf ex Is IndexOutOfRangeException Then
ContainsItem = False
End If
End Try
End Function
C# code - once I get the linked list correct I should be able to finish the rest
namespace NSTDB_QC_Utility
{
public class clsFeature
{
private int m_OID;
private IGeometry m_Geometry;
public clsFeature(int iOID, IGeometry pGeometry)
{
m_OID = iOID;
m_Geometry = pGeometry;
}
public int OID
{
get { return m_OID; }
}
public IGeometry Geometry
{
get { return m_Geometry; }
}
}
public class clsFeatureCollection : System.Collections.IEnumerable
{
// used dictionary -> Should really use a linked list because of the strBefore and strAfter
// possible but need a way to handle m_ocol and strbefore - result was to reverse m_ocol on the strBefore
public LinkedList<clsFeature> m_oCol;
// public Dictionary<int, object> m_oCol;
public Dictionary<string, string> m_oColReverse;
public clsFeatureCollection()
: base()
{
m_oCol = new LinkedList<clsFeature>();
// m_oCol = new Dictionary<int, object>();
m_oColReverse = new Dictionary<string, string>();
}
public IEnumerator GetEnumerator()
{
return m_oCol.GetEnumerator();
}
Below is the final working solution I came up with. It integrates with the other similar collections. I initially used a list but I needed a string as a key for the other collections