IdeaBlade DevForce 2010 Help Reference
Convert(IEnumerable) Method
See Also  Example Send Feedback
IdeaBlade.Core Assembly > IdeaBlade.Core Namespace > DynamicTypeConverter Class > Convert Method : Convert(IEnumerable) Method



anonObjects
Convert a collection of anonymously-typed objects into dynamicly-typed objects.

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function Convert( _
   ByVal anonObjects As IEnumerable _
) As IEnumerable
Visual Basic (Usage)Copy Code
Dim anonObjects As IEnumerable
Dim value As IEnumerable
 
value = DynamicTypeConverter.Convert(anonObjects)
C# 
public static IEnumerable Convert( 
   IEnumerable anonObjects
)
C++/CLI 
public:
static IEnumerable^ Convert( 
   IEnumerable^ anonObjects
) 

Parameters

anonObjects

Example

C#Copy Code
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;
}

Remarks

The return object will be a collection of dynamic type instances, which can be bound to without problems in Silverlight.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.