locked
How to pass class name to method in C#

    Question

  • Hi,

    I am using Sqlite for Windows 8.1 App to store data locally. I want to create SqliteHelper class as generic. I have to pass class name as parameter to method. So how should I achieve this?

    Actually  have to create tables using CreateTableAsync method of Sqlite. It accepts parameter as Class.

    Private async Task CreateTable(strng tbleName)

    {

    await conn.CreateTableAsync<tbleName>()

    }

     It gives error here. Please help me.

    Thursday, February 26, 2015 1:03 PM

All replies

  • So have you created the class already, the name of which you need to pass in CreateTableAsync() method. You need to assign that particular class with 'Table' attribute.

    [Table]
    public class somename
    {
    
    }

    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

    Thursday, February 26, 2015 1:12 PM
  • Hi,

    I am using Sqlite for Windows 8.1 App to store data locally. I want to create SqliteHelper class as generic. I have to pass class name as parameter to method. So how should I achieve this?

    Actually  have to create tables using CreateTableAsync method of Sqlite. It accepts parameter as Class.

    Private async Task CreateTable(strng tbleName)

    {

    await conn.CreateTableAsync<tbleName>()

    }

     It gives error here. Please help me.


    Visual Studio 2015 allows solving this problem with the nameof operator. It's CTP 6 now, not for production yet, but keep it in mind. Cheers.

    Alessandro Del Sole
    Microsoft MVP - Visual Basic: development
    http://community.visual-basic.it/alessandro/

    Thursday, February 26, 2015 5:18 PM