Recuperare un attributo in base al valore di un campo

martedì 30 dicembre 2014 - 12.55
Tag Elenco Tags  C#  |  .NET 4.0

Gemini Profilo | Expert

ciao a tutti
Ho questa classe:
public class Corriere { struct tipoCampo { public string Valore; internal string Campo; } public Corriere() { DestinatarioRagioneSociale = new tipoCampo { Valore = string.Empty, Campo = BRT.VABRSD }; DestinatarioIndirizzo = new tipoCampo { Valore = string.Empty, Campo = BRT.VABIND }; DestinatarioCap = new tipoCampo { Valore = string.Empty, Campo = BRT.VABCAD }; DestinatarioLocalita = new tipoCampo { Valore = string.Empty, Campo = BRT.VABLOD }; DestinatarioProvincia = new tipoCampo { Valore = string.Empty, Campo = BRT.VABPRD }; DestinatarioNazione = new tipoCampo { Valore = string.Empty, Campo = BRT.VABNZD }; Peso = new tipoCampo { Valore = string.Empty, Campo = BRT.VABPKB }; ValoreMerceDichiarato = new tipoCampo { Valore = string.Empty, Campo = BRT.VABVMD }; ValoreMerceDichiaratoDivisa = new tipoCampo { Valore = string.Empty, Campo = BRT.VABVAD }; DestinatarioReferente = new tipoCampo { Valore = string.Empty, Campo = BRT.VABNRC }; DestinatarioTelefono = new tipoCampo { Valore = string.Empty, Campo = BRT.VABTRC }; DestinatarioMail = new tipoCampo { Valore = string.Empty, Campo = BRT.VABEMD }; DestinatarioCellulare = new tipoCampo { Valore = string.Empty, Campo = BRT.VABCEL }; Note = new tipoCampo { Valore = string.Empty, Campo = BRT.VABNOT }; } public tipoCampo DestinatarioRagioneSociale { get; set; } public tipoCampo DestinatarioIndirizzo { get; set; } public tipoCampo DestinatarioCap { get; set; } public tipoCampo DestinatarioLocalita { get; set; } public tipoCampo DestinatarioProvincia { get; set; } public tipoCampo DestinatarioNazione { get; set; } public tipoCampo DestinatarioReferente { get; set; } public tipoCampo DestinatarioTelefono { get; set; } public tipoCampo DestinatarioMail { get; set; } public tipoCampo DestinatarioCellulare { get; set; } public tipoCampo Note { get; set; } public tipoCampo Peso { get; set; } public tipoCampo ValoreMerceDichiarato { get; set; } public tipoCampo ValoreMerceDichiaratoDivisa { get; set; } }

Ho un vettore con i valori: VABIND, VABNZD, ecc

E una lista List<Corriere>

Voglio eseguire un ciclo su tutti i valori contenuti nel vettore e, dato un elemento della lista, recuperare il valore del campo 'Valore' che ha come valore del campo 'Campo' l'elemento del vettore che sto considerando.

Es. sto considerando 'VABIND' e voglio come risultato il valore di DestinatarioIndirizzo.Valore

Come posso fare?

Grazie mille

ysdemarc Profilo | Expert

Così credo non si possa fare, forse si potrebbe utilizzando la Reflection.

Altrimenti non sarebbe più semplice usare un IDictionary<string, string> e nel costruttore aggiungere gli item?
Vincenzo
Programmatore sbilenco
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5