Skip to content

Commit db4e3f2

Browse files
Merge branch 'release/Radical-1.4.3.0-Beta-1-Gonzales'
2 parents 1e1e4ea + 9d623ca commit db4e3f2

File tree

25 files changed

+990
-244
lines changed

25 files changed

+990
-244
lines changed

Radical.sln

Lines changed: 13 additions & 208 deletions
Large diffs are not rendered by default.

src/net35/Radical/Model/Entity/Entity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected PropertyMetadata<T> SetInitialPropertyValue<T>( String property, T val
233233
/// </returns>
234234
protected PropertyMetadata<T> GetPropertyMetadata<T>( Expression<Func<T>> property )
235235
{
236-
Ensure.That( property ).Named( () => property ).IsNotNull();
236+
Ensure.That( property ).Named( "property" ).IsNotNull();
237237

238238
return ( PropertyMetadata<T> )this.GetPropertyMetadata<T>( property.GetMemberName() );
239239
}
@@ -246,7 +246,7 @@ protected PropertyMetadata<T> GetPropertyMetadata<T>( Expression<Func<T>> proper
246246
/// <returns>An instance of the requested property metadata.</returns>
247247
protected PropertyMetadata<T> GetPropertyMetadata<T>( String propertyName )
248248
{
249-
Ensure.That( propertyName ).Named( () => propertyName ).IsNotNullNorEmpty();
249+
Ensure.That( propertyName ).Named( "propertyName" ).IsNotNullNorEmpty();
250250

251251
//return ( PropertyMetadata<T> )this.GetPropertyMetadata( propertyName, typeof( T ) );
252252

src/net35/Radical/Model/Entity/PropertyMetadata.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,23 @@ public static PropertyMetadata<T> Create<T>( Object propertyOwner, String proper
6262
readonly HashSet<String> cascadeChangeNotifications = new HashSet<String>();
6363
#endif
6464

65-
protected PropertyInfo Property { get; private set; }
65+
readonly Object propertyOwner;
66+
PropertyInfo _property;
67+
68+
protected PropertyInfo Property
69+
{
70+
get
71+
{
72+
if ( this._property == null )
73+
{
74+
this._property = this.propertyOwner
75+
.GetType()
76+
.GetProperty( this.PropertyName );
77+
}
78+
79+
return this._property;
80+
}
81+
}
6682

6783
/// <summary>
6884
/// Initializes a new instance of the <see cref="PropertyMetadata" /> class.
@@ -71,10 +87,10 @@ public static PropertyMetadata<T> Create<T>( Object propertyOwner, String proper
7187
/// <param name="propertyName">Name of the property.</param>
7288
protected PropertyMetadata( Object propertyOwner, String propertyName )
7389
{
74-
Ensure.That( propertyOwner ).Named( () => propertyOwner ).IsNotNull();
90+
Ensure.That( propertyOwner ).Named( "propertyOwner" ).IsNotNull();
7591
Ensure.That( propertyName ).Named( "propertyName" ).IsNotNullNorEmpty();
7692

77-
this.Property = propertyOwner.GetType().GetProperty( propertyName );
93+
this.propertyOwner = propertyOwner;
7894
this.PropertyName = propertyName;
7995
this.NotifyChanges = true;
8096
}

src/net35/Radical/Model/EntityView/EntityView.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ String IBindingListView.Filter
693693
get { return this.Filter.ToString(); }
694694
set
695695
{
696-
throw new NotSupportedException( "Setting a Instance as String is currently not supported" );
696+
var msg = String.Format( "Setting '{0}' directly as Filter is not supported.", value ?? "<null>");
697+
throw new NotSupportedException( msg );
697698
//TODO: IBindingListView.Instance
698699
/* Bisogna capire se siamo in grado data
699700
* una stringa di convertirla in un filtro

src/net35/Radical/Properties/NugetInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
#pragma warning disable 1607
55
//This is the build number userd to publish the NuGet package.
6-
[assembly: AssemblyInformationalVersion( "1.4.3.0-Alfa" )]
6+
[assembly: AssemblyInformationalVersion( "1.4.3.0-Beta-1" )]
77
#pragma warning restore 1607

src/net35/Radical/Radical.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@
543543
del "$(SolutionDir)build\$(ConfigurationName)\$(ProjectName)\lib\net35\it-it\*.*" /Q
544544
)
545545

546-
del "$(SolutionDir)build\$(ConfigurationName)\$(ProjectName)\lib\net35\*.*" /Q
546+
del "$(SolutionDir)build\$(ConfigurationName)\$(ProjectName)\lib\net35\*.*" /Q
547547
echo "Build/NuGet folder purged".
548548
) else (
549549
echo "no Build/NuGet folder to purge.".

src/net35/Radical/Validation/Ensure/Ensure.cs

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,127 @@ namespace Topics.Radical.Validation
1010
/// </summary>
1111
public static class Ensure
1212
{
13+
#if DEBUG
14+
static SourceInfoLoadStrategy _sourceInfoLoadStrategy = SourceInfoLoadStrategy.Load;
15+
#else
16+
static SourceInfoLoadStrategy _sourceInfoLoadStrategy = SourceInfoLoadStrategy.Skip;
17+
#endif
18+
19+
/// <summary>
20+
/// Determines if the Ensure class tries to load the Stack before moving on.
21+
/// </summary>
22+
public static SourceInfoLoadStrategy SourceInfoLoadStrategy
23+
{
24+
get { return _sourceInfoLoadStrategy; }
25+
set { _sourceInfoLoadStrategy = value; }
26+
}
27+
1328
internal class SourceInfo
1429
{
1530
public readonly static SourceInfo Empty = new SourceInfo( "", "", MemberTypes.Custom );
1631

32+
private StackFrame frame;
33+
private bool lazy;
34+
private bool loaded;
35+
36+
private MemberTypes _sourceType;
37+
private string _className;
38+
private string _methodName;
39+
40+
public static SourceInfo FromStack( StackTrace st, bool lazy )
41+
{
42+
SourceInfo si = SourceInfo.Empty;
43+
if ( st.FrameCount > 0 )
44+
{
45+
var frame = st.GetFrame( 0 );
46+
si = new SourceInfo( frame, lazy );
47+
}
48+
49+
return si;
50+
}
51+
1752
/// <summary>
1853
/// Initializes a new instance of the <see cref="SourceInfo"/> class.
1954
/// </summary>
2055
/// <param name="methodName">Name of the method.</param>
2156
/// <param name="className">Name of the class.</param>
2257
/// <param name="sourceType">Type of the source.</param>
23-
public SourceInfo( String methodName, String className, MemberTypes sourceType )
58+
private SourceInfo( String methodName, String className, MemberTypes sourceType )
2459
{
25-
this.MethodName = methodName;
26-
this.ClassName = className;
27-
this.SourceType = sourceType;
60+
this._methodName = methodName;
61+
this._className = className;
62+
this._sourceType = sourceType;
63+
}
64+
65+
private SourceInfo( StackFrame frame, bool lazy )
66+
{
67+
this.frame = frame;
68+
this.lazy = lazy;
69+
if ( !this.lazy )
70+
{
71+
this.EnsureDataAreLoaded();
72+
}
73+
}
74+
75+
void EnsureDataAreLoaded()
76+
{
77+
if ( !this.loaded )
78+
{
79+
var mi = this.frame.GetMethod();
80+
if ( mi != null )
81+
{
82+
this._methodName = mi.Name;
83+
this._className = mi.DeclaringType.Name;
84+
this._sourceType = mi.MemberType;
85+
}
86+
else
87+
{
88+
this._methodName = SourceInfo.Empty.MethodName;
89+
this._className = SourceInfo.Empty.ClassName;
90+
this._sourceType = SourceInfo.Empty.SourceType;
91+
}
92+
93+
this.loaded = true;
94+
}
2895
}
2996

3097
/// <summary>
3198
/// Gets the name of the method.
3299
/// </summary>
33100
/// <value>The name of the method.</value>
34-
public String MethodName { get; private set; }
101+
public String MethodName
102+
{
103+
get
104+
{
105+
this.EnsureDataAreLoaded();
106+
return this._methodName;
107+
} }
35108

36109
/// <summary>
37110
/// Gets the name of the class.
38111
/// </summary>
39112
/// <value>The name of the class.</value>
40-
public String ClassName { get; private set; }
113+
public String ClassName
114+
{
115+
get
116+
{
117+
this.EnsureDataAreLoaded();
118+
return this._className;
119+
}
120+
}
41121

42122
/// <summary>
43123
/// Gets the type of the source.
44124
/// </summary>
45125
/// <value>The type of the source.</value>
46-
public MemberTypes SourceType { get; private set; }
126+
public MemberTypes SourceType
127+
{
128+
get
129+
{
130+
this.EnsureDataAreLoaded();
131+
return this._sourceType;
132+
}
133+
}
47134
}
48135

49136
/// <summary>
@@ -54,25 +141,40 @@ public SourceInfo( String methodName, String className, MemberTypes sourceType )
54141
/// <param name="obj">The object value to inspect.</param>
55142
/// <returns>The Ensure instance for fluent interface usage.</returns>
56143
public static IConfigurableEnsure<T> That<T>( T obj )
144+
{
145+
return That<T>( obj, Ensure.SourceInfoLoadStrategy );
146+
}
147+
148+
/// <summary>
149+
/// Initialize a new instance of the generic Ensure class using the supplied
150+
/// value as the value to insepct.
151+
/// </summary>
152+
/// <typeparam name="T">The type of the inepcted object value.</typeparam>
153+
/// <param name="obj">The object value to inspect.</param>
154+
/// <param name="strategy">Determines if the Ensure instance should load the current Stack.</param>
155+
/// <returns>The Ensure instance for fluent interface usage.</returns>
156+
public static IConfigurableEnsure<T> That<T>( T obj, SourceInfoLoadStrategy strategy )
57157
{
58158
var si = SourceInfo.Empty;
59159

60160
#if !SILVERLIGHT
61161

62-
var st = new StackTrace( 1 );
63-
if( st.FrameCount > 0 )
162+
if ( strategy != Validation.SourceInfoLoadStrategy.Skip )
64163
{
65-
var f = st.GetFrame( 0 );
66-
var mi = f.GetMethod();
67-
if( mi != null )
68-
{
69-
si = new SourceInfo( mi.Name, mi.DeclaringType.Name, mi.MemberType );
70-
}
164+
var lazy = strategy == Validation.SourceInfoLoadStrategy.LazyLoad;
165+
si = SourceInfo.FromStack( new StackTrace( 1 ), lazy: lazy );
71166
}
72167

73168
#endif
74169

75170
return new Ensure<T>( obj, si );
76171
}
77172
}
173+
174+
public enum SourceInfoLoadStrategy
175+
{
176+
Load=0,
177+
Skip,
178+
LazyLoad
179+
}
78180
}

src/net35/Radical/Validation/Ensure/EnsureExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ public static class EnsureExtensions
1717
public static IEnsure<T> IsNotNull<T>( this IEnsure<T> validator )
1818
where T : class
1919
{
20-
return validator.If( s => s == null )
21-
.ThenThrow( v =>
22-
{
23-
return new ArgumentNullException( v.Name, v.GetFullErrorMessage( "The inspected value should be non null." ) );
24-
} );
20+
var value = validator.GetValue<T>();
21+
if ( value == null )
22+
{
23+
throw new ArgumentNullException( validator.Name, validator.GetFullErrorMessage( "The inspected value should be non null." ) );
24+
}
25+
26+
return validator;
2527
}
2628
}
2729
}

src/net35/Radical/Validation/Ensure/StringEnsureExtension.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public static class StringEnsureExtension
2121
/// is raised if the current inspected object is an empty string.</exception>
2222
public static IEnsure<String> IsNotEmpty( this IEnsure<String> validator )
2323
{
24-
validator.If( s => s.Length == 0 )
25-
.ThenThrow( v =>
26-
{
27-
return new ArgumentOutOfRangeException( v.Name, v.GetFullErrorMessage( "The inspected string value should be not empty." ) );
28-
} );
24+
var value = validator.GetValue<String>();
25+
26+
if ( value != null && value.Length == 0 )
27+
{
28+
throw new ArgumentOutOfRangeException( validator.Name, validator.GetFullErrorMessage( "The inspected string value should be not empty." ) );
29+
}
2930

3031
return validator;
3132
}

src/net40/Radical.Windows.Presentation/AbstractViewModel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected virtual IValidationService GetValidationService()
8181
/// </summary>
8282
protected AbstractViewModel()
8383
{
84-
this.ValidationErrors = new ObservableCollection<ValidationError>();
84+
8585
}
8686

8787
//protected virtual void OnLoading()
@@ -163,14 +163,23 @@ public virtual Boolean IsValid
163163
get { return this.ValidationService.IsValid; }
164164
}
165165

166+
ObservableCollection<ValidationError> _validationErrors;
167+
166168
/// <summary>
167169
/// Gets the validation errors if any.
168170
/// </summary>
169171
/// <value>The validation errors.</value>
170172
public virtual ObservableCollection<ValidationError> ValidationErrors
171173
{
172-
get;
173-
private set;
174+
get
175+
{
176+
if ( this._validationErrors == null )
177+
{
178+
this._validationErrors = new ObservableCollection<ValidationError>();
179+
}
180+
181+
return this._validationErrors;
182+
}
174183
}
175184

176185
/// <summary>

0 commit comments

Comments
 (0)