CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

silverlight criteria question

rated by 0 users
Answered (Not Verified) This post has 0 verified answers | 3 Replies | 2 Followers

Top 75 Contributor
106 Posts
griff posted on Thu, Jul 19 2012 6:44 AM

When I do this

 /// <summary>
            /// Maintains metadata about <see cref="ClientID"/> property.
            /// </summary>
#if SILVERLIGHT
 
            [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
            public static readonly PropertyInfo<Int32> ClientIDProperty = RegisterProperty<Int32>(p => p.ClientID);
 
#else
            protected static readonly PropertyInfo<Int32> ClientIDProperty = RegisterProperty<Int32>(p => p.ClientID);
#endif
 
            /// <summary>
            /// Gets the Client ID.
            /// </summary>
            /// <value>The Client ID.</value>
            public Int32 ClientID
            {
                get { return ReadProperty(ClientIDProperty); }
              set { LoadProperty(ClientIDProperty, value); }
            }

However when I miss off the
#if SILVERLIGHT
 
            [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
            public static readonly PropertyInfo<Int32> ClientIDProperty = RegisterProperty<Int32>(p => p.ClientID);
 
#else

I get errors - is this correct and can someone explain - thanks

All Replies

Top 10 Contributor
9,270 Posts

I recommend declaring the PropertyInfo fields as public in scope. It is just too messy and hard to maintain the #if statements and duplicate code necessary to have two scopes. Besides, having those values as public is valuable in many UI and DAL scenarios, because that other code can also use the metadata if necessary.

Rocky

Top 10 Contributor
628 Posts

With respect to the UI scenarios (like binding) it might not seem immediately useful as they are static, so just wanted to raise what we do to get around it.

We expose a public collection of PropertyInfos in our base class for businessbase (instance property) that is calculated and then cached, and provides an "indexable" propertyinfo list we use for databinding to labels.

(i.e. Model.PropertyInfos["PropertyName"].FriendlyName

It's a really useful construct we've built into our base classes.  Just wanted to mention it as it seemed on-topic and we use it quite heavily.

Slightly more on-topic, we declare our property infos to be public, but we tag them as readonly.

Top 10 Contributor
9,270 Posts

Ahh, you should like the 4.3 enhancement that now includes a public method to get all the registered PropertyInfo elements for a type. That allows you to use the list already maintained by CSLA.

Rocky

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems