public void GetPersonInterface()
 {
     var engine = new RazorTemplateEngine();
     var content = engine.GetTypeScriptInterface(typeof (Person));
     var filePath = String.Format("./../../Models/Person.ts");
     var expectContent = File.ReadAllText(filePath);
     Assert.AreEqual(expectContent,content);
 }
示例#2
0
        /// <summary>
        /// TODO : not only JSON stuff.
        /// </summary>
        /// <param name="targetMembers"></param>
        /// <returns></returns>
        private static string GetTypeScriptJSonInterfaces(IEnumerable<MemberInfo> targetMembers)
        {
            var engine = new RazorTemplateEngine();
            var methods = targetMembers.OfType<MethodInfo>().ToList();
            var returnTypes = methods.Select(m => m.ReturnType).Distinct().ToList();
            var parameterTypes = methods.SelectMany(m => m.GetParameters()).Select(p => p.ParameterType).Distinct().ToList();
            var relevantTypes = returnTypes.Concat(parameterTypes).Where(t => !t.FullName.StartsWith("System")).ToList();
            var result = new StringBuilder();

            foreach (var relevantType in relevantTypes.Where(t => t.IsJsonResult()))
            {
                var genericArgument = relevantType.GetGenericArguments()[0];
                result.Append(engine.GetTypeScriptInterface(genericArgument));
            }
            return result.ToString();
        }