vendredi 20 novembre 2015

How to find out whether given object is Generic List

List<List<HeaderTypeEnq<dynamic>>> IDEnq = new List<List<HeaderTypeEnq<dynamic>>>();
List<HeaderTypeEnq<dynamic>> IDListEnq = new List<HeaderTypeEnq<dynamic>>();

for (int i = 0; i < enq.Id.Count; i++)
{
    IDListEnq.Add(new HeaderTypeEnq<dynamic>() { FieldTag = "ID", FieldName = "Segment Tag", Value = enq.Id[i].SegmentTag, Mandatory = "Y", CharacterType = "A", MaxLength = 03 });
    IDListEnq.Add(new HeaderTypeEnq<dynamic>() { FieldTag = "01", FieldName = "ID Type", Value = enq.Id[i].IDType, Mandatory = "Y", CharacterType = "N", MaxLength = 02 });
    IDListEnq.Add(new HeaderTypeEnq<dynamic>() { FieldTag = "02", FieldName = "ID Number", Value = enq.Id[i].IDNumber, Mandatory = "N", CharacterType = "P", MaxLength = 30 });
    IDEnq.Add(IDListEnq);
}
ValidateValue<List<HeaderTypeEnq<dynamic>>>(IDEnq, concaDel);


private string ValidateValue<T>(object EnqTagList, ValidationDelegate del)
{
    //errorstr = "";

    Type typeParameterType = typeof(T);
    if (typeof(T) == typeof(List<HeaderTypeEnq<dynamic>>))
    {
        //code
    }

As per my understanding if (typeof(T) == typeof(List<HeaderTypeEnq<dynamic>>)) should return false for IDEnq (list of list) but it returns true!





Aucun commentaire:

Enregistrer un commentaire