silverlight criteria question

silverlight criteria question

Old forum URL: forums.lhotka.net/forums/t/11485.aspx


griff posted on Thursday, July 19, 2012

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

RockfordLhotka replied on Thursday, July 19, 2012

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.

skagen00 replied on Thursday, July 19, 2012

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.

RockfordLhotka replied on Thursday, July 19, 2012

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.

Copyright (c) Marimer LLC