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 + ");"); } }
public void Dictionary3() { var type = typeof(Dictionary <string, Dictionary <string, int[]> >); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("System.Collections.Generic.Dictionary<System.String, System.Collections.Generic.Dictionary<System.String, System.Int32[]>>", result); }
public void TSM_Beam_BeamTypeEnum() { var type = typeof(Tekla.Structures.Model.Beam.BeamTypeEnum); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("Tekla.Structures.Model.Beam.BeamTypeEnum", result); }
public void Int32() { var type = typeof(int[]); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("System.Int32[]", result); }
public void GenericList() { var type = typeof(List <string>); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("System.Collections.Generic.List<System.String>", result); }
public void Dictionary2() { var type = typeof(Dictionary <string, Beam.BeamTypeEnum>); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("System.Collections.Generic.Dictionary<System.String, Tekla.Structures.Model.Beam.BeamTypeEnum>", result); }
public void DetailMark_DetailMarkAttributes() { var type = typeof(Tekla.Structures.Drawing.DetailMark.DetailMarkAttributes.DetailBoundaryShape); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("Tekla.Structures.Drawing.DetailMark.DetailMarkAttributes.DetailBoundaryShape", result); }
public void Nullable2() { var type = typeof(System.Nullable <DateTime>); Console.WriteLine(type.ToString()); var result = TypeFullName.GetTypeFullName(type); Console.WriteLine("Result:\t" + result); Assert.AreEqual("System.Nullable<System.DateTime>", result); }
public void Dictionary_In_DatabaseObject() { var method = typeof(Tekla.Structures.Drawing.DatabaseObject).GetMethods() .Where(m => m.Name.Equals("GetStringUserProperties", StringComparison.InvariantCulture) && m.GetParameters().Count().Equals(1)).FirstOrDefault(); Assert.NotNull(method); var param = method.GetParameters().FirstOrDefault(); var result = TypeFullName.GetTypeFullName(param.ParameterType); Console.WriteLine(result); Assert.AreEqual("System.Collections.Generic.Dictionary<System.String, System.String>", result); }
public static System.Type FromTSObjects(System.Type input) { try { var typeFullName = TypeFullName.GetTypeFullName(input); if (typeFullName.StartsWith("Tekla.Structures.", System.StringComparison.InvariantCulture)) { var typeName = typeFullName.Replace("Tekla.Structures.", "Dynamic.Tekla.Structures."); return(TSActivator.GetTypeFromTypeName(typeName)); } else { return(input); } } catch (System.Exception ex) { throw new DynamicAPIException("Error in method TypeConverter.FromTSObjects() Input type: " + input.GetType().ToString() + "\n Internal error message: " + ex.Message, ex); } }
private static string GetMethodCall(MethodInfo methodInfo, List <MethodParameter> parameters) { var sb = new StringBuilder(200); bool hasOutParameter = methodInfo.GetParameters().Any(p => p.IsOut); if (!IsVoid(methodInfo)) { sb.Append("var result = "); } if (!Converters.HaveToBeConverted(methodInfo.ReturnType)) { sb.Append("(").Append(TypeFullName.GetTypeFullName(methodInfo.ReturnType)).Append(") "); } if (methodInfo.IsStatic) { sb.Append("MethodInvoker.InvokeStaticMethod(\"").Append("$typeFullName").Append("\", \"") .Append(methodInfo.Name).Append("\""); if (parameters.Count > 0) { sb.Append(", "); } } else if (hasOutParameter) { sb.Append("MethodInvoker.InvokeMethod(\"").Append("$typeFullName").Append("\", \"") .Append(methodInfo.Name).Append("\", ").Append("teklaObject"); if (parameters.Count > 0) { sb.Append(", "); } } else { sb.Append("teklaObject.") .Append(methodInfo.Name) .Append("("); } if (parameters.Count > 0) { foreach (var parameter in parameters) { if (methodInfo.IsStatic) { sb.Append(parameter.MethodCall.Replace("out ", "ref ")); } else { sb.Append(parameter.MethodCall); } sb.Append(", "); } sb.Remove(sb.Length - 2, 2); } sb.Append(");"); if (methodInfo.IsStatic == false) { return($@" try {{ {sb.ToString()}"); } else { return(sb.ToString()); } }