public int Add(CSType t, Object obj) { _count++; _slots[_count].Type = t; _slots[_count].obj = new WeakReference(obj); return(_count); }
public ThreadIntegration(int iterationNumber, int timeout, int Сount, CSType csType) { _iterationNumber = iterationNumber; _timeout = timeout; _csType = csType; _cs = new AutoResetEventCS(); _cs.SetSpinCount(Сount); }
public void CreateChart3D(ArrayList ary, CSType csType, string capt) { Chart3D chart3D = new Chart3D(); chart3D.caption = capt; int vertNum = ary.Count; int trigNum = (int)(vertNum / 3); chart3D.SetDataNo(vertNum); double phi, theta; double alpha, beta, r; for (int i = 0; i < vertNum; i++) { switch (csType) { case CSType.DEC: { } break; case CSType.CALC: { phi = ((Point3D)ary[i]).X; theta = ((Point3D)ary[i]).Y; r = ((Point3D)ary[i]).Z; chart3D.vertices[i] = new Vertex3D(); chart3D.vertices[i].x = r * Math.Cos(phi) * Math.Sin(theta); chart3D.vertices[i].y = r * Math.Sin(phi) * Math.Sin(theta); chart3D.vertices[i].z = r * Math.Cos(theta); } break; case CSType.TOPO: { alpha = ((Point3D)ary[i]).X; beta = ((Point3D)ary[i]).Y; r = ((Point3D)ary[i]).Z; chart3D.vertices[i] = new Vertex3D(); chart3D.vertices[i].x = r * Math.Sin(alpha) * Math.Cos(beta); chart3D.vertices[i].y = r * Math.Sin(beta); chart3D.vertices[i].z = r * Math.Cos(alpha) * Math.Cos(beta); } break; } } chart3D.GetDataRange(); for (int i = 0; i < vertNum; i++) { Vertex3D vert = chart3D[i]; r = Math.Pow((vert.x - xC) / (xMax - xMin), 2); r += Math.Pow((vert.y - yC) / (yMax - yMin), 2); r += Math.Pow((vert.z - zC) / (zMax - zMin), 2); r = 1.8 * Math.Sqrt(r); Color color = TextureMapping.PseudoColor(r); chart3D[i].color = color; } chart3D.SetAxes(0.0, 0.0, 0.0, 1.2f, 1.2f, 1.2f); chart3DList.Add(chart3D); }
private static ICoordinateSystem GetCoordinateSystem(CSType csType) { ICoordinateSystem cs = null; switch (csType) { case CSType.GCS_Xian_1980: cs = CoordinateSystemWktReader.Parse(CSWKT.GCS_Xian_1980) as IGeographicCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_35: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_35) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_36: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_36) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_37: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_37) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_GK_Zone_18: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_GK_Zone_18) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_GK_Zone_19: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_GK_Zone_19) as IProjectedCoordinateSystem; break; case CSType.GCS_Beijing_1954: cs = CoordinateSystemWktReader.Parse(CSWKT.GCS_Beijing_1954) as IGeographicCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_35: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_35) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_36: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_36) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_37: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_37) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_GK_Zone_18: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_GK_Zone_18) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_GK_Zone_19: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_GK_Zone_19) as IProjectedCoordinateSystem; break; } return(cs); }
static bool IsEqualTo(this CSType one, CSType other) { if (other == null) { return(false); } if (one is CSSimpleType simpleOne && other is CSSimpleType simpleOther) { return(simpleOne.IsEqualTo(simpleOther)); }
public void ClassWithSingleDeclAllTypes() { foreach (MethodInfo mi in typeof(CSType).GetMethods().Where(mii => mii.IsStatic && mii.IsPublic && mii.ReturnType == typeof(CSType))) { CSType cs = mi.Invoke(null, null) as CSType; if (cs != null) { DeclType(cs); } } }
public static CSSimpleType ToCSTuple(IList <NetTypeBundle> innerTypes, CSUsingPackages use) { if (innerTypes.Count <= 7) { return(new CSSimpleType("Tuple", false, ToCSSimpleType(innerTypes, use).ToArray())); } else { IEnumerable <CSType> head = ToCSSimpleType(innerTypes.Take(7), use); CSType tail = ToCSTuple(innerTypes.Skip(7).ToList(), use); return(new CSSimpleType("Tuple", false, Enumerable.Concat(head, Enumerable.Repeat(tail, 1)).ToArray())); } }
private static void Process(int iterationNumber, int timeout, int count, CSType csType, string typeStr) { ThreadIntegration integration = new ThreadIntegration(iterationNumber, timeout, count, csType); Stopwatch watch = Stopwatch.StartNew(); double pi = integration.Integrate(); watch.Stop(); Console.WriteLine("PI: " + pi); Console.WriteLine("TIME: " + watch.ElapsedMilliseconds); Console.WriteLine("TYPE: " + typeStr); Console.WriteLine("---------------------"); }
void DeclType(CSType type) { if (type == CSSimpleType.Void) { return; } using (Stream stm = Utils.BasicClass("None", "AClass", null, cl => { cl.Fields.Add(CSFieldDeclaration.FieldLine(type, "b", null, CSVisibility.Public)); return(cl); })) { Utils.CompileAStream(stm); } }
//public static DataSet GetDataSetbySql(string select) //{ // DBCommInfo.DBSQLCommandInfo cmdInfo = new DBSQLCommandInfo();//执行命令的对象 // cmdInfo.SqlText = select; // cmdInfo.SqlType = SqlCommandType.sctSql; //SQL命令类型 SqlCommandType.sctSql SQL 语句 SqlCommandType.sctProcedure 表存储过程 // cmdInfo.PageIndex = 0; //需要分页时的页号 // cmdInfo.PageSize = 0; //需要分页时的每页记录条数 // cmdInfo.FromSysType = "dotnet"; // SunEast.SeDBClient sdcX = new SeDBClient(); // string sErr = ""; // DataSet ds = sdcX.GetDataSet(cmdInfo, out sErr); // return ds; //} /// <summary> /// 选择客户或供应商方法 /// </summary> /// <param name="objApp">应用程序对象</param> /// <param name="objUser">用户对象</param> /// <param name="csType">客户供应商类型</param> /// <param name="nIsInner">是否内部单位 -1 全部 0 否 1 是</param> /// <param name="nIsFacctory">是否生产厂家 -1 全部 0 否 1 是(仅对供应商而言)</param> /// <param name="sCSName">搜索的名称</param> /// <param name="doSelCuSpplier">处理选择的事件方法</param> public static void SelectCuSupplier(WMSAppInfo objApp, WMSUserInfo objUser, CSType csType, int nIsInner, int nIsFacctory, string sCSName, DoSelCuSupplierEvent doSelCuSpplier) { frmSelCuSupplier frmX = new frmSelCuSupplier(); frmX.AppInformation = objApp; frmX.UserInformation = objUser; frmX.DoSelCuSupplier = doSelCuSpplier; frmX.CuSupplierType = csType; frmX.IsInner = nIsInner; frmX.IsFactory = nIsFacctory; frmX.txt_cName.Text = sCSName.Trim(); frmX.ShowDialog(); frmX.Dispose(); }
private void btn_OK_Click(object sender, EventArgs e) { if (bds_Data.Count == 0) { MessageBox.Show("对不起,无数据可选择!"); return; } if (grd_Data.SelectedRows.Count == 0) { MessageBox.Show("对不起,没有选择数据!!"); return; } prgMain.Maximum = grd_Data.SelectedRows.Count; prgMain.Minimum = 0; prgMain.Value = 0; prgMain.Visible = true; foreach (DataGridViewRow grdr in grd_Data.SelectedRows) { CSType csTypeX = CSType.cstAll; if (grdr.Cells["col_nType"].Value != null) { csTypeX = (CSType)Convert.ToInt16(grdr.Cells["col_nType"].Value); } int nIsInner = 0; if (grdr.Cells["col_nIsInner"].Value != null) { nIsInner = Convert.ToInt16(grdr.Cells["col_nIsInner"].Value); } int nIsFactory = 0; if (grdr.Cells["col_nIsFactory"].Value != null) { nIsFactory = Convert.ToInt16(grdr.Cells["col_nIsFactory"].Value); } int bUsed = 1; if (grdr.Cells["col_bUsed"].Value != null) { bUsed = Convert.ToInt16(grdr.Cells["col_bUsed"].Value); } if (_DoSelCuSupplier != null) { _DoSelCuSupplier(grdr.Cells["col_cCSId"].Value.ToString(), grdr.Cells["col_cCSNameJ"].Value.ToString(), grdr.Cells["col_cCSNameQ"].Value.ToString(), csTypeX, grdr.Cells["col_cTel"].Value.ToString(), grdr.Cells["col_cFax"].Value.ToString(), grdr.Cells["col_cAddress"].Value.ToString(), grdr.Cells["col_cRemark"].Value.ToString(), grdr.Cells["col_cType"].Value.ToString(), nIsInner, nIsFactory, grdr.Cells["col_cIsInner"].Value.ToString(), grdr.Cells["col_cIsFactory"].Value.ToString(), bUsed, grdr.Cells["col_cUsed"].Value.ToString()); } prgMain.Value++; } Close(); }
CSType MapType(TypeReference typeReference) { CSType commonType = null; if (TryGetCommonName(typeReference.FullName, out commonType)) { return(commonType); } if (typeReference.HasGenericParameters) { var generics = typeReference.GenericParameters.Select(gen => MapType(gen)).ToArray(); var genericType = new CSSimpleType(typeReference.Name, false, generics); return(genericType); } else { var theType = new CSSimpleType(typeReference.Name); return(theType); } }
public static double[] TransForm(double x, double y, CSType fromCSType, CSType toCSType) { ICoordinateSystem fromCS = GetCoordinateSystem(fromCSType); ICoordinateSystem toCS = GetCoordinateSystem(toCSType); string dH = y.ToString().Substring(0, 2); double[] point = new double[2] { y, x }; double[] result = new double[2]; if (y.ToString().Length < 3) { return(null); } if (fromCS != null && toCS != null) { PtsToPts(fromCS, toCS, point, out result); } else { return(null); } return(result); }
private void LoadAction() { StreamReader sr = File.OpenText(fileName); char[] delimiters = { ' ', '\t', ';' }; string str = sr.ReadLine(); int strNo = 1; taskProgress = 0.0; viewer3DWindow.chart3DList.Clear(); while (!sr.EndOfStream) { string[] words = new string[0]; string caption = ""; words = str.Split(delimiters); CSType csType = CSType.DEC; if ((words[0] == "#") && (words[1] != null)) { if (words[1] == "DEC") { csType = CSType.DEC; } else if (words[1] == "CALC") { csType = CSType.CALC; } else if (words[1] == "TOPO") { csType = CSType.TOPO; } else { sr.Close(); return; } } for (int i = 2; i < words.Length; i++) { caption += words[i] + " "; } str = " "; ArrayList verts = new ArrayList(); while (!sr.EndOfStream) { str = sr.ReadLine(); strNo++; if (str[0] != '#') { words = str.Split(delimiters); if (words.Length != 9) { MessageBox.Show("Неправильный формат файла: в строке №" + strNo.ToString() + " найдено " + words.Length.ToString() + " координат(ы). Загрузка будет прервана.", "Ошибка чтения файла", MessageBoxButton.OK, MessageBoxImage.Warning); progressWindow.Close(); return; } verts.Add(new Point3D(double.Parse(words[0]), double.Parse(words[1]), double.Parse(words[2]))); verts.Add(new Point3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5]))); verts.Add(new Point3D(double.Parse(words[6]), double.Parse(words[7]), double.Parse(words[8]))); } else { break; } if (strNo % 1000 == 0) { taskProgress = sr.BaseStream.Position * 100.0 / sr.BaseStream.Length; mainUIDispatcher.Invoke(new DispatcherDelegate(ProgressWindowUpdate)); } } viewer3DWindow.CreateChart3D(verts, csType, caption); } taskProgress = 100.0; mainUIDispatcher.Invoke(new DispatcherDelegate(ProgressWindowUpdate)); sr.Close(); }
static bool TryGetCommonName(string fullName, out CSType result) { return(nativeTypeNameMap.TryGetValue(fullName, out result)); }
public CSDelegateTypeDecl CompileToDelegateDeclaration(FunctionDeclaration func, CSUsingPackages packs, string mangledName, string delegateName, bool objectsAreIntPtrs, CSVisibility vis, bool isSwiftProtocol) { bool returnIsGeneric = func.IsTypeSpecGeneric(func.ReturnTypeSpec); var args = typeMap.MapParameterList(func, func.ParameterLists.Last(), objectsAreIntPtrs, true, null, null); RemapSwiftClosureRepresensation(args); var returnType = returnIsGeneric ? null : typeMap.MapType(func, func.ReturnTypeSpec, objectsAreIntPtrs, true); delegateName = delegateName ?? typeMap.SanitizeIdentifier(func.Name); args.ForEach(a => AddUsingBlock(packs, a.Type)); if (returnType != null && !returnIsGeneric) { AddUsingBlock(packs, returnType); } CSType csReturnType = returnType == null || returnType.IsVoid ? CSSimpleType.Void : returnType.ToCSType(packs); var csParams = new CSParameterList(); for (int i = 0; i < args.Count; i++) { var arg = args [i]; var argIsGeneric = func.IsTypeSpecGeneric(func.ParameterLists.Last() [i].TypeSpec); CSParameter csParam = null; var parmType = func.ParameterLists.Last() [i].TypeSpec; if (arg.Type.Entity == EntityType.Tuple || (!argIsGeneric && IsObjCStruct(parmType))) { csParam = new CSParameter(CSSimpleType.IntPtr, new CSIdentifier(arg.Name), CSParameterKind.None, null); } else { csParam = new CSParameter(arg.Type.ToCSType(packs), new CSIdentifier(arg.Name), arg.Type.IsReference ? CSParameterKind.Ref : CSParameterKind.None, null); } csParams.Add(csParam); } if (isSwiftProtocol) { packs.AddIfNotPresent(typeof(SwiftExistentialContainer1)); csParams.Insert(0, new CSParameter(new CSSimpleType(typeof(SwiftExistentialContainer1)), new CSIdentifier("self"), CSParameterKind.Ref)); } else { csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, new CSIdentifier("self"))); } var retvalName = "xam_retval"; var retvalID = new CSIdentifier(retvalName); if (func.HasThrows || returnIsGeneric || !returnType.IsVoid) // && func.Signature.ReturnType.IsStruct || func.Signature.ReturnType.IsEnum) { { if (func.HasThrows) { csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalName, CSParameterKind.None)); csReturnType = CSSimpleType.Void; } else { if (!returnIsGeneric) { if (!(func.ReturnTypeSpec is ClosureTypeSpec)) { Entity ent = typeMap.GetEntityForTypeSpec(func.ReturnTypeSpec); if (ent == null && !(func.ReturnTypeSpec is ProtocolListTypeSpec)) { throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 8, $"Unable to find entity for class {csReturnType.ToString ()}."); } if (ent != null && (ent.IsStructOrEnum || ent.EntityType == EntityType.Protocol)) { csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalID, CSParameterKind.None)); csReturnType = CSSimpleType.Void; } else if (func.ReturnTypeSpec is ProtocolListTypeSpec pl) { csParams.Insert(0, new CSParameter(new CSSimpleType($"SwiftExistentialContainer{pl.Protocols.Count}"), retvalID, CSParameterKind.Ref)); csReturnType = CSSimpleType.Void; } } } else { csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalID, CSParameterKind.None)); } } } return(new CSDelegateTypeDecl(vis, csReturnType, new CSIdentifier(delegateName), csParams)); }
public List <ICodeElement> MarshalFromLambdaReceiverToCSProp(CSProperty prop, CSType thisType, string csProxyName, CSParameterList delegateParams, FunctionDeclaration funcDecl, CSType methodType, bool isObjC) { bool forProtocol = csProxyName != null; bool needsReturn = funcDecl.IsGetter; bool returnIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.ReturnTypeSpec); var entity = !returnIsGeneric?typeMapper.GetEntityForTypeSpec(funcDecl.ReturnTypeSpec) : null; var entityType = !returnIsGeneric?typeMapper.GetEntityTypeForTypeSpec(funcDecl.ReturnTypeSpec) : EntityType.None; bool returnIsStructOrEnum = needsReturn && entity != null && entity.IsStructOrEnum; bool returnIsClass = needsReturn && entity != null && entity.EntityType == EntityType.Class; bool returnIsProtocol = needsReturn && entity != null && entity.EntityType == EntityType.Protocol; bool returnIsProtocolList = needsReturn && entityType == EntityType.ProtocolList; bool returnIsTuple = needsReturn && entityType == EntityType.Tuple; bool returnIsClosure = needsReturn && entityType == EntityType.Closure; string returnCsProxyName = returnIsProtocol ? NewClassCompiler.CSProxyNameForProtocol(entity.Type.ToFullyQualifiedName(true), typeMapper) : null; if (returnIsProtocol && returnCsProxyName == null) { throw ErrorHelper.CreateError(ReflectorError.kCompilerReferenceBase + 22, $"Unable to find C# interface for protocol {entity.Type.ToFullyQualifiedName ()}"); } var body = new List <ICodeElement> (); if (isObjC) { use.AddIfNotPresent("ObjCRuntime"); } else { use.AddIfNotPresent(typeof(SwiftObjectRegistry)); } CSIdentifier csharpCall = null; if (forProtocol) { csharpCall = new CSIdentifier($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString()}> (self).{prop.Name.Name}"); } else { var call = isObjC ? $"ObjCRuntime.Runtime.GetNSObject<{thisType.ToString ()}> (self).{prop.Name.Name}" : $"SwiftObjectRegistry.Registry.CSObjectForSwiftObject<{thisType.ToString ()}> (self).{prop.Name.Name}"; csharpCall = new CSIdentifier(call); } if (funcDecl.IsGetter) { if (returnIsClass) { if (isObjC) { body.Add(CSReturn.ReturnLine(csharpCall.Dot(new CSIdentifier("Handle")))); } else { body.Add(CSReturn.ReturnLine(csharpCall.Dot(NewClassCompiler.kSwiftObjectGetter))); } } else if (returnIsStructOrEnum || returnIsTuple || returnIsGeneric) { use.AddIfNotPresent(typeof(StructMarshal)); string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); var retvalId = new CSIdentifier(retvalName); body.Add(CSFieldDeclaration.VarLine(methodType, retvalId, csharpCall)); if (returnIsGeneric) { body.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, methodType.Typeof(), retvalId, delegateParams [0].Name)); } else { body.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, retvalId, delegateParams [0].Name)); } } else if (returnIsProtocol) { string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); identifiersUsed.Add(retvalName); var retvalId = new CSIdentifier(retvalName); body.Add(CSFieldDeclaration.VarLine(methodType, retvalId, csharpCall)); var protocolMaker = new CSFunctionCall("SwiftExistentialContainer1", true, new CSFunctionCall("SwiftObjectRegistry.Registry.ExistentialContainerForProtocols", false, retvalId, methodType.Typeof())); body.Add(CSReturn.ReturnLine(protocolMaker)); } else if (returnIsProtocolList) { var protoTypeOf = new List <CSBaseExpression> (); var swiftProtoList = funcDecl.ReturnTypeSpec as ProtocolListTypeSpec; foreach (var swiftProto in swiftProtoList.Protocols.Keys) { protoTypeOf.Add(typeMapper.MapType(funcDecl, swiftProto, false).ToCSType(use).Typeof()); } var callExprs = new List <CSBaseExpression> (); callExprs.Add(csharpCall); callExprs.AddRange(protoTypeOf); var retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); identifiersUsed.Add(retvalName); var retvalId = new CSIdentifier(retvalName); body.Add(CSVariableDeclaration.VarLine(methodType, retvalId, new CSFunctionCall("StructMarshal.ThrowIfNotImplementsAll", false, callExprs.ToArray()))); var containerExprs = new List <CSBaseExpression> (); containerExprs.Add(retvalId); containerExprs.AddRange(protoTypeOf); var returnContainerName = MarshalEngine.Uniqueify("returnContainer", identifiersUsed); identifiersUsed.Add(returnContainerName); var returnContainerId = new CSIdentifier(returnContainerName); body.Add(CSVariableDeclaration.VarLine(CSSimpleType.Var, returnContainerId, new CSFunctionCall("SwiftObjectRegistry.Registry.ExistentialContainerForProtocols", false, containerExprs.ToArray()))); body.Add(CSFunctionCall.FunctionCallLine($"{returnContainerName}.CopyTo", false, new CSUnaryExpression(CSUnaryOperator.Ref, delegateParams [0].Name))); } else { if (returnIsClosure) { body.Add(CSReturn.ReturnLine(MarshalEngine.BuildBlindClosureCall(csharpCall, methodType as CSSimpleType, use))); } else { body.Add(CSReturn.ReturnLine(csharpCall)); } } } else { CSBaseExpression valueExpr = null; bool valueIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.ParameterLists [1] [0].TypeSpec); entity = !valueIsGeneric?typeMapper.GetEntityForTypeSpec(funcDecl.ParameterLists [1] [0].TypeSpec) : null; entityType = !valueIsGeneric?typeMapper.GetEntityTypeForTypeSpec(funcDecl.ParameterLists [1] [0].TypeSpec) : EntityType.None; var isUnusualNewValue = IsUnusualParameter(entity, delegateParams [1]); if (entityType == EntityType.Class || (entity != null && entity.IsObjCProtocol)) { var csParmType = delegateParams [1].CSType as CSSimpleType; if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 42, "Inconceivable! The class type for a method was a CSSimpleType!"); } use.AddIfNotPresent(typeof(SwiftObjectRegistry)); var fullClassName = entity.Type.ToFullyQualifiedName(true); var retrievecall = NewClassCompiler.SafeMarshalClassFromIntPtr(delegateParams [1].Name, csParmType, use, fullClassName, typeMapper, entity.IsObjCProtocol); valueExpr = retrievecall; } else if (entityType == EntityType.Protocol) { use.AddIfNotPresent(typeof(SwiftObjectRegistry)); var retrievecall = new CSFunctionCall($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString ()}> (self).{prop.Name.Name}", false); valueExpr = retrievecall; } else if (entityType == EntityType.Tuple || (entity != null && entity.IsStructOrEnum && !isUnusualNewValue)) { var ntb = typeMapper.MapType(funcDecl, funcDecl.ParameterLists [1] [0].TypeSpec, false); var valType = ntb.ToCSType(use); if (entityType == EntityType.TrivialEnum) { valueExpr = new CSCastExpression(valType, new CSCastExpression(CSSimpleType.Long, delegateParams [1].Name)); } else { var marshalCall = new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [1].Name, valType.Typeof()); valueExpr = new CSCastExpression(valType, marshalCall); } } else if (valueIsGeneric) { // T someVal = (T)StructMarshal.Marshaler.ToNet(parm, typeof(T)); // someVal gets passed in var depthIndex = funcDecl.GetGenericDepthAndIndex(funcDecl.ParameterLists [1] [0].TypeSpec); var genRef = new CSGenericReferenceType(depthIndex.Item1, depthIndex.Item2); use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify(delegateParams [1].Name + "Temp", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(genRef, valMarshalId, new CSCastExpression(genRef, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [1].Name, genRef.Typeof()))); body.Add(valDecl); valueExpr = valMarshalId; } else { if (entityType == EntityType.Closure) { valueExpr = MarshalEngine.BuildWrappedClosureCall(delegateParams [1].Name, methodType as CSSimpleType); } else { valueExpr = delegateParams [1].Name; } } body.Add(CSAssignment.Assign(csharpCall, valueExpr)); } return(body); }
public List <ICodeElement> MarshalFromLambdaReceiverToCSFunc(CSType thisType, string csProxyName, CSParameterList delegateParams, FunctionDeclaration funcDecl, CSType methodType, CSParameterList methodParams, string methodName, bool isObjC) { bool thisIsInterface = csProxyName != null; bool isIndexer = funcDecl.IsSubscript; bool needsReturn = methodType != null && methodType != CSSimpleType.Void; bool isSetter = funcDecl.IsSubscriptSetter; bool returnIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.ReturnTypeSpec); var entity = !returnIsGeneric?typeMapper.GetEntityForTypeSpec(funcDecl.ReturnTypeSpec) : null; var returnEntity = entity; var entityType = !returnIsGeneric?typeMapper.GetEntityTypeForTypeSpec(funcDecl.ReturnTypeSpec) : EntityType.None; bool returnIsStruct = needsReturn && entity != null && entity.IsStructOrEnum; bool returnIsClass = needsReturn && entity != null && entity.EntityType == EntityType.Class; bool returnIsProtocol = needsReturn && ((entity != null && entity.EntityType == EntityType.Protocol) || entityType == EntityType.ProtocolList); bool returnIsTuple = needsReturn && entityType == EntityType.Tuple; bool returnIsClosure = needsReturn && entityType == EntityType.Closure; var callParams = new List <CSBaseExpression> (); var preMarshalCode = new List <CSLine> (); var postMarshalCode = new List <CSLine> (); CSBaseExpression valueExpr = null; bool marshalingThrows = false; if (isSetter) { var valueID = delegateParams [1].Name; valueExpr = valueID; var swiftNewValue = funcDecl.ParameterLists [1] [0]; bool newValueIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.PropertyType); entity = !newValueIsGeneric?typeMapper.GetEntityForTypeSpec(swiftNewValue.TypeSpec) : null; entityType = !newValueIsGeneric?typeMapper.GetEntityTypeForTypeSpec(swiftNewValue.TypeSpec) : EntityType.None; var isUnusualNewValue = IsUnusualParameter(entity, delegateParams [1]); if (entityType == EntityType.Class || entity.IsObjCProtocol) { var csParmType = new CSSimpleType(entity.SharpNamespace + "." + entity.SharpTypeName); if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 26, "Inconceivable! The class type for a subscript was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(SwiftObjectRegistry)); var fullClassName = entity.Type.ToFullyQualifiedName(true); valueExpr = NewClassCompiler.SafeMarshalClassFromIntPtr(valueID, csParmType, use, fullClassName, typeMapper, entity.IsObjCProtocol); } else if (entityType == EntityType.Protocol) { var csParmType = new CSSimpleType(entity.SharpNamespace + "." + entity.SharpTypeName); if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 27, "Inconceivable! The protocol type for a subscript was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(StructMarshal)); use.AddIfNotPresent(typeof(SwiftObjectRegistry)); valueExpr = new CSFunctionCall($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{csParmType.ToString ()}>", false, valueID); } else if ((entityType == EntityType.Struct || entityType == EntityType.Enum) && !isUnusualNewValue) { var csParmType = new CSSimpleType(entity.SharpNamespace + "." + entity.SharpTypeName); if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 28, $"Inconceivable! The {entityType} type for a subscript was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify("val", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); CSLine valDecl = CSVariableDeclaration.VarLine(csParmType, valMarshalId, new CSCastExpression(csParmType, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, valueID, csParmType.Typeof()))); preMarshalCode.Add(valDecl); valueExpr = valMarshalId; } else if (entityType == EntityType.Tuple) { var csParmType = new CSSimpleType(entity.SharpNamespace + "." + entity.SharpTypeName); if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 29, "Inconceivable! The tuple type for a subscript was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify("val", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(csParmType, valMarshalId, new CSCastExpression(csParmType, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, valueID, csParmType.Typeof()))); preMarshalCode.Add(valDecl); valueExpr = valMarshalId; } else if (newValueIsGeneric) { var depthIndex = funcDecl.GetGenericDepthAndIndex(swiftNewValue.TypeSpec); var genRef = new CSGenericReferenceType(depthIndex.Item1, depthIndex.Item2); if (genRef == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 30, "Inconceivable! The generic type for a parameter in a method was NOT a CSGenericReferenceType!"); } use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify("valTemp", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(genRef, valMarshalId, new CSCastExpression(genRef, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, valueID, genRef.Typeof()))); preMarshalCode.Add(valDecl); valueExpr = valMarshalId; } } int j = 0; int k = isSetter ? 1 : 0; for (int i = (funcDecl.HasThrows || returnIsStruct || returnIsProtocol || isSetter || returnIsGeneric) ? 2 : 1; i < delegateParams.Count; i++, j++, k++) { var swiftParm = funcDecl.ParameterLists [1] [k]; bool parmIsGeneric = funcDecl.IsTypeSpecGeneric(swiftParm); entity = !parmIsGeneric?typeMapper.GetEntityForTypeSpec(swiftParm.TypeSpec) : null; entityType = !parmIsGeneric?typeMapper.GetEntityTypeForTypeSpec(swiftParm.TypeSpec) : EntityType.None; var isUnusualParameter = IsUnusualParameter(entity, delegateParams [i]); var csParm = methodParams [j]; if (entityType == EntityType.Class || (entity != null && entity.IsObjCProtocol)) { var csParmType = csParm.CSType as CSSimpleType; if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 31, "Inconceivable! The class type for a method was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(SwiftObjectRegistry)); var fullClassName = entity.Type.ToFullyQualifiedName(true); var retrievecall = NewClassCompiler.SafeMarshalClassFromIntPtr(delegateParams [0].Name, csParmType, use, fullClassName, typeMapper, entity.IsObjCProtocol); if (csParm.ParameterKind == CSParameterKind.Out || csParm.ParameterKind == CSParameterKind.Ref) { string id = MarshalEngine.Uniqueify(delegateParams [i].Name.Name, identifiersUsed); identifiersUsed.Add(id); preMarshalCode.Add(CSFieldDeclaration.FieldLine(csParmType, id, retrievecall)); callParams.Add(new CSIdentifier(String.Format("{0} {1}", csParm.ParameterKind == CSParameterKind.Out ? "out" : "ref", id))); postMarshalCode.Add(CSAssignment.Assign(delegateParams [i].Name, NewClassCompiler.SafeBackingFieldAccessor(new CSIdentifier(id), use, entity.Type.ToFullyQualifiedName(true), typeMapper))); } else { callParams.Add(retrievecall); } } else if (entityType == EntityType.Protocol) { var thePtr = new CSIdentifier(MarshalEngine.Uniqueify("p", identifiersUsed)); var csParmType = csParm.CSType as CSSimpleType; if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 32, "Inconceivable! The protocol type for a method was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(SwiftObjectRegistry)); string csParmProxyType = NewClassCompiler.CSProxyNameForProtocol(entity.Type.ToFullyQualifiedName(true), typeMapper); if (csParmProxyType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 33, $"Unable to find C# interface type for protocol {entity.Type.ToFullyQualifiedName ()}"); } var retrievecall = new CSFunctionCall($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{csParmType.Name}>", false, delegateParams [i].Name); if (csParm.ParameterKind == CSParameterKind.Out || csParm.ParameterKind == CSParameterKind.Ref) { CSIdentifier id = new CSIdentifier(MarshalEngine.Uniqueify(delegateParams [i].Name.Name, identifiersUsed)); identifiersUsed.Add(id.Name); preMarshalCode.Add(CSFieldDeclaration.FieldLine(csParmType, id.Name, retrievecall)); callParams.Add(new CSIdentifier(String.Format("{0} {1}", csParm.ParameterKind == CSParameterKind.Out ? "out" : "ref", id))); postMarshalCode.Add(CSAssignment.Assign(delegateParams [i].Name, new CSFunctionCall("SwiftExistentialContainer1", true, new CSFunctionCall("SwiftObjectRegistry.Registry.ExistentialContainerForProtocol", false, id, csParmType.Typeof())))); } else { callParams.Add(retrievecall); } } else if ((entityType == EntityType.Struct || entityType == EntityType.Enum) && !isUnusualParameter) { var csParmType = csParm.CSType as CSSimpleType; if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 34, $"Inconceivable! The {entityType} type for a method was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(StructMarshal)); use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify(delegateParams [i].Name + "Temp", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(csParmType, valMarshalId, new CSCastExpression(csParmType, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [i].Name, csParmType.Typeof()))); preMarshalCode.Add(valDecl); callParams.Add(valMarshalId); } else if (entityType == EntityType.Tuple) { var csParmType = csParm.CSType as CSSimpleType; if (csParmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 35, "Inconceivable! The tuple type for a parameter in a method was NOT a CSSimpleType!"); } use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify(delegateParams [i].Name + "Temp", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(csParmType, valMarshalId, new CSCastExpression(csParmType, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [i].Name, csParmType.Typeof()))); preMarshalCode.Add(valDecl); callParams.Add(valMarshalId); } else if (entityType == EntityType.Closure) { // parm is a SwiftClosureRepresentation // (FuncType)StructMarshal.Marshaler.MakeDelegateFromBlindClosure (arg, argTypes, returnType); var argTypesId = new CSIdentifier(MarshalEngine.Uniqueify("argTypes" + delegateParams [i], identifiersUsed)); identifiersUsed.Add(argTypesId.Name); var parmType = csParm.CSType as CSSimpleType; if (parmType == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 44, "Inconceivable! The type for a closure should be a CSSimpleType"); } var hasReturn = parmType.GenericTypeName == "Func"; var returnType = hasReturn ? (CSBaseExpression)parmType.GenericTypes [parmType.GenericTypes.Length - 1].Typeof() : CSConstant.Null; var argTypesLength = hasReturn ? parmType.GenericTypes.Length - 1 : parmType.GenericTypes.Length; var argTypes = new CSBaseExpression [argTypesLength]; for (int idx = 0; idx < argTypesLength; idx++) { argTypes [idx] = parmType.GenericTypes [idx].Typeof(); } var typeArr = new CSArray1DInitialized(CSSimpleType.Type, argTypes); var closureExpr = new CSFunctionCall("StructMarshal.Marshaler.MakeDelegateFromBlindClosure", false, delegateParams [i].Name, typeArr, returnType); var castTo = new CSCastExpression(csParm.CSType, closureExpr); callParams.Add(castTo); } else if (entityType == EntityType.ProtocolList) { preMarshalCode.Add(CSFunctionCall.FunctionCallLine("throw new NotImplementedException", false, CSConstant.Val($"Argument {csParm.Name} is a protocol list type and can't be marshaled from a virtual method."))); callParams.Add(CSConstant.Null); marshalingThrows = true; } else if (parmIsGeneric) { // parm is an IntPtr to some T // to get T, we ask funcDecl for the depthIndex of T // T someVal = (T)StructMarshal.Marshaler.ToNet(parm, typeof(T)); // someVal gets passed in var genRef = csParm.CSType as CSGenericReferenceType; if (genRef == null) { throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 36, "Inconceivable! The generic type for a parameter in a method was NOT a CSGenericReferenceType!"); } use.AddIfNotPresent(typeof(StructMarshal)); string valMarshalName = MarshalEngine.Uniqueify(delegateParams [i].Name + "Temp", identifiersUsed); var valMarshalId = new CSIdentifier(valMarshalName); var valDecl = CSVariableDeclaration.VarLine(genRef, valMarshalId, new CSCastExpression(genRef, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [i].Name, genRef.Typeof()))); preMarshalCode.Add(valDecl); callParams.Add(valMarshalId); } else { if (csParm.ParameterKind == CSParameterKind.Out || csParm.ParameterKind == CSParameterKind.Ref) { callParams.Add(new CSIdentifier(String.Format("{0} {1}", csParm.ParameterKind == CSParameterKind.Out ? "out" : "ref", delegateParams [i].Name.Name))); } else { callParams.Add(delegateParams [i].Name); } } } var body = new CSCodeBlock(); if (isObjC) { use.AddIfNotPresent("ObjCRuntime"); } else { use.AddIfNotPresent(typeof(SwiftObjectRegistry)); } CSBaseExpression invoker = null; if (isIndexer) { if (thisIsInterface) { invoker = new CSIndexExpression( $"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString ()}> (self)", false, callParams.ToArray()); } else { var registryCall = isObjC ? $"Runtime.GetNSObject<{thisType.ToString ()}> (self)" : $"SwiftObjectRegistry.Registry.CSObjectForSwiftObject <{thisType.ToString ()}> (self)"; invoker = new CSIndexExpression(registryCall, false, callParams.ToArray()); } } else { if (thisIsInterface) { invoker = new CSFunctionCall( $"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString ()}> (self).{methodName}", false, callParams.ToArray()); } else { var registryCall = isObjC ? $"Runtime.GetNSObject<{thisType.ToString ()}>(self).{methodName}" : $"SwiftObjectRegistry.Registry.CSObjectForSwiftObject <{thisType.ToString ()}> (self).{methodName}"; invoker = new CSFunctionCall(registryCall, false, callParams.ToArray()); } } var tryBlock = funcDecl.HasThrows ? new CSCodeBlock() : null; var catchBlock = funcDecl.HasThrows ? new CSCodeBlock() : null; var altBody = tryBlock ?? body; string catchName = MarshalEngine.Uniqueify("e", identifiersUsed); var catchID = new CSIdentifier(catchName); altBody.AddRange(preMarshalCode); if (marshalingThrows) { return(altBody); } if (funcDecl.HasThrows || needsReturn) // function that returns or getter { if (funcDecl.HasThrows) { use.AddIfNotPresent(typeof(SwiftError)); use.AddIfNotPresent(typeof(Tuple)); use.AddIfNotPresent(typeof(StructMarshal)); CSType returnTuple = null; if (needsReturn) { returnTuple = new CSSimpleType("Tuple", false, methodType, new CSSimpleType(typeof(SwiftError)), CSSimpleType.Bool); } else { returnTuple = new CSSimpleType("Tuple", false, new CSSimpleType(typeof(SwiftError)), CSSimpleType.Bool); } if (needsReturn) { string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); var retvalId = new CSIdentifier(retvalName); altBody.Add(CSFieldDeclaration.VarLine(methodType, retvalId, invoker)); postMarshalCode.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, methodType.Typeof(), retvalId, delegateParams [0].Name)); altBody.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.SetErrorNotThrown", false, delegateParams [0].Name, returnTuple.Typeof())); } else { if (isSetter) { altBody.Add(CSAssignment.Assign(invoker, CSAssignmentOperator.Assign, valueExpr)); } else { altBody.Add(new CSLine(invoker)); } altBody.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.SetErrorNotThrown", false, delegateParams [0].Name, returnTuple.Typeof())); } string swiftError = MarshalEngine.Uniqueify("err", identifiersUsed); var swiftErrorIdentifier = new CSIdentifier(swiftError); catchBlock.Add(CSFieldDeclaration.VarLine(new CSSimpleType(typeof(SwiftError)), swiftErrorIdentifier, new CSFunctionCall("SwiftError.FromException", false, catchID))); catchBlock.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.SetErrorThrown", false, delegateParams [0].Name, swiftErrorIdentifier, returnTuple.Typeof())); } else { if (returnIsClass) { string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); CSIdentifier retvalId = new CSIdentifier(retvalName); altBody.Add(CSFieldDeclaration.VarLine(methodType, retvalId, invoker)); postMarshalCode.Add(CSReturn.ReturnLine( NewClassCompiler.SafeBackingFieldAccessor(retvalId, use, returnEntity.Type.ToFullyQualifiedName(), typeMapper))); } else if (returnIsProtocol) { string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); identifiersUsed.Add(retvalName); var retvalId = new CSIdentifier(retvalName); altBody.Add(CSFieldDeclaration.VarLine(methodType, retvalId, invoker)); var returnContainer = MarshalEngine.Uniqueify("returnContainer", identifiersUsed); identifiersUsed.Add(returnContainer); var returnContainerId = new CSIdentifier(returnContainer); var protoGetter = new CSFunctionCall($"SwiftObjectRegistry.Registry.ExistentialContainerForProtocols", false, retvalId, methodType.Typeof()); var protoDecl = CSVariableDeclaration.VarLine(CSSimpleType.Var, returnContainerId, protoGetter); var marshalBack = CSFunctionCall.FunctionCallLine($"{returnContainer}.CopyTo", delegateParams [0].Name); postMarshalCode.Add(protoDecl); postMarshalCode.Add(marshalBack); } else if (returnIsStruct) { // non-blitable means that the parameter is an IntPtr and we can call the // marshaler to copy into it use.AddIfNotPresent(typeof(StructMarshal)); var marshalCall = CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, invoker, delegateParams [0].Name); altBody.Add(marshalCall); } else if (returnIsTuple) { // non-blitable means that the parameter is an IntPtr and we can call the // marshaler to copy into it use.AddIfNotPresent(typeof(StructMarshal)); var marshalCall = CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, invoker, delegateParams [0].Name); altBody.Add(marshalCall); } else if (returnIsGeneric) { // T retval = invoker(); // if (retval is ISwiftObject) { // Marshal.WriteIntPtr(delegateParams [0].Name, ((ISwiftObject)retval).SwiftObject); // } // else { // StructMarshal.Marshaler.ToSwift(typeof(T), retval, delegateParams[0].Name); // } string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); var retvalId = new CSIdentifier(retvalName); altBody.Add(CSFieldDeclaration.VarLine(methodType, retvalId, invoker)); var ifClause = new CSCodeBlock(); ifClause.Add(CSFunctionCall.FunctionCallLine("Marshal.WriteIntPtr", false, delegateParams [0].Name, new CSParenthesisExpression(new CSCastExpression("ISwiftObject", retvalId)).Dot(NewClassCompiler.kSwiftObjectGetter))); var elseClause = new CSCodeBlock(); elseClause.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false, methodType.Typeof(), retvalId, delegateParams [0].Name)); CSBaseExpression ifExpr = new CSSimpleType("ISwiftObject").Typeof().Dot(new CSFunctionCall("IsAssignableFrom", false, methodType.Typeof())); var retTest = new CSIfElse(ifExpr, ifClause, elseClause); altBody.Add(retTest); } else { if (returnIsClosure) { invoker = MarshalEngine.BuildBlindClosureCall(invoker, methodType as CSSimpleType, use); } if (postMarshalCode.Count > 0) { string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed); CSIdentifier retvalId = new CSIdentifier(retvalName); altBody.Add(CSFieldDeclaration.VarLine(methodType, retvalId, invoker)); postMarshalCode.Add(CSReturn.ReturnLine(retvalId)); } else { altBody.Add(CSReturn.ReturnLine(invoker)); } } } } else // no return or setter { if (isSetter) { altBody.Add(CSAssignment.Assign(invoker, CSAssignmentOperator.Assign, valueExpr)); } else { altBody.Add(new CSLine(invoker)); } } altBody.AddRange(postMarshalCode); if (funcDecl.HasThrows) { body.Add(new CSTryCatch(tryBlock, new CSCatch(typeof(Exception), catchName, catchBlock))); } return(body); }
public static double[] TransForm(double x, double y, CSType fromCSType, CSType toCSType) { ICoordinateSystem fromCS = GetCoordinateSystem(fromCSType); ICoordinateSystem toCS = GetCoordinateSystem(toCSType); string dH = y.ToString().Substring(0, 2); double[] point = new double[2] { y, x }; double[] result = new double[2]; if (y.ToString().Length < 3) { return null; } if (fromCS != null && toCS != null) { PtsToPts(fromCS, toCS, point, out result); } else { return null; } return result; }
private static ICoordinateSystem GetCoordinateSystem(CSType csType) { ICoordinateSystem cs = null; switch (csType) { case CSType.GCS_Xian_1980: cs = CoordinateSystemWktReader.Parse(CSWKT.GCS_Xian_1980) as IGeographicCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_35: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_35) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_36: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_36) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_3_Degree_GK_Zone_37: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_3_Degree_GK_Zone_37) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_GK_Zone_18: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_GK_Zone_18) as IProjectedCoordinateSystem; break; case CSType.Xian_1980_GK_Zone_19: cs = CoordinateSystemWktReader.Parse(CSWKT.Xian_1980_GK_Zone_19) as IProjectedCoordinateSystem; break; case CSType.GCS_Beijing_1954: cs = CoordinateSystemWktReader.Parse(CSWKT.GCS_Beijing_1954) as IGeographicCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_35: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_35) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_36: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_36) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_3_Degree_GK_Zone_37: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_3_Degree_GK_Zone_37) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_GK_Zone_18: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_GK_Zone_18) as IProjectedCoordinateSystem; break; case CSType.Beijing_1954_GK_Zone_19: cs = CoordinateSystemWktReader.Parse(CSWKT.Beijing_1954_GK_Zone_19) as IProjectedCoordinateSystem; break; } return cs; }
/// <summary> /// Read assemblies to list members /// </summary> public void Read() { foreach (ProjectInfo projectInfo in ProjectInfos) { if (!projectInfo.BuildConfigurations.ContainsKey(BuildConfiguration)) { // TODO Logs warn continue; } BuildConfiguration config = projectInfo.BuildConfigurations[BuildConfiguration]; if (string.IsNullOrWhiteSpace(config.OutputPath)) { // TODO Logs warn continue; } // Read assembly Assembly assembly = Assembly.LoadFile(Path.GetFullPath(config.OutputPath)); // Set full path in BuildConfiguration object // Create doc object XmlDoc doc = default; if (!string.IsNullOrWhiteSpace(config.DocumentationFilePath)) { doc = XmlDocDeserializer.Deserialize(config.DocumentationFilePath); } // Create assembly object CSAssembly csAssembly = new CSAssembly(assembly); CSMembers.Add(csAssembly); // Run through all the types foreach (TypeInfo type in assembly.DefinedTypes) { // Get the namespace object from the list of members CSNamespace csNamespace = CSMembers.Namespaces.FirstOrDefault(n => n.Name == type.Namespace); // If the namespace object does not exist, create it if (csNamespace == null) { csNamespace = new CSNamespace(type.Namespace); CSMembers.Add(csNamespace); } // Create type object CSType csType = default; if (type.IsClass) { // TODO Create class object csType = new CSClass(csAssembly, csNamespace, type); } // Create type object if (type.IsInterface) { // TODO Create interface object csType = new CSInterface(csAssembly, csNamespace, type); } // Create type object if (type.IsEnum) { // TODO Create enumeration object csType = new CSEnumeration(csAssembly, csNamespace, type); } // Read doc to get type summary csType.Summary = doc?.Members.FirstOrDefault(m => m.Name == csType.XmlFullName)?.Summary.Value; csAssembly.Types.Add(csType); csNamespace.Types.Add(csType); CSMembers.Add(csType); } } }