From 535490e95dc9513186b3ae850a7b479c6d48ca4e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 12 Oct 2024 02:13:13 +0000 Subject: [PATCH] Adding local property initializers (#255) Co-authored-by: Michael Waddell --- salt2type | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/salt2type b/salt2type index 78a3516..7950fe9 100755 --- a/salt2type +++ b/salt2type @@ -60,7 +60,7 @@ class PropDef: """ Whether or not this is a rest parameter (None if unknown). """ is_static: Optional[bool] = None - """ Whether or not this method is static (None if unknown). """ + """ Whether or not this property is static (None if unknown). """ @dataclass @@ -628,6 +628,8 @@ def add_doc_info(defs: List[ClassDef], types: List[ClassDef]) -> None: curr_prop.typ = prop.typ curr_prop.desc = prop.desc curr_prop.is_rest = prop.is_rest + elif not prop.name.startswith("this["): + curr_class.props.append(PropDef(to_local_prop(prop.name), None, prop.typ, prop.desc, prop.is_rest, False)) curr_class.links.extend(typ.links) @@ -682,6 +684,16 @@ def copy_tpl(out_dir: str, asm_name: str, ns_name: str) -> None: copy_file(src_file, dst_file, asm_name, ns_name) +def to_local_prop(name: str) -> str: + """ + Converts a C# local property to a S# name + """ + if name[:1] == name[:1].lower(): + return "$" + name + + return name[:1].lower() + name[1:] + + def prop_to_string(prop: PropDef) -> str: """ Generates a stringified version of the property for typescript