Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 26th, 2012, 04:22 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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..?
  #2 (permalink)  
Old December 31st, 2012, 10:36 AM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
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
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09: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



All times are GMT -4. The time now is 03:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.