none
how can i use dynamic properties of that classes? RRS feed

  • Question

  • i want to make dynamic classes from which user can fill the data in LINQ to  SQL objects.

    how it would be porperties of that dynamic classes? i want to pass dynamic classes 's object to one of my webservice's method.

    how can i use dynamic properties of that classes?


    maifs
    Wednesday, September 15, 2010 6:58 AM

Answers

  • Hello,

    Would you please clarify the "dynamic class" and "dynamic properties"? Do you mean dynamic linq queries? If that's the case, you could use dynamic query library (C# version) from Microsoft. An example of dynamic query is like this:

    NorthwindDataContext northwind = new NorthwindDataContext();
    var query = northwind.Product
               .Where("CategoryID=2 And UnitPrice>3")
               .OrderBy("SupplierId");
    

    For more tutorial and samples, please take a look at this blog entry:
    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Tuesday, September 21, 2010 8:10 AM
    • Unmarked as answer by Mehmood Ahmed Tuesday, October 12, 2010 11:20 AM
    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Monday, September 20, 2010 3:26 AM
  • No, sorry that won't work like that, first when you use var you need to give it a value inmediately in c#

    So:

    var myvar;//doesn't work

    http://msdn.microsoft.com/en-us/library/bb384061.aspx

    Read this, the remark at the end talk about the limitations of var keyword

    Regards

    PS: Perhaps if you explained better then..

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Tuesday, October 12, 2010 3:22 PM
  • Additionally, I think the webservice needs to be explicitly written out at compile time.

    I would try to get around it with the following two classes.  Then just have adapters into them.  You can use reflection to parse the type or create the desired type. On each side of the webservice.

    public class DynamicType
    {
      public List<DynamicProperty> Values;
    }
    
    public class DynamicProperty
    {
      public string Name;
      public object Value;
    }
    
    The common solution to this problem is usually using XML.
    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Tuesday, October 12, 2010 7:51 PM

All replies

  • Hello,

    Would you please clarify the "dynamic class" and "dynamic properties"? Do you mean dynamic linq queries? If that's the case, you could use dynamic query library (C# version) from Microsoft. An example of dynamic query is like this:

    NorthwindDataContext northwind = new NorthwindDataContext();
    var query = northwind.Product
               .Where("CategoryID=2 And UnitPrice>3")
               .OrderBy("SupplierId");
    

    For more tutorial and samples, please take a look at this blog entry:
    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by liurong luo Tuesday, September 21, 2010 8:10 AM
    • Unmarked as answer by Mehmood Ahmed Tuesday, October 12, 2010 11:20 AM
    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Monday, September 20, 2010 3:26 AM
  • sory for late reply. i am talking about implicit classes.

    can i use like this?

    Class A

    {

    NorthwindDataContext northwind = new NorthwindDataContext();
    var query;
    A() { query = northwind.Product
          .Where("CategoryID=2 And UnitPrice>3")
          .OrderBy("SupplierId");}
    public var GetValues(var t)
    {
        t = query ;
        return t;
    }
    }
    

    maifs
    Tuesday, October 12, 2010 11:17 AM
  • No, sorry that won't work like that, first when you use var you need to give it a value inmediately in c#

    So:

    var myvar;//doesn't work

    http://msdn.microsoft.com/en-us/library/bb384061.aspx

    Read this, the remark at the end talk about the limitations of var keyword

    Regards

    PS: Perhaps if you explained better then..

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Tuesday, October 12, 2010 3:22 PM
  • Additionally, I think the webservice needs to be explicitly written out at compile time.

    I would try to get around it with the following two classes.  Then just have adapters into them.  You can use reflection to parse the type or create the desired type. On each side of the webservice.

    public class DynamicType
    {
      public List<DynamicProperty> Values;
    }
    
    public class DynamicProperty
    {
      public string Name;
      public object Value;
    }
    
    The common solution to this problem is usually using XML.
    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:43 AM
    Tuesday, October 12, 2010 7:51 PM