How can I retrieve the namespace to a string C#

后端 未结 9 1005
一向
一向 2020-12-15 02:38

I am writing a program which needs the namespace of the program but I cant seem to figure out how to retrieve it. I would like the end result to be in a string.

I wa

9条回答
  •  无人及你
    2020-12-15 02:47

    as a roll upp all post answers: getting all columns' values from a table given as a string tableName:

    
         var tableName = "INVENTORY_PRICE";
                    var assembly = Assembly.GetExecutingAssembly();
    
                    var tip = typeof(Form3);
    
                    var t = assembly.GetType(tip.Namespace + "." + tableName);
                    if (t != null)
                    {
                        var foos = db.GetTable(t);
    
                        foreach (var f in foos)
                        {
                            Console.WriteLine(f + ":");
                            foreach (var property in f.GetType().GetProperties())
                                if (property != null)
                                {
                                    var pv = property.GetValue(f, null);
                                    Console.WriteLine("   " + property.Name + ":" + pv);
                                }
    
                            Console.WriteLine("------------------------------------------------");
                        }
                    }
    
    

    it is very easy if we use ado, this sample uses LINQ context...

提交回复
热议问题