Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize the type in Typewriter

The Typewriter is generating date type in TypeScript for DateTime types in C#, I want to change it to "string", but not able to do so

here is what I tried in .tst

string TypeConverter(Type type){
    if(type.Name == "Month") return "string";
    return type.Name;
}

And then in latter section tried

//1
export class $Name {$Properties[
    public $Name: TypeConverter($Type);]
}

//2
export class $Name {$Properties[
    public $Name: TypeConverter;]
}

//3
export class $Name {$Properties[
    public $Name: $TypeConverter;]
}

But none of them are working

like image 840
harishr Avatar asked Mar 29 '16 14:03

harishr


1 Answers

Custom methods are called like any other property using $MethodName using the current context as the parameter. So in your example there are two ways to solve the problem.

Change the parameter of the method to match the context:

${
    string TypeConverter(Parameter parameter)
    {  
        if(parameter.Type.Name == "Month")
            return "string";  
        return parameter.Type.Name;  
    }  
}  
export class $Name {$Properties[  
    public $Name: $TypeConverter;]  
}

Or, call the method from a Type context:

${
    string TypeConverter(Type type)
    {  
        if(type.Name == "Month")
            return "string";  
        return type.Name;  
    }  
}  
export class $Name {$Properties[  
    public $Name: $Type[$TypeConverter];]  
}
like image 81
frhagn Avatar answered Sep 23 '22 18:09

frhagn