Created
November 9, 2013 18:59
-
-
Save Jaecen/7388582 to your computer and use it in GitHub Desktop.
A simple C# implementation of Siren.
This file contains hidden or 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
public class Siren | |
{ | |
public readonly string Title; | |
public readonly IEnumerable<string> Class; | |
public readonly IDictionary<string, string> Properties; | |
public readonly IEnumerable<Entity> Entities; | |
public readonly IEnumerable<Action> Actions; | |
public Siren( | |
string title = null, | |
IEnumerable<string> @class = null, | |
IDictionary<string, string> properties = null, | |
IEnumerable<Entity> entities = null, | |
IEnumerable<Action> actions = null | |
) | |
{ | |
Title = title; | |
Class = @class; | |
Properties = properties; | |
Entities = entities; | |
Actions = actions; | |
} | |
public class Entity | |
{ | |
public readonly IEnumerable<string> Rel; | |
public Entity(IEnumerable<string> rel = null) | |
{ | |
Rel = rel; | |
} | |
} | |
public class EntityLink : Entity | |
{ | |
public readonly IEnumerable<string> Class; | |
public readonly string Href; | |
public EntityLink(string href, IEnumerable<string> rel, IEnumerable<string> @class = null) | |
: base(rel) | |
{ | |
Href = href; | |
Class = @class; | |
} | |
} | |
public class EntityRepresentation<T> : Entity | |
{ | |
public readonly T Entity; | |
public EntityRepresentation(IEnumerable<string> rel, T entity) | |
: base(rel) | |
{ | |
Entity = entity; | |
} | |
} | |
public class Link | |
{ | |
public readonly string Href; | |
public readonly IEnumerable<string> Rel; | |
public Link(string href, IEnumerable<string> rel) | |
{ | |
Href = href; | |
Rel = rel; | |
} | |
} | |
public class Action | |
{ | |
public readonly string Name; | |
public readonly IEnumerable<string> Class; | |
public readonly string Method; | |
public readonly string Href; | |
public readonly string Title; | |
public readonly string Type; | |
public readonly IEnumerable<Field> Fields; | |
public Action(string name, string href, IEnumerable<string> @class = null, string method = null, string title = null, string type = null, IEnumerable<Field> fields = null) | |
{ | |
Name = name; | |
Href = href; | |
Class = @class; | |
Method = method; | |
Title = title; | |
Type = type; | |
Fields = fields; | |
} | |
} | |
public class Field | |
{ | |
public readonly string Name; | |
public readonly string Type; | |
public readonly string Value; | |
public Field(string name, string type = "text", string value = null) | |
{ | |
Name = name; | |
Type = type; | |
Value = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment