Some refactoring of LINQ to Umbraco to make writing custom UmbracoDataProviders

Fixing the code gen for LINQ to Umbraco to properly do the IsDirty stuff

[TFS Changeset #76215]
This commit is contained in:
slace
2010-08-23 08:57:36 +00:00
parent 2e8dbeebdc
commit 662f8f381b
3 changed files with 28 additions and 20 deletions

View File

@@ -100,28 +100,18 @@ namespace umbraco.Linq.Core.Node
#region IDisposable Members
private bool _disposed;
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected internal override void Dispose(bool disposing)
{
if (!this._disposed && disposing)
if (disposing)
{
this._xmlPath = null;
this._disposed = true;
}
}
internal void CheckDisposed()
{
if (this._disposed)
{
throw new ObjectDisposedException(null);
}
base.Dispose(disposing);
}
#endregion
@@ -344,7 +334,7 @@ namespace umbraco.Linq.Core.Node
if (propertyXml != null)
data = propertyXml.Value;
if (p.PropertyType.IsValueType && typeof(Nullable<>).IsAssignableFrom(p.PropertyType.GetGenericTypeDefinition()))
if (p.PropertyType.IsValueType && p.PropertyType.GetGenericArguments().Length > 0 && typeof(Nullable<>).IsAssignableFrom(p.PropertyType.GetGenericTypeDefinition()))
{
if (string.IsNullOrEmpty(data))
{

View File

@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace umbraco.Linq.Core
{
/// <summary>
/// Provides the methods required for a data access model within the LINQ to umbraco project
/// Provides the methods required for a data access model within the LINQ to Umbraco project
/// </summary>
/// <remarks>
/// This base class is used when defining how a DataProvider operates against a data source (such as the umbraco.config).
@@ -16,6 +13,11 @@ namespace umbraco.Linq.Core
/// </remarks>
public abstract class UmbracoDataProvider : IDisposable
{
/// <summary>
/// Indicates the disposal status of the current provider
/// </summary>
protected bool _disposed;
/// <summary>
/// Gets the name of the provider
/// </summary>
@@ -23,21 +25,21 @@ namespace umbraco.Linq.Core
public abstract string Name { get; }
/// <summary>
/// Loads the tree with the relivent DocTypes
/// Loads the tree with the relevant DocTypes
/// </summary>
/// <typeparam name="TDocType">The type of the DocType to load.</typeparam>
/// <returns></returns>
public abstract Tree<TDocType> LoadTree<TDocType>() where TDocType : DocTypeBase, new();
/// <summary>
/// Loads the associated nodes with the relivent DocTypes
/// Loads the associated nodes with the relevant DocTypes
/// </summary>
/// <param name="parentNodeId">The parent node id.</param>
/// <returns></returns>
public abstract AssociationTree<DocTypeBase> LoadAssociation(int parentNodeId);
/// <summary>
/// Loads the associated nodes with the relivent DocTypes
/// Loads the associated nodes with the relevant DocTypes
/// </summary>
/// <typeparam name="TDocType">The type of the DocType to load.</typeparam>
/// <param name="nodes">The nodes.</param>
@@ -61,6 +63,15 @@ namespace umbraco.Linq.Core
#region IDisposable Members
/// <summary>
/// Checks if the provider has been disposed
/// </summary>
protected internal void CheckDisposed()
{
if (this._disposed)
throw new ObjectDisposedException(null);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
@@ -77,10 +88,16 @@ namespace umbraco.Linq.Core
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
protected internal virtual void Dispose(bool disposing)
{
this._disposed = true;
}
#endregion
/// <summary>
/// Submits the changes tracked by the UmbracoDataProvider
/// </summary>
/// <remarks>It is up to the implementor of the UmbracoDataProvider to decide whether or not they are supporting change submission in their provider. This will thrown an exception unless it is explicitly implemented.</remarks>
/// <exception cref="System.NotImplementedException">Thrown unless the method is implemented in a custom UmbracoDataProvider.</exception>
protected internal virtual void SubmitChanges()
{
throw new NotImplementedException("Provider \"" + this.Name + "\" does not implement a submittable pattern");

View File

@@ -151,6 +151,7 @@ namespace {0} {{
{{
this.RaisePropertyChanging();
this._{1} = value;
this.IsDirty = true;
this.RaisePropertyChanged(""{1}"");
}}
}}