convertir de C# a VB.NET [cerrado]
Frecuentes
Visto 102 veces
-2
Tengo un problema con la conversión de esta paz de código. Intento usar convertidores pero no tuve suerte. Todos los convertidores tienen problemas con esta parte "vista. Filtro = delegado (elemento de objeto)" Gracias de antemano.
private void ApplyFilters()
{
// Get the view
ICollectionView view = CollectionViewSource.GetDefaultView(ItemsSource);
if (view != null)
{
// Create a filter
view.Filter = delegate(object item)
{
// Show the current object
bool show = true;
// Loop filters
foreach (KeyValuePair<string, string> filter in columnFilters)
{
object property = GetPropertyValue(item, filter.Key);
if (property != null)
{
// Check if the current column contains a filter
bool containsFilter = false;
if (IsFilteringCaseSensitive)
containsFilter = property.ToString().Contains(filter.Value);
else
containsFilter = property.ToString().ToLower().Contains(filter.Value.ToLower());
// Do the necessary things if the filter is not correct
if (!containsFilter)
{
show = false;
break;
}
}
}
// Return if it's visible or not
return show;
};
}
}
2 Respuestas
1
Puedes utilizar una Expresión Lambda para convertir el Método anónimo de C#:
view.Filter = Function(item As Object)
' Show the current object
Dim show As Boolean = True
' Loop filters
For Each filter As KeyValuePair(Of String, String) In columnFilters
Dim prop As Object = GetPropertyValue(item, filter.Key)
If prop IsNot Nothing Then
' Check if the current column contains a filter
Dim containsFilter As Boolean = False
If IsFilteringCaseSensitive Then
containsFilter = prop.ToString().Contains(filter.Value)
Else
containsFilter = prop.ToString().ToLower().Contains(filter.Value.ToLower())
End If
' Do the necessary things if the filter is not correct
If Not containsFilter Then
show = False
Exit For
End If
End If
Next
' Return if it's visible or not
Return show
End Function
Respondido 24 ago 12, 21:08
Ya probé esta solución pero no funciona. - neobgd
0
Es porque VB.Net no admite métodos anónimos.
Puede intentar extraer el código de delegado en una llamada de función separada y luego ejecutarlo a través de un convertidor.
Respondido 24 ago 12, 21:08
Gracias por tu respuesta pero ya lo intento. No funciona. - neobgd
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# vb.net or haz tu propia pregunta.
¿Qué has intentado?? SO no es un servicio de traducción de idiomas. Es un sitio de preguntas y respuestas relacionado con la programación, así que utilícelo como tal. También por favor lea el Preguntas Frecuentes. - Darin Dimitrov