locked
get dynamically property of dynamic class RRS feed

  • Question

  • User-1045082127 posted

    hi there .

    in our scenario I used  a (paste to json) extension and some class and their properties are generated automatically .

    but i want to get all classes and properties which was generated dynamically to create a DataTable and etc...

    but my question is how can i get all property and class names?

        class Json
        {
    
            public class Rootobject
            {
                public Cheshme[] cheshme { get; set; }
                public Qanat[] qanat { get; set; }
            }
    
            public class Cheshme
            {
                public float Accuracy { get; set; }
                public object AccuracyPayeenDast { get; set; }
                public int AmarEdited { get; set; }
                public int AmarIsSend { get; set; }
                public string AmarSaveDate { get; set; }
                public string AmarSendDate { get; set; }
                public string AmarSenderPhone { get; set; }
                public float AmarUserDistance { get; set; }
                public int AmarUserId { get; set; }
                public int BaseId { get; set; }
                public string CheshmeAbadiName { get; set; }
                public int CheshmeAbdehiBaTajhizat { get; set; }
                public object CheshmeAbdehiDarAvg { get; set; }
                public float CheshmeAbdehiDarFaslKhosk { get; set; }
                public int CheshmeAbdehiDarFaslMartoob { get; set; }
                public int CheshmeAbdehiPayeenDast { get; set; }
                public int CheshmeAloodegiGhabelMoshahede { get; set; }
                public string CheshmeBakhshName { get; set; }
                public string CheshmeCode { get; set; }
                public string CheshmeCodeAbMantaghe { get; set; }
                public string CheshmeCodeMahdode { get; set; }
                public float CheshmeDamayeAb { get; set; }
                public int CheshmeDarsadMasrafAbziParvari { get; set; }
                public int CheshmeDarsadMasrafBasteBandi { get; set; }
                public int CheshmeDarsadMasrafDamTyoor { get; set; }
                public int CheshmeDarsadMasrafFazayeSabz { get; set; }
                public int CheshmeDarsadMasrafGiyahanDaroo { get; set; }
                public int CheshmeDarsadMasrafGolkhane { get; set; }
                public int CheshmeDarsadMasrafKeshavarzi { get; set; }
                public int CheshmeDarsadMasrafKhademat { get; set; }
                public int CheshmeDarsadMasrafSanat { get; set; }
                public int CheshmeDarsadMasrafSayerMasaref { get; set; }
                public int CheshmeDarsadMasrafShorbRoostayi { get; set; }
                public int CheshmeDarsadMasrafShorbShahri { get; set; }
                public int CheshmeDarsadUnused { get; set; }
                public int CheshmeHedayatElectric { get; set; }
                public int CheshmeId { get; set; }
                public int CheshmeJensSangMashar { get; set; }
                public int CheshmeKarkardDarBahar { get; set; }
                public int CheshmeKarkardDarPayeez { get; set; }
                public int CheshmeKarkardDarTabestan { get; set; }
                public int CheshmeKarkardDarZemestan { get; set; }
                public object CheshmeKarkardHajmBahrebardariSalane { get; set; }
                public int CheshmeKarkardKolSalane { get; set; }
                public int CheshmeKarkardSaatBahar { get; set; }
                public object CheshmeKarkardSaatBaharKol { get; set; }
                public int CheshmeKarkardSaatPayeez { get; set; }
                public object CheshmeKarkardSaatPayeezKol { get; set; }
                public int CheshmeKarkardSaatTabestan { get; set; }
                public object CheshmeKarkardSaatTabestanKol { get; set; }
                public int CheshmeKarkardSaatZemestan { get; set; }
                public object CheshmeKarkardSaatZemestanKol { get; set; }
                public string CheshmeKeshtGhaleb { get; set; }
                public string CheshmeMalek { get; set; }
                public int CheshmeMasahtBagh { get; set; }
                public int CheshmeMazharUtmX { get; set; }
                public int CheshmeMazharUtmY { get; set; }
                public int CheshmeMazharUtmZ { get; set; }
                public string CheshmeMolahezat { get; set; }
                public int CheshmeNahveTozeeAb { get; set; }
                public string CheshmeName { get; set; }
                public string CheshmeNameAbMantaghe { get; set; }
                public string CheshmeNameMahdode { get; set; }
                public int CheshmeNoeDama { get; set; }
                public int CheshmeNoeKeyfiyat { get; set; }
                public int CheshmeNoeRikhtar { get; set; }
                public int CheshmeNoeSakhtar { get; set; }
                public string CheshmeOstanName { get; set; }
                public float CheshmePh { get; set; }
                public int CheshmeRaveshAbyari { get; set; }
                public int CheshmeSathZirKesht { get; set; }
                public string CheshmeShahrName { get; set; }
                public string CheshmeShomareParvandeGhadim { get; set; }
                public string CheshmeShomareParvandeJadid { get; set; }
                public int CheshmeTadavomAbdehi { get; set; }
                public object CheshmeTakhliyeSalane { get; set; }
                public string CheshmeTarikhAmar { get; set; }
                public string CheshmeTarikhAndazegiriKhoshk { get; set; }
                public string CheshmeTarikhAndazegiriMartoob { get; set; }
                public int CheshmeTedadRoozAbdariSal { get; set; }
                public int CheshmeUtmXManual { get; set; }
                public object CheshmeUtmXManualPayeenDast { get; set; }
                public object CheshmeUtmXPayeenDast { get; set; }
                public int CheshmeUtmYManual { get; set; }
                public object CheshmeUtmYManualPayeenDast { get; set; }
                public object CheshmeUtmYPayeenDast { get; set; }
                public int CheshmeUtmZManual { get; set; }
                public int CheshmeUtmZone { get; set; }
                public int CheshmeUtmZoneManual { get; set; }
                public int CheshmeVasileAbdehiBaTajhizat { get; set; }
                public int CompanyId { get; set; }
                public int SeriId { get; set; }
                public int ServerSaveId { get; set; }
                public string UniqueId { get; set; }
            }
    
            public class Qanat
            {
                public int AmarEdited { get; set; }
                public int AmarIsSend { get; set; }
                public string AmarSaveDate { get; set; }
                public string AmarSendDate { get; set; }
                public float AmarUserDistance { get; set; }
                public int AmarUserId { get; set; }
                public int BaseId { get; set; }
                public int CompanyId { get; set; }
                public string QanatAbadiName { get; set; }
                public int QanatAbdehiBaTajhizat { get; set; }
                public int QanatAbdehiDarAvg { get; set; }
                public float QanatAbdehiDarFaslKhosk { get; set; }
                public int QanatAbdehiDarFaslMartoob { get; set; }
                public int QanatAloodegiGhabelMoshahede { get; set; }
                public string QanatBakhshName { get; set; }
                public int QanatChahBejayeQanat { get; set; }
                public string QanatCode { get; set; }
                public string QanatCodeAbMantaghe { get; set; }
                public string QanatCodeMahdode { get; set; }
                public float QanatDamayeAb { get; set; }
                public int QanatDarsadMasrafAbziParvari { get; set; }
                public int QanatDarsadMasrafBasteBandi { get; set; }
                public int QanatDarsadMasrafDamTyoor { get; set; }
                public int QanatDarsadMasrafFazayeSabz { get; set; }
                public int QanatDarsadMasrafGiyahanDaroo { get; set; }
                public int QanatDarsadMasrafGolkhane { get; set; }
                public int QanatDarsadMasrafKeshavarzi { get; set; }
                public int QanatDarsadMasrafKhademat { get; set; }
                public int QanatDarsadMasrafSanat { get; set; }
                public int QanatDarsadMasrafSayerMasaref { get; set; }
                public int QanatDarsadMasrafShorbRoostayi { get; set; }
                public int QanatDarsadMasrafShorbShahri { get; set; }
                public int QanatDarsadUnused { get; set; }
                public int QanatHedayatElectric { get; set; }
                public int QanatId { get; set; }
                public int QanatJensSangMazhar { get; set; }
                public int QanatKarkardDarBahar { get; set; }
                public int QanatKarkardDarPayeez { get; set; }
                public int QanatKarkardDarTabestan { get; set; }
                public int QanatKarkardDarZemestan { get; set; }
                public int QanatKarkardHajmBahrebardariSalane { get; set; }
                public int QanatKarkardKolSalane { get; set; }
                public int QanatKarkardSaatBahar { get; set; }
                public object QanatKarkardSaatBaharKol { get; set; }
                public int QanatKarkardSaatPayeez { get; set; }
                public object QanatKarkardSaatPayeezKol { get; set; }
                public int QanatKarkardSaatTabestan { get; set; }
                public object QanatKarkardSaatTabestanKol { get; set; }
                public int QanatKarkardSaatZemestan { get; set; }
                public object QanatKarkardSaatZemestanKol { get; set; }
                public string QanatKeshtGhaleb { get; set; }
                public object QanatMadarChahAccuracy { get; set; }
                public object QanatMadarUtmX { get; set; }
                public object QanatMadarUtmXManual { get; set; }
                public object QanatMadarUtmY { get; set; }
                public object QanatMadarUtmYManual { get; set; }
                public object QanatMadarUtmZ { get; set; }
                public object QanatMadarUtmZManual { get; set; }
                public object QanatMadarUtmZone { get; set; }
                public string QanatMalek { get; set; }
                public int QanatMasahtBagh { get; set; }
                public object QanatMazharAccuracy { get; set; }
                public int QanatMazharUtmX { get; set; }
                public int QanatMazharUtmXManual { get; set; }
                public int QanatMazharUtmY { get; set; }
                public int QanatMazharUtmYManual { get; set; }
                public object QanatMazharUtmZ { get; set; }
                public object QanatMazharUtmZManual { get; set; }
                public int QanatMazharUtmZone { get; set; }
                public string QanatMolahezat { get; set; }
                public int QanatNahveTozeeAb { get; set; }
                public string QanatName { get; set; }
                public string QanatNameAbMantaghe { get; set; }
                public string QanatNameMahdode { get; set; }
                public int QanatOmghMadarChah { get; set; }
                public string QanatOstanName { get; set; }
                public float QanatPh { get; set; }
                public int QanatRaveshAbyari { get; set; }
                public int QanatSathZirKesht { get; set; }
                public string QanatShahrName { get; set; }
                public string QanatShomareMojavezAkharinLayroobi { get; set; }
                public string QanatShomareMojavezAkharinPishkari { get; set; }
                public string QanatShomareParvandeChahGhadim { get; set; }
                public string QanatShomareParvandeChahJadid { get; set; }
                public string QanatShomareParvandeGhadim { get; set; }
                public string QanatShomareParvandeJadid { get; set; }
                public int QanatTakhliyeSalane { get; set; }
                public string QanatTarikhAkharinLayroobi { get; set; }
                public string QanatTarikhAkharinPishkari { get; set; }
                public string QanatTarikhAmar { get; set; }
                public string QanatTarikhAndazegiriKhoshk { get; set; }
                public string QanatTarikhAndazegiriMartoob { get; set; }
                public int QanatTedadMileChah { get; set; }
                public int QanatTedadReshteFaree { get; set; }
                public int QanatTedadRoozAbdariSal { get; set; }
                public int QanatToolBolandtarinReshte { get; set; }
                public int QanatVasileAbdehiBaTajhizat { get; set; }
                public int QanatVazeeat { get; set; }
                public string QanatVazeeatAbdehi { get; set; }
                public int SeriId { get; set; }
                public int ServerSaveId { get; set; }
                public string UniqueId { get; set; }
            }
    
        }
    

    Friday, October 19, 2018 1:47 PM

All replies

  • User753101303 posted

    Hi,

    Not really clear. Where do you have a dynamic class ? It seems you are looking for https://docs.microsoft.com/en-us/dotnet/api/system.type.getproperties?view=netframework-4.7.2 or maybe you could use a Dictionary<Key,Object> to deserialize some objects so that you access their properties using a key/value couple ?

    Your ultimate goal is really to put back json data into a DataTable ???? You can't work on .NET data or at worst on a Dictionary<string,object> ?

    Friday, October 19, 2018 2:20 PM
  • User-893317190 posted

    Hi aminsoraya,

    If you want to get classes and properties ,you could use reflection, below is a sample of get all the classes and properties with the namespace "MyWebFormCases.Models"

    List<Type> classes=   typeof(Category).Assembly.GetTypes().Where(t=>t.Namespace== "MyWebFormCases.Models").ToList() ;
                
                foreach (Type clazz in classes)
                {
                    Response.Write(clazz.FullName + "<br/>");
                    foreach (PropertyInfo  prop in clazz.GetProperties() )
                    {
                        Response.Write(prop.Name+",");
                    }
                    Response.Write("<br/><br/>");
                }

    The result.

    Best regards,

    Ackerly Xu

    Wednesday, October 24, 2018 6:13 AM