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

Commit

Permalink
Merge pull request #242 from umco/develop
Browse files Browse the repository at this point in the history
Preparing Ditto 0.12.2 release
  • Loading branch information
leekelleher authored Dec 7, 2018
2 parents 59faa63 + b993561 commit 28535eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2017

# version format
version: 0.12.1.{build}
version: 0.12.2.{build}

# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
Expand Down Expand Up @@ -48,7 +48,7 @@ deploy:
- provider: NuGet
server:
api_key:
secure: 0+oAleUTnr9UuJrhLW5rphRR+QGz00XX1Ui3k5kwyr2kUdEamiQ3F+gW0q8MJbDT
secure: vEophXSqus5F60LRBY4/j1l6K/S5+n3/yYpiID3O7JJW1gyj+0q0enuHhN3tgdhl
artifact: /.*\.nupkg/
on:
branch: master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected DittoProcessorAttribute()
{
if (Ditto.TryGetTypeAttribute(this.GetType(), out DittoProcessorMetaDataAttribute metaData, true) == false || metaData == null)
{
throw new ApplicationException("Ditto processor attributes require a DittoProcessorMetaData attribute to be applied to the class but none was found.");
throw new ApplicationException($"The Ditto processor attribute ('{this.GetType()}') requires a DittoProcessorMetaData attribute to be applied to the class but none was found.");
}

this.ValueType = metaData.ValueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ namespace Our.Umbraco.Ditto
/// <typeparam name="TAttribute">A specific Ditto attribute type.</typeparam>
internal sealed class AttributedTypeResolver<TAttribute> where TAttribute : Attribute
{
private readonly ConcurrentDictionary<Type, TAttribute> _attributedTypeLookup;
private readonly object _lock = new object();

private readonly Dictionary<Type, TAttribute> _attributedTypeLookup;

private AttributedTypeResolver()
{
_attributedTypeLookup = new ConcurrentDictionary<Type, TAttribute>();
_attributedTypeLookup = new Dictionary<Type, TAttribute>();
}

private void Initialize(IEnumerable<Type> types, bool inherit = false)
{
if (types != null)
// NOTE: Lock when initializing the resolver, so that it can't be read from (at the same time).
lock (_lock)
{
foreach (var type in types)
if (types != null)
{
TryAddAttributedType(type, out TAttribute attribute, inherit);
foreach (var type in types)
{
TryAddAttributedType(type, out TAttribute attribute, inherit);
}
}
}
}
Expand Down Expand Up @@ -83,7 +89,8 @@ private bool TryAddAttributedType(Type type, out TAttribute attribute, bool inhe
{
if (_attributedTypeLookup.ContainsKey(type) == false)
{
return _attributedTypeLookup.TryAdd(type, attribute);
_attributedTypeLookup.Add(type, attribute);
return true;
}
else
{
Expand All @@ -103,14 +110,18 @@ private bool TryAddAttributedType(Type type, out TAttribute attribute, bool inhe
/// <returns>Returns the associated attribute for the given object-type.</returns>
public bool TryGetTypeAttribute(Type type, out TAttribute attribute, bool inherit = false)
{
bool result = _attributedTypeLookup.TryGetValue(type, out attribute);

if (result == false)
// NOTE: Lock when looking up from the resolver, to avoid concurrency issues.
lock (_lock)
{
result = TryAddAttributedType(type, out attribute, inherit);
}
bool result = _attributedTypeLookup.TryGetValue(type, out attribute);

return result;
if (result == false)
{
result = TryAddAttributedType(type, out attribute, inherit);
}

return result;
}
}
}
}

0 comments on commit 28535eb

Please sign in to comment.