Added IntegerDataTypeModel and HtmlStringDataTypeModel to the core and removed the internal integer upcasting code. Model will automatically apply for 'Numeric' data type. use umbraco.MacroEngines.RazorDataTypeModels.IntegerDataTypeModel to apply a staticMapping in umbracoSettings for a given datatype or alias as per previous commit

This commit is contained in:
agrath
2012-01-09 12:58:15 -13:00
parent e6f0c2a17c
commit 7b157c5083
4 changed files with 54 additions and 12 deletions

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace umbraco.MacroEngines.RazorDataTypeModels
{
public class HtmlStringDataTypeModel : IRazorDataTypeModel
{
public bool Init(int CurrentNodeId, string PropertyData, out object instance)
{
instance = new HtmlString(PropertyData);
return true;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace umbraco.MacroEngines.RazorDataTypeModels
{
[RazorDataTypeModel("1413afcb-d19a-4173-8e9a-68288d2a73b8", 90)]
public class IntegerDataTypeModel : IRazorDataTypeModel
{
public bool Init(int CurrentNodeId, string PropertyData, out object instance)
{
int integer = 0;
if (int.TryParse(PropertyData, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out integer))
{
instance = integer;
return true;
}
instance = null;
return false;
}
}
}

View File

@@ -29,7 +29,7 @@ namespace umbraco.MacroEngines
private readonly Guid DATATYPE_TINYMCE_GUID = new Guid("5e9b75ae-face-41c8-b47e-5f4b0fd82f83");
private readonly Guid DATATYPE_DATETIMEPICKER_GUID = new Guid("b6fb1622-afa5-4bbf-a3cc-d9672a442222");
private readonly Guid DATATYPE_DATEPICKER_GUID = new Guid("23e93522-3200-44e2-9f29-e61a6fcbb79a");
private readonly Guid DATATYPE_INTEGER_GUID = new Guid("1413afcb-d19a-4173-8e9a-68288d2a73b8");
//private readonly Guid DATATYPE_INTEGER_GUID = new Guid("1413afcb-d19a-4173-8e9a-68288d2a73b8");
#endregion
internal readonly DynamicBackingItem n;
@@ -660,17 +660,17 @@ namespace umbraco.MacroEngines
}
}
//integer
//this will eat csv strings, so only do it if the decimal also includes a decimal seperator (according to the current culture)
if (dataType == DATATYPE_INTEGER_GUID)
{
int iResult = 0;
if (int.TryParse(sResult, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out iResult))
{
result = iResult;
return true;
}
}
////integer
////this will eat csv strings, so only do it if the decimal also includes a decimal seperator (according to the current culture)
//if (dataType == DATATYPE_INTEGER_GUID)
//{
// int iResult = 0;
// if (int.TryParse(sResult, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out iResult))
// {
// result = iResult;
// return true;
// }
//}
//this will eat csv strings, so only do it if the decimal also includes a decimal seperator (according to the current culture)
if (sResult.Contains(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator))

View File

@@ -74,6 +74,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="RazorCore\BaseContext.cs" />
<Compile Include="RazorDataTypeModels\HtmlStringDataTypeModel.cs" />
<Compile Include="RazorDataTypeModels\IntegerDataTypeModel.cs" />
<Compile Include="RazorDynamicNode\DynamicBackingItem.cs" />
<Compile Include="RazorDynamicNode\DynamicBackingItemType.cs" />
<Compile Include="RazorDynamicNode\DynamicGrouping.cs" />