-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from contentstack/2.4.0
Autoload converter support Delivery Token Support added JsonConverter autoload implemented
- Loading branch information
Showing
14 changed files
with
262 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
namespace Contentstack.Core | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class CSJsonConverterAttribute : Attribute | ||
{ | ||
private readonly string name; | ||
private readonly bool isAutoloadEnable; | ||
private static ConcurrentDictionary<Type, List<Type>> _types = new ConcurrentDictionary<Type, List<Type>>(); | ||
|
||
/// <summary> | ||
/// Name for the JsonConverter | ||
/// </summary> | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return this.name; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// To enable autoload in ContentstackClient. Default is Enable. | ||
/// </summary> | ||
public bool IsAutoloadEnable | ||
{ | ||
get | ||
{ | ||
return this.isAutoloadEnable; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// CSJsonConverterAttribute constructor | ||
/// </summary> | ||
/// <param name="name">Name for the JsonConverter</param> | ||
/// <param name="isAutoloadEnable"> To enable autoload in ContentstackClient. Default is Enable.</param> | ||
public CSJsonConverterAttribute(string name, bool isAutoloadEnable = true) | ||
{ | ||
this.name = name; | ||
this.isAutoloadEnable = isAutoloadEnable; | ||
} | ||
|
||
internal static IEnumerable<Type> GetCustomAttribute(Type attribute) | ||
{ | ||
if (!_types.ContainsKey(attribute)) | ||
{ | ||
List<Type> result = new List<Type>(); | ||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) | ||
{ | ||
try | ||
{ | ||
foreach (Type type in assembly.GetTypes()) | ||
{ | ||
var objectType = type.GetCustomAttributes(attribute, true); | ||
foreach (var attr in type.GetCustomAttributes(typeof(CSJsonConverterAttribute))) | ||
{ | ||
CSJsonConverterAttribute ctdAttr = attr as CSJsonConverterAttribute; | ||
Trace.Assert(ctdAttr != null, "cast is null"); | ||
if (ctdAttr.isAutoloadEnable) | ||
{ | ||
result.Add(type); | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
} | ||
} | ||
_types[attribute] = result; | ||
} | ||
return _types[attribute].ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.