【发布时间】:2015-12-19 00:35:36
【问题描述】:
我正在尝试探索 TypeLite 框架,以便能够用 C# 编写代码并随后生成一个 javascript 文件(因为我们在客户端和服务器端都需要相同的代码)。
当我可以将所有类转换为接口时,我取得了初步成功。但是,我坚持转换方法。 TypeLite 是否也支持将方法转换为 Typescript? TypeLite 支持 POCO 对象,因此,理想情况下,我应该能够从这些方法中生成一个 Typescript 方法。
这是我尝试运行的示例代码和我得到的输出:
public class Person
{
public string Name { get; set; }
public List<Address> Addresses { get; set; }
public Dictionary<int, string> dict { get; set; }
public string GetName()
{
return Name + Addresses.ToString();
}
}
public class Concrete
{
public Person person { get; set; }
public string name;
public Concrete()
{
person = new Person();
name = person.GetName();
}
}
public class Employee : Person
{
public decimal Salary { get; set; }
}
这就是我得到的:
declare module MvcApplication4.Controllers {
interface Person {
Name: string;
Addresses: MvcApplication4.Controllers.Address[];
dict: System.Collections.Generic.KeyValuePair<number, string>[];
}
interface Address {
Street: string;
}
interface Concrete {
person: MvcApplication4.Controllers.Person;
}
interface Employee extends MvcApplication4.Controllers.Person {
Salary: number;
}
}
declare module System.Collections.Generic {
interface KeyValuePair<TKey, TValue> {
Key: TKey;
Value: TValue;
}
}
注意:我在生成的 ts 文件中没有得到 GetName 函数 :(
任何帮助将不胜感激。
【问题讨论】: