DevForce Help Reference
Convert(Object) Method
Example 


Convert a single anonymously-typed object into a dynamically-typed object.
Syntax
'Declaration
 
Public Overloads Shared Function Convert( _
   ByVal anonObject As Object _
) As Object
'Usage
 
Dim anonObject As Object
Dim value As Object
 
value = DynamicTypeConverter.Convert(anonObject)
public static object Convert( 
   object anonObject
)

Parameters

anonObject
Remarks
The return object will be an instance of a dynamic type, and you can bind to its properties without problems in Silverlight.
Example
private void RunProjectionQuery() {
   // Run a query (asynchronously) which returns an anonymous type.
   // Assume we've already connected and logged in.
   
   DomainModelEntityManager mgr = DomainModelEntityManager.DefaultManager;

   var query = mgr.Customers
               .Select(c => new { c.CustomerID, c.CompanyName });
   mgr.ExecuteQueryAsync(query, FetchCompleted, "F1");
 }

 private void FetchCompleted(EntityFetchedEventArgs args) {
   // Special logic to handle a projection query - 
   //  you can't bind to an anonymous type in Silverlight.

   // If an anonymous type is returned from a query, convert
   // it to a DevForce dynamic type to enable binding.
   // The Convert method returns an IEnumerable, which you
   // can use to directly set a DataGrid ItemsSource property.
   if (AnonymousFns.IsAnonymousType(args.Query.ReturnType)) {
     _dataGrid.ItemsSource = DynamicTypeConverter.Convert(args.Result);
   } else {
     _dataGrid.ItemsSource = args.Result;
   }

   // Binding to anonymous types isn't supported in Silverlight because the anonymous
   // type is not a public type.  The converted 'dynamic type' is public.  We can see this
   // here:
   bool isPublic1 = args.Query.ReturnType.IsPublic;
   bool isPublic2 = DynamicTypeConverter.Convert(args.Result).AsQueryable().ElementType.IsPublic;
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DynamicTypeConverter Class
DynamicTypeConverter Members
Overload List

Send Feedback