Fixing some problems with LINQ to Umbraco:

- inherited properties not properly managed
- non-mandatory structs are handled
- adding NodeName and Path to the BaseDocType class (obsoleted Name property, but not removed)

[TFS Changeset #76091]
This commit is contained in:
slace
2010-08-22 05:16:12 +00:00
parent 1d45486465
commit b68bf3f627
8 changed files with 516 additions and 426 deletions

View File

@@ -16,7 +16,7 @@ namespace umbraco.Linq.Core
{
#region Internal Storage
private int _Id;
private string _name;
private string _nodeName;
private string _versionId;
private int _templateId;
private int _parentId;
@@ -24,6 +24,7 @@ namespace umbraco.Linq.Core
private User _writer;
private int creatorID;
private User _creator;
private string _path;
private IEnumerable<DocTypeBase> _ancestors;
private AssociationTree<DocTypeBase> _children;
#endregion
@@ -77,22 +78,36 @@ namespace umbraco.Linq.Core
/// </summary>
/// <value>The name.</value>
[Field]
[UmbracoInfo("nodeName", DisplayName = "Name", Mandatory = true), DataMember(Name = "Name")]
[UmbracoInfo("nodeName", DisplayName = "NodeName", Mandatory = true), DataMember(Name = "NodeName")]
public virtual string NodeName
{
get
{
return this._nodeName;
}
set
{
if (this._nodeName != value)
{
this.RaisePropertyChanging();
this._nodeName = value;
this.IsDirty = true;
this.RaisePropertyChanged("NodeName");
}
}
}
[Field]
[Obsolete("Name property is obsolete, use NodeName instead")] //this is because most people expect NodeName not Name as the property
public virtual string Name
{
get
{
return this._name;
return this.NodeName;
}
set
{
if (this._name != value)
{
this.RaisePropertyChanging();
this._name = value;
this.IsDirty = true;
this.RaisePropertyChanged("Name");
}
this.NodeName = value;
}
}
@@ -115,7 +130,7 @@ namespace umbraco.Linq.Core
this.RaisePropertyChanging();
this._templateId = value;
this.IsDirty = true;
this.RaisePropertyChanged("Name");
this.RaisePropertyChanged("Template");
}
}
}
@@ -161,7 +176,7 @@ namespace umbraco.Linq.Core
{
this.RaisePropertyChanging();
this._parentId = value;
this.RaisePropertyChanged("Version");
this.RaisePropertyChanged("ParentId");
}
}
}
@@ -197,6 +212,30 @@ namespace umbraco.Linq.Core
[Field]
[UmbracoInfo("level", DisplayName = "Level"), DataMember(Name = "Level")]
public virtual int Level { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
[Field]
[UmbracoInfo("path", DisplayName = "Path")]
[DataMember(Name = "Path")]
public virtual string Path
{
get
{
return this._path;
}
set
{
if (this._path != value)
{
this.RaisePropertyChanging();
this._path = value;
this.RaisePropertyChanged("Path");
}
}
}
#endregion
#region Parents and Children

View File

@@ -59,6 +59,12 @@ namespace umbraco.Linq.Core
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
string NodeName { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[Obsolete("Name property is obsolete, use NodeName instead")] //this is because most people expect NodeName not Name as the property
string Name { get; set; }
/// <summary>
/// Parent if current instance
@@ -101,5 +107,10 @@ namespace umbraco.Linq.Core
/// </summary>
/// <value>The name of the writer.</value>
string WriterName { get; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
string Path { get; set; }
}
}

View File

@@ -320,7 +320,7 @@ namespace umbraco.Linq.Core.Node
node.Id = (int)xml.Attribute("id");
node.ParentNodeId = (int)xml.Attribute("parentID");
node.Name = (string)xml.Attribute("nodeName");
node.NodeName = (string)xml.Attribute("nodeName");
node.Version = (string)xml.Attribute("version");
node.CreateDate = (DateTime)xml.Attribute("createDate");
node.SortOrder = (int)xml.Attribute("sortOrder");
@@ -337,12 +337,29 @@ namespace umbraco.Linq.Core.Node
{
var attr = ReflectionAssistance.GetUmbracoInfoAttribute(p);
var data = xml.Element(Casing.SafeAliasWithForcingCheck(attr.Alias)).Value;
if (p.PropertyType == typeof(int) && string.IsNullOrEmpty(data))
data = "-1";
//here is where you would put a check if the property exists in the XML
//I'm NOT putting the check in here, as there will be unusual results if the XML doesn't
//contain the property, you'd get nulls when something shouldn't really be null
string data = xml.Element(Casing.SafeAliasWithForcingCheck(attr.Alias)).Value;
// TODO: Address how Convert.ChangeType works in globalisation
p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null);
if (p.PropertyType.IsValueType && typeof(Nullable<>).IsAssignableFrom(p.PropertyType.GetGenericTypeDefinition()))
{
if (string.IsNullOrEmpty(data))
{
//non-mandatory structs which have no value will be null
p.SetValue(node, null, null);
}
else
{
//non-mandatory structs which do have a value have to be cast based on the type of their Nullable<T>, found from the first (well, only) GenericArgument
p.SetValue(node, Convert.ChangeType(data, p.PropertyType.GetGenericArguments()[0]), null);
}
}
else
{
// TODO: Address how Convert.ChangeType works in globalisation
p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null);
}
}
}
}

View File

@@ -146,4 +146,4 @@
<PropertyGroup>
<PostBuildEvent>XCOPY "$(TargetPath)" "$(SolutionDir)\umbraco\presentation\bin" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>