Skip to content

Commit

Permalink
MarimerLLC#1101 Add overloads for RegisterMethod and nameof()
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Jun 3, 2019
1 parent 266b3ad commit 1a70708
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
36 changes: 13 additions & 23 deletions Source/Csla.Shared/BusinessBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void BeginSave(EventHandler<SavedEventArgs> handler)
[Obsolete]
public async void BeginSave(bool forceUpdate, EventHandler<SavedEventArgs> handler, object userState)
{
T result = default(T);
T result = default;
Exception error = null;
try
{
Expand All @@ -324,8 +324,7 @@ public async void BeginSave(bool forceUpdate, EventHandler<SavedEventArgs> handl

if (error != null)
OnSaved(null, error, userState);
if (handler != null)
handler(this, new SavedEventArgs(result, error, userState));
handler?.Invoke(this, new SavedEventArgs(result, error, userState));
}

/// <summary>
Expand Down Expand Up @@ -388,7 +387,6 @@ public void BeginSave(EventHandler<SavedEventArgs> handler, object userState)
this.BeginSave(false, handler, userState);
}


#endregion

#region ISavable Members
Expand All @@ -403,8 +401,6 @@ void Csla.Core.ISavable<T>.SaveComplete(T newObject)
OnSaved(newObject, null, null);
}

#if !(ANDROID || IOS) && !NETFX_CORE

object Csla.Core.ISavable.Save()
{
return Save();
Expand Down Expand Up @@ -451,12 +447,6 @@ public event EventHandler<Csla.Core.SavedEventArgs> Saved
System.Delegate.Remove(_nonSerializableSavedHandlers, value);
}
}
#else
/// <summary>
/// Event raised when an object has been saved.
/// </summary>
public event EventHandler<Csla.Core.SavedEventArgs> Saved;
#endif

async Task<object> ISavable.SaveAsync()
{
Expand All @@ -480,20 +470,15 @@ async Task<object> ISavable.SaveAsync(bool forceUpdate)
protected virtual void OnSaved(T newObject, Exception e, object userState)
{
Csla.Core.SavedEventArgs args = new Csla.Core.SavedEventArgs(newObject, e, userState);
#if !(ANDROID || IOS) && !NETFX_CORE
if (_nonSerializableSavedHandlers != null)
_nonSerializableSavedHandlers.Invoke(this, args);
if (_serializableSavedHandlers != null)
_serializableSavedHandlers.Invoke(this, args);
#else
if (Saved != null)
Saved(this, args);
#endif
}

#endregion

#region Register Properties
#region Register Properties/Methods

/// <summary>
/// Indicates that the specified property belongs
Expand Down Expand Up @@ -685,9 +670,15 @@ protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>>
return RegisterProperty(reflectedPropertyInfo.Name, friendlyName, defaultValue, relationship);
}

#endregion

#region Register Methods
/// <summary>
/// Registers a method for use in Authorization.
/// </summary>
/// <param name="methodName">Method name from nameof()</param>
/// <returns></returns>
protected static MethodInfo RegisterMethod(string methodName)
{
return RegisterMethod(typeof(T), methodName);
}

/// <summary>
/// Registers a method for use in Authorization.
Expand All @@ -697,8 +688,7 @@ protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>>
protected static MethodInfo RegisterMethod(Expression<Action<T>> methodLambdaExpression)
{
System.Reflection.MethodInfo reflectedMethodInfo = Reflect<T>.GetMethod(methodLambdaExpression);

return RegisterMethod(typeof(T), reflectedMethodInfo.Name);
return RegisterMethod(reflectedMethodInfo.Name);
}

#endregion
Expand Down
13 changes: 11 additions & 2 deletions Source/Csla.Shared/ReadOnlyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,16 @@ protected static MethodInfo RegisterMethod(Type objectType, string methodName)
return info;
}

/// <summary>
/// Registers a method for use in Authorization.
/// </summary>
/// <param name="methodName">Method name from nameof()</param>
/// <returns></returns>
protected static MethodInfo RegisterMethod(string methodName)
{
return RegisterMethod(typeof(T), methodName);
}

/// <summary>
/// Registers the method.
/// </summary>
Expand All @@ -796,8 +806,7 @@ protected static MethodInfo RegisterMethod(Type objectType, string methodName)
protected static MethodInfo RegisterMethod(Expression<Action<T>> methodLambdaExpression)
{
System.Reflection.MethodInfo reflectedMethodInfo = Reflect<T>.GetMethod(methodLambdaExpression);

return RegisterMethod(typeof(T), reflectedMethodInfo.Name);
return RegisterMethod(reflectedMethodInfo.Name);
}

#endregion
Expand Down

0 comments on commit 1a70708

Please sign in to comment.