Exemplo n.º 1
0
        public static void Configure(HttpConfiguration config)
        {
            config.EnsureInitialized();

            var apiExplorer = config.Services.GetApiExplorer();

            var table = new LinkTable();
            foreach (var apiDescription in apiExplorer.ApiDescriptions)
            {
                var descriptor = apiDescription.ActionDescriptor as ReflectedHttpActionDescriptor;
                if (descriptor != null)
                {
                    var linksFromAttributes = descriptor.MethodInfo.GetCustomAttributes(typeof (LinksFromAttribute), false).Cast<LinksFromAttribute>().ToArray();
                    if (linksFromAttributes.Length > 0)
                    {
                        foreach (var attribute in linksFromAttributes)
                        {
                            var linkBuilder = LinkBuilder.Create(attribute, apiDescription);
                            if (linkBuilder != null)
                            {
                                table.Add(linkBuilder);
                            }
                        }
                    }
                }
            }

            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.ContractResolver = new LinkyContractResolver(table, json.SerializerSettings.ContractResolver);
        }
Exemplo n.º 2
0
        public static void Configure(HttpConfiguration config, string propName = null)
        {
            config.EnsureInitialized();

            var apiExplorer = config.Services.GetApiExplorer();

            var table = new LinkTable();

            foreach (var apiDescription in apiExplorer.ApiDescriptions)
            {
                var descriptor = apiDescription.ActionDescriptor as ReflectedHttpActionDescriptor;
                if (descriptor != null)
                {
                    var linksFromAttributes = descriptor.MethodInfo.GetCustomAttributes(typeof(LinksFromAttribute), false).Cast <LinksFromAttribute>().ToArray();
                    if (linksFromAttributes.Length > 0)
                    {
                        foreach (var attribute in linksFromAttributes)
                        {
                            var linkBuilder = LinkBuilder.Create(attribute, apiDescription);
                            if (linkBuilder != null)
                            {
                                table.Add(linkBuilder);
                            }
                        }
                    }
                }
            }

            var json = config.Formatters.JsonFormatter;

            json.SerializerSettings.ContractResolver = new LinkyContractResolver(table, json.SerializerSettings.ContractResolver, propName);
        }
Exemplo n.º 3
0
 public LinkyContractResolver(LinkTable table, IContractResolver contractResolver, string propName)
 {
     _table            = table;
     _propName         = propName ?? "_links";
     _contractResolver = contractResolver ?? new DefaultContractResolver();
 }
Exemplo n.º 4
0
 public LinkyContractResolver(LinkTable table, IContractResolver contractResolver)
 {
     _table = table;
     _contractResolver = contractResolver ?? new DefaultContractResolver();
 }