I had never seen the partial on method. This is similar to C++ where you specify the signature, and then implement it in a .cp file.
Here is the URL to the definitive 195 page (pdf) MVC tutorial for building the NerdDinner:
http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspxHere's the example of using the "partial" keyword. Note the "partial void OnValidate(ChangeAction action)"
public partial class Dinner {
public bool IsValid {
get { return (GetRuleViolations().Count() == 0); }
}
public IEnumerable<RuleViolation> GetRuleViolations() {
yield break;
}
partial void OnValidate(ChangeAction action) {
if (!IsValid) throw new ApplicationException("Rule violations prevent saving");
}
}
public class RuleViolation {
public string ErrorMessage { get; private set; }
public string PropertyName { get; private set; }
public RuleViolation(string errorMessage) {
ErrorMessage = errorMessage;
}
public RuleViolation(string errorMessage, string propertyName) {
ErrorMessage = errorMessage;
PropertyName = propertyName;
}
}
Note that in the NerdDinner.designer.cs LINQ 2 SQL databased drag-n-drop defined class:
public partial class NerdDinnerDataContext : System.Data.Linq.DataContext
the class has these "extensible" aka partial-method-signatures listed:
#region
Extensibility Method Definitions
partialvoid OnLoaded();
partialvoid OnValidate(System.Data.Linq.ChangeAction action);
partialvoid OnCreated();
partialvoid OnDinnerIDChanging(int value);
partialvoid OnDinnerIDChanged();
partialvoid OnTitleChanging(string value);
partialvoid OnTitleChanged();
partialvoid OnEventDateChanging(System.DateTime value);
partialvoid OnEventDateChanged();
partialvoid OnDescriptionChanging(string value);
partialvoid OnDescriptionChanged();
partialvoid OnHostedByChanging(string value);
partialvoid OnHostedByChanged();
partialvoid OnContactPhoneChanging(string value);
partialvoid OnContactPhoneChanged();
partialvoid OnAddressChanging(string value);
partialvoid OnAddressChanged();
partialvoid OnCountryChanging(string value);
partialvoid OnCountryChanged();
partialvoid OnLatitudeChanging(System.Nullable<double> value);
partialvoid OnLatitudeChanged();
partialvoid OnLongitudeChanging(System.Nullable<double> value);
partialvoid OnLongitudeChanged();
#endregion
I find this odd, that neither myself nor my smartest programmer friend, BJ Herrington, knew about this partial on a method trickery!
ScottGu and friends are Rock-n-Rolla's! Thanks from the community to yalls.
Thanks, LinkedIn.com/danwygant twitter.com/danwygant
Dan Wygant, Sr Software Consultant
MVP 04'-08' Windows Customer Experience
Founder HUNTUG.org VSdotNetUG.org HowToVS.NET
INETA VS.NET User Group Mentor for Al/Ms/La/Tn/Ky