Skip to content

Commit

Permalink
feat: release v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adragonite committed Sep 26, 2017
1 parent bb7b7b3 commit 96b7751
Show file tree
Hide file tree
Showing 8 changed files with 972 additions and 219 deletions.
49 changes: 26 additions & 23 deletions Assets/Plugins/UnityJSON/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ public NodeOptions options {
/// list/array of objects or a dictionary with value type object. For dictionaries,
/// the restriction is only applied to the value type.
/// </summary>
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Property)]
[AttributeUsage (
AttributeTargets.Field |
AttributeTargets.Property |
AttributeTargets.Parameter)]
public class RestrictTypeAttribute : Attribute
{
private ObjectTypes _types;
Expand All @@ -183,11 +186,31 @@ public RestrictTypeAttribute (ObjectTypes types) : base ()
_types = types;
}

public RestrictTypeAttribute (ObjectTypes types, Type[] customTypes) : base ()
public RestrictTypeAttribute (ObjectTypes types, params Type[] customTypes) : base ()
{
if (customTypes == null) {
throw new ArgumentNullException ("customTypes");
}
_types = types;

if (!_types.SupportsCustom ()) {
throw new ArgumentException ("Attribute does not support custom types.");
}

List<Type> typeList = new List<Type> ();
HashSet<Type> typeSet = new HashSet<Type> ();
foreach (Type type in customTypes) {
if (type != null
&& !typeSet.Contains (type)
&& Util.IsCustomType (type)) {
typeSet.Add (type);
typeList.Add (type);
}
}

if (typeList.Count != 0) {
_customTypes = typeList.ToArray ();
}
}

/// <summary>
Expand All @@ -205,26 +228,6 @@ public ObjectTypes types {
/// </summary>
public Type[] customTypes {
get { return _customTypes; }
set {
if (!_types.SupportsCustom ()) {
throw new ArgumentException ("Attribute does not support custom types.");
}

List<Type> typeList = new List<Type> ();
HashSet<Type> typeSet = new HashSet<Type> ();
foreach (Type type in value) {
if (type != null
&& !typeSet.Contains (type)
&& Util.IsCustomType (type)) {
typeSet.Add (type);
typeList.Add (type);
}
}

if (typeList.Count != 0) {
_customTypes = typeList.ToArray ();
}
}
}
}

Expand Down Expand Up @@ -293,7 +296,7 @@ public object value {
/// contain any data for the class / struct in order to
/// prevent any unknown key errors.
/// </summary>
public bool removeKey { get; set; }
public bool ignoreConditionKey { get; set; }
}

/// <summary>
Expand Down
Loading

0 comments on commit 96b7751

Please sign in to comment.