Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Renamed DittoTypeConfig to DittoTypeInfo
Browse files Browse the repository at this point in the history
As it contains information about the Type, it's not a "configuration".
  • Loading branch information
leekelleher committed Aug 3, 2018
1 parent 3a29898 commit 26b4b03
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace Our.Umbraco.Ditto
{
internal sealed class DittoTypeConfig
internal sealed class DittoTypeInfo
{
public static DittoTypeConfig Create<T>()
public static DittoTypeInfo Create<T>()
{
return Create(typeof(T));
}

public static DittoTypeConfig Create(Type type)
public static DittoTypeInfo Create(Type type)
{
var config = new DittoTypeConfig
var config = new DittoTypeInfo
{
TargetType = type
};
Expand Down Expand Up @@ -70,9 +70,9 @@ public static DittoTypeConfig Create(Type type)

// properties (lazy & eager)
//
var lazyProperties = new List<DittoTypePropertyConfig>();
var lazyProperties = new List<DittoTypePropertyInfo>();
var lazyPropertyNames = new List<string>();
var eagerProperties = new List<DittoTypePropertyConfig>();
var eagerProperties = new List<DittoTypePropertyInfo>();

// Collect all the properties of the given type and loop through writable ones.
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
Expand All @@ -90,7 +90,7 @@ public static DittoTypeConfig Create(Type type)

var propertyType = property.PropertyType;

var propertyConfig = new DittoTypePropertyConfig
var propertyConfig = new DittoTypePropertyInfo
{
CustomAttributes = attributes,
PropertyInfo = property,
Expand Down Expand Up @@ -223,17 +223,17 @@ public static DittoTypeConfig Create(Type type)
public IEnumerable<Attribute> CustomAttributes { get; set; }

public bool HasLazyProperties { get; set; }
public IEnumerable<DittoTypePropertyConfig> LazyProperties { get; set; }
public IEnumerable<DittoTypePropertyInfo> LazyProperties { get; set; }
public IEnumerable<string> LazyPropertyNames { get; set; }

public bool HasEagerProperties { get; set; }
public IEnumerable<DittoTypePropertyConfig> EagerProperties { get; set; }
public IEnumerable<DittoTypePropertyInfo> EagerProperties { get; set; }

public IEnumerable<DittoConversionHandler> ConversionHandlers { get; set; }
public IEnumerable<MethodInfo> ConvertingMethods { get; set; }
public IEnumerable<MethodInfo> ConvertedMethods { get; set; }

internal sealed class DittoTypePropertyConfig
internal sealed class DittoTypePropertyInfo
{
public bool IsCacheable { get; set; }
public DittoCacheAttribute CacheInfo { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Our.Umbraco.Ditto
{
internal static class DittoTypeConfigCache
internal static class DittoTypeInfoCache
{
private static readonly ConcurrentDictionary<Type, DittoTypeConfig> _cache = new ConcurrentDictionary<Type, DittoTypeConfig>();
private static readonly ConcurrentDictionary<Type, DittoTypeInfo> _cache = new ConcurrentDictionary<Type, DittoTypeInfo>();

public static void Add<T>()
{
Expand All @@ -14,7 +14,7 @@ public static void Add<T>()

public static void Add(Type type)
{
_cache.TryAdd(type, DittoTypeConfig.Create(type));
_cache.TryAdd(type, DittoTypeInfo.Create(type));
}

public static void Clear<T>()
Expand All @@ -24,19 +24,19 @@ public static void Clear<T>()

public static void Clear(Type type)
{
_cache.TryRemove(type, out DittoTypeConfig config);
_cache.TryRemove(type, out DittoTypeInfo config);
}

public static DittoTypeConfig GetOrAdd<T>()
public static DittoTypeInfo GetOrAdd<T>()
{
return GetOrAdd(typeof(T));
}

public static DittoTypeConfig GetOrAdd(Type type)
public static DittoTypeInfo GetOrAdd(Type type)
{
if (_cache.TryGetValue(type, out DittoTypeConfig config) == false)
if (_cache.TryGetValue(type, out DittoTypeInfo config) == false)
{
config = DittoTypeConfig.Create(type);
config = DittoTypeInfo.Create(type);
_cache.TryAdd(type, config);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Our.Umbraco.Ditto/Extensions/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static object As(
// Convert
using (DittoDisposableTimer.DebugDuration(typeof(Ditto), $"As<{type.Name}>({content.DocumentTypeAlias} {content.Id})"))
{
var config = DittoTypeConfigCache.GetOrAdd(type);
var config = DittoTypeInfoCache.GetOrAdd(type);

if (config.IsCacheable)
{
Expand All @@ -164,7 +164,7 @@ public static object As(
/// <exception cref="InvalidOperationException">Thrown if the given type has invalid constructors.</exception>
private static object ConvertContent(
IPublishedContent content,
DittoTypeConfig config,
DittoTypeInfo config,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> onConverting,
Expand Down Expand Up @@ -254,8 +254,8 @@ private static object ConvertContent(
private static object GetProcessedValue(
IPublishedContent content,
CultureInfo culture,
DittoTypeConfig config,
DittoTypeConfig.DittoTypePropertyConfig mappableProperty,
DittoTypeInfo config,
DittoTypeInfo.DittoTypePropertyInfo mappableProperty,
object instance,
DittoChainContext chainContext)
{
Expand Down Expand Up @@ -291,7 +291,7 @@ private static object GetProcessedValue(
/// <returns>Returns the processed value.</returns>
private static object DoGetProcessedValue(
IPublishedContent content,
DittoTypeConfig.DittoTypePropertyConfig mappableProperty,
DittoTypeInfo.DittoTypePropertyInfo mappableProperty,
DittoProcessorContext baseProcessorContext,
DittoChainContext chainContext)
{
Expand Down Expand Up @@ -344,7 +344,7 @@ private static object DoGetProcessedValue(
/// <param name="callback">The <see cref="Action{ConversionHandlerContext}"/> to fire when converting.</param>
private static void OnConverting(
IPublishedContent content,
DittoTypeConfig config,
DittoTypeInfo config,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
Expand All @@ -366,7 +366,7 @@ private static void OnConverting(
/// <param name="callback">The <see cref="Action{ConversionHandlerContext}"/> to fire when converted.</param>
private static void OnConverted(
IPublishedContent content,
DittoTypeConfig config,
DittoTypeInfo config,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
Expand All @@ -391,7 +391,7 @@ private static void OnConverted(
private static void OnConvert<TAttributeType>(
DittoConversionHandlerType conversionType,
IPublishedContent content,
DittoTypeConfig config,
DittoTypeInfo config,
CultureInfo culture,
object instance,
Action<DittoConversionHandlerContext> callback)
Expand Down
4 changes: 2 additions & 2 deletions src/Our.Umbraco.Ditto/Our.Umbraco.Ditto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Common\CachedInvocations.cs" />
<Compile Include="Common\DittoTypeConfigCache.cs" />
<Compile Include="Common\DittoTypeConfig.cs" />
<Compile Include="Common\DittoTypeInfoCache.cs" />
<Compile Include="Common\DittoTypeInfo.cs" />
<Compile Include="Common\FastPropertyAccessor.cs" />
<Compile Include="Common\DittoContextAccessor.cs" />
<Compile Include="ComponentModel\Attributes\DittoDefaultProcessorAttribute.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Setup()
Ditto.DeregisterPostProcessorType<TryConvertToAttribute>();

// pre-load the type config
DittoTypeConfigCache.Add<BasicModel>();
DittoTypeInfoCache.Add<BasicModel>();
}

[Benchmark(Baseline = true)]
Expand Down
2 changes: 1 addition & 1 deletion tests/Our.Umbraco.Ditto.Tests/DefaultProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void Default_Processor_GlobalLevel_IsUsed()
Ditto.RegisterDefaultProcessorType<UmbracoPropertyAttribute>();

// ...and clear the type-config cache
DittoTypeConfigCache.Clear<MyModel>();
DittoTypeInfoCache.Clear<MyModel>();
}
}
}
16 changes: 8 additions & 8 deletions tests/Our.Umbraco.Ditto.Tests/PropertySourceMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ public void PropertySource_Properties_Map()
};

Ditto.DefaultPropertySource = PropertySource.InstanceThenUmbracoProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

var model = content.As<BasicModelProperty>();
Assert.AreEqual(instanceName, model.Name);
Assert.AreEqual(instanceUrl, model.Url);
Assert.AreEqual(customProp, model.Custom);

Ditto.DefaultPropertySource = PropertySource.UmbracoThenInstanceProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

model = content.As<BasicModelProperty>();
Assert.AreEqual(customName, model.Name);
Assert.AreEqual(instanceUrl, model.Url);
Assert.AreEqual(customProp, model.Custom);

Ditto.DefaultPropertySource = PropertySource.InstanceProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

model = content.As<BasicModelProperty>();
Assert.AreEqual(instanceName, model.Name);
Assert.AreEqual(instanceUrl, model.Url);
Assert.IsNull(model.Custom);

Ditto.DefaultPropertySource = PropertySource.UmbracoProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

model = content.As<BasicModelProperty>();
Assert.AreEqual(customName, model.Name);
Expand All @@ -85,7 +85,7 @@ public void PropertySource_Properties_Map()

// Reset
Ditto.DefaultPropertySource = PropertySource.InstanceThenUmbracoProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();
}

[Test]
Expand Down Expand Up @@ -152,7 +152,7 @@ public void PropertySource_Hidden_Properties_Warn()

// Check for hidden Umbraco properties
Ditto.DefaultPropertySource = PropertySource.InstanceThenUmbracoProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

var model = content.As<BasicModelProperty>();

Expand All @@ -165,7 +165,7 @@ public void PropertySource_Hidden_Properties_Warn()
mockLogger.ClearLogMessages();

Ditto.DefaultPropertySource = PropertySource.UmbracoThenInstanceProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();

model = content.As<BasicModelProperty>();

Expand All @@ -176,7 +176,7 @@ public void PropertySource_Hidden_Properties_Warn()

// Reset
Ditto.DefaultPropertySource = PropertySource.InstanceThenUmbracoProperties;
DittoTypeConfigCache.Clear<BasicModelProperty>();
DittoTypeInfoCache.Clear<BasicModelProperty>();
}
}
}

0 comments on commit 26b4b03

Please sign in to comment.