Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 26th, 2012, 04:22 AM
Registered User
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default The QueryBuilder that was created with this book gives great flexibility

I tried enumerating through the QueryFields in the Builder right after calling the GetCustomAttributes method. But I failed because it's of type object[] and I tried doing something like:
IEnumerable<QueryFieldAttribute> qfa = QueryFields.OrderBy(q => q.FriendlyFieldName);

I'm completely shooting in the dark on this since I never worked with QueryFieldAttributes till now. Is there a simple way of doing this and I'm just completely looking at this wrong..?
 
Old December 31st, 2012, 10:36 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi Carterly,

Type.GetCustomAttributes will always return an object array, so in your LINQ statement, q is of type object. You will need to cast each one to QueryFieldAttribute to check it.

Luckily there is a Cast() method in LINQ to do it for you! So you can use:
Code:
IEnumerable<QueryFieldAttribute> queryFieldAttrs = QueryFields.Cast<QueryFieldAttribute>();

IEnumerable<QueryFieldAttribute> qfa = queryFieldAttrs.OrderBy(q => q.FriendlyFieldName);
Be careful tho, as this will error if the attribute isn't a QueryFieldAttribute or inherited from it. You can see in the QueryBuilder code that it checks if the attribute is a QueryFieldAttribute before using it.

You could of course get round this by extending ENTBaseQueryBO to create a second version of GetCustomAttributes() which takes an attribute type:

Code:
public object[] GetCustomAttributes(Type attributeType)
{
    return typeof(T).GetCustomAttributes(attributeType, false);
}
Hope this gives you some ideas

Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
this book is great abilify BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 1 April 19th, 2010 08:23 AM
Great Book! djaus BOOK: Professional Visual Studio 2008 ISBN: 978-0-470-22988-0 2 January 11th, 2010 10:15 PM
Great book...but rsearing BOOK: Beginning Access 2007 VBA ISBN: 978-0-470-04684-5 0 March 2nd, 2009 10:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.