private static string GetNonStaticGet(MemberInfo propertyOrField, Type propertyOrFieldType) { string getCode = string.Empty; if (Converters.HaveToBeConverted(propertyOrFieldType)) { getCode = $@" var value = teklaObject.{propertyOrField.Name}; {Converters.FromTSObjects(propertyOrFieldType, "value", "var value_")} return ({TypeFullName.GetTypeFullName_WithDynamic(propertyOrFieldType)}) value_;"; } else { getCode = $@" return teklaObject.{ propertyOrField.Name};"; } return($@"get {{ try {{{getCode} }} catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex) {{ throw DynamicAPINotFoundException.CouldNotFindProperty(nameof({propertyOrField.Name}), ex); }} }}"); }
private static string NonStaticProperty(MemberInfo propertyOrField, Type currentType, bool hasGet, bool hasSet) { var typeFullNameWithDynamic = TypeFullName.GetTypeFullName_WithDynamic(currentType); string nonstaticGet = string.Empty; if (hasGet) { nonstaticGet = GetNonStaticGet(propertyOrField, currentType); } string nonstaticSet = string.Empty; if (hasSet) { nonstaticSet = GetNonStaticSet(propertyOrField, currentType); } return($@" public {typeFullNameWithDynamic} {propertyOrField.Name} {{ {nonstaticGet} {nonstaticSet} }} "); }
public static string ToTSObjects(Type type, string inputName, string outputName) { var typeFullName = TypeFullName.GetTypeFullName(type); var typeFullNameWithDynamic = TypeFullName.GetTypeFullName_WithDynamic(type); if (TypeFullName.IsTeklaType(type)) { if (typeFullNameWithDynamic.EndsWith("[]", StringComparison.InvariantCulture)) { return(outputName + " = " + typeFullNameWithDynamic.Replace("[]", "") + "Array_.GetTSObject(" + inputName + ");"); } else { return(outputName + " = " + typeFullNameWithDynamic + "_.GetTSObject(" + inputName + ");"); } } else if (typeof(ArrayList).IsAssignableFrom(type)) { return(outputName + " = ArrayListConverter.ToTSObjects(" + inputName + ");"); } else if (typeFullName.StartsWith("System.Collections.Generic.List<", StringComparison.InvariantCulture) || typeFullName.StartsWith("System.Collections.Generic.IList<", StringComparison.InvariantCulture) ) { if (typeFullName.StartsWith("System.Collections.Generic.List<System.Collections.Generic.List<", StringComparison.InvariantCulture) || typeFullName.StartsWith("System.Collections.Generic.IList<System.Collections.Generic.IList<", StringComparison.InvariantCulture)) { return(outputName + " = ListOfListConverter.ToTSObjects(" + inputName + ");"); } else { return(outputName + " = ListConverter.ToTSObjects(" + inputName + ");"); } } else if (typeof(System.Type).IsAssignableFrom(type) || typeof(System.Type[]).IsAssignableFrom(type)) { return(outputName + " = TypeConverter.ToTSObjects(" + inputName + ");"); } else if (typeof(IEnumerable).IsAssignableFrom(type)) { //var ienumerableParameters = typeFullName.Substring(typeFullName.IndexOf("<"), typeFullName.Length - typeFullName.IndexOf("<")); return(outputName + " = IEnumerableConverter.ToTSObjects(" + inputName + ");"); } else if (typeFullName.StartsWith("System.Tuple", StringComparison.InvariantCulture)) { var tupleParams = typeFullName.Substring(typeFullName.IndexOf("<"), typeFullName.Length - typeFullName.IndexOf("<")); return(outputName + " = TupleConverter.ToTSObjects" + tupleParams + "(" + inputName + ");"); } else if (typeFullName.StartsWith("System.Nullable", StringComparison.InvariantCulture)) { return(outputName + " = NullableConverter.ToTSObjects(" + inputName + ");"); } else { return(outputName + " = ObjectConverter.ToTSObject(" + inputName + ");"); } }
private static string GetReturnType(MethodInfo methodInfo) { var returnType = TypeFullName.GetTypeFullName_WithDynamic(methodInfo.ReturnType); if (returnType.Equals("System.Void")) { returnType = "void"; } return(returnType); }
private static string GetStaticGet(MemberInfo propertyOrField, Type propertyOrFieldType) { var propTypeFullName = TypeFullName.GetTypeFullName_WithDynamic(propertyOrFieldType); string valueConverter = $"return ({propTypeFullName}) value;"; if (Converters.HaveToBeConverted(propertyOrFieldType)) { valueConverter = Converters.FromTSObjects(propertyOrFieldType, "value", "var value_"); valueConverter += $"\n\treturn ({propTypeFullName}) value_;"; } return($@"get {{ var value = PropertyInvoker.GetStaticPropertyOrFieldValue(""$typeFullName"", ""{propertyOrField.Name}""); {valueConverter} }}"); }
private string GetFieldsText(Type type) { var sb = new StringBuilder(100); var fields = GetFields(type); foreach (var field in fields) { sb.Append("\t\t\t"); sb.Append("public "); sb.Append(TypeFullName.GetTypeFullName_WithDynamic(field.FieldType)); sb.Append(" "); sb.Append(field.Name); sb.Append(";\n"); } return(sb.ToString()); }
public string GetTextFromType(Type type) { if (type.IsEnum == false) { return(string.Empty); } var sb = new StringBuilder(text.Length * 5); sb.Append(text); sb.Replace("$enumValues", GetEnumValuesText(type)); sb.Replace("$switch1Values", GetSwitch1Values(type)); sb.Replace("$switch2Values", GetSwitch2Values(type)); sb.Replace("$classname", type.Name); sb.Replace("$typeFullName", TypeFullName.GetTypeFullName_WithDynamic(type).Replace("Dynamic.", "")); return(sb.ToString()); }
private string GetTypeFullName(Type type) { return(TypeFullName.GetTypeFullName_WithDynamic(type)); }