| 937 | |
| 938 | |
| 939 | class Csharp(BaseParser): |
| 940 | |
| 941 | function_name_mapping = dict(Props1SI='CoolProp.Props1SI', |
| 942 | PropsSI='CoolProp.PropsSI', |
| 943 | PhaseSI='CoolProp.PhaseSI', |
| 944 | HAPropsSI='CoolProp.HAPropsSI', |
| 945 | get_global_param_string='CoolProp.get_global_param_string', |
| 946 | factory='AbstractState.factory') |
| 947 | type_name_mapping = {'vector': "DoubleVector", |
| 948 | 'AbstractState': 'AbstractState'} |
| 949 | enum_name_mapping = {'input_pairs': "input_pairs", 'parameters': "parameters"} |
| 950 | indentation = ' ' * 12 |
| 951 | |
| 952 | def parse_arguments(self, arguments): |
| 953 | out = [] |
| 954 | for arg in arguments: |
| 955 | if isinstance(arg, str) and arg[0] == "'" and arg[-1] == "'": |
| 956 | out.append('\"' + arg[1:-1] + '\"') |
| 957 | elif isinstance(arg, dict): |
| 958 | out.append(self.dict2string(arg)) |
| 959 | else: |
| 960 | out.append(arg) |
| 961 | return out |
| 962 | |
| 963 | def dict2string(self, d): |
| 964 | if d['type'] == 'comment': |
| 965 | l = '// ' + d['comment'] |
| 966 | elif d['type'] == 'print': |
| 967 | l = 'Console.Write(' + ' + " " + '.join(self.parse_arguments(d['arguments'])) + ' + "\\n")' |
| 968 | elif d['type'] == 'function': |
| 969 | l = self.map_function(d['function']) + '(' + ', '.join(self.parse_arguments(d['arguments'])) + ')' |
| 970 | elif d['type'] == 'vector': |
| 971 | l = 'new DoubleVector(new double[]{' + ', '.join(self.parse_arguments(d['arguments'])) + '})' |
| 972 | elif d['type'] == 'enum': |
| 973 | l = self.enum_name_mapping[d['enum']] + '.' + d['key'] |
| 974 | elif d['type'] == 'class_dereference': |
| 975 | l = d['name'] + '.' + self.dict2string(d['RHS']) |
| 976 | elif d['type'] == 'custom_assignment': |
| 977 | type_name = self.type_name_mapping[d['variable_type']] |
| 978 | if type_name: |
| 979 | LHS = type_name + ' ' + d['variable_name'] |
| 980 | else: |
| 981 | LHS = d['variable_name'] |
| 982 | l = ' '.join([LHS, '=', self.dict2string(d['RHS'])]) |
| 983 | else: |
| 984 | raise ValueError |
| 985 | |
| 986 | if 'EOL' in d and d['EOL']: |
| 987 | l += ';' |
| 988 | |
| 989 | return l |
| 990 | |
| 991 | def header(self): |
| 992 | return 'using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n' |
| 993 | |
| 994 | def footer(self): |
| 995 | return '\n }\n }\n}' |
| 996 |
no outgoing calls
no test coverage detected