private void CreateMethod(Type aType, Classifier aCls, MethodBase aMethod, PdOOM.BasePackage aPckg, Operation anOper, InfluenceTable anInfTable) { Operation operation; if (anOper != null) { operation = anOper; } else { operation = (Operation) aCls.CreateObject(0x18112066, "", -1, true); } operation.Static = aMethod.IsStatic; operation.Visibility = GetMethodVisibility(aMethod); operation.Final = aMethod.IsFinal; if (aMethod.IsGenericMethod) { operation.Generic = true; foreach (TypeParameter parameter in operation.TypeParameters) { parameter.delete(); } foreach (Type type in aMethod.GetGenericArguments()) { TypeParameter parameter2 = (TypeParameter) operation.CreateObject(0x1811207d, "", -1, true); this.ProcessType(type, false); TypeMapping mapping = TypeMapping.Retrieve(type); parameter2.Name = parameter2.Code = mapping.Name; operation.TypeParameters.Add(parameter2); } } if (aMethod.IsVirtual) { if (LZ.Reverse.Info._bVBNet) { operation.SetExtendedAttribute("VB.NET.Overridable", "true"); } else { operation.SetExtendedAttribute("C#.virtual", "true"); } } if (aMethod.IsAbstract) { operation.Abstract = true; } new CustomHandlerMethod(aMethod, operation).Convert(); if (anOper == null) { foreach (ParameterInfo info in aMethod.GetParameters()) { this.AddParameter(operation, info, aPckg); } } bool flag = aMethod.IsConstructor || aMethod.GetType().IsSubclassOf(typeof(ConstructorInfo)); if (!flag) { MethodInfo info2 = (MethodInfo) aMethod; Type returnType = info2.ReturnType; if (returnType.IsArray) { operation.Array = true; returnType = returnType.GetElementType(); } this.ProcessType(returnType, false); TypeMapping mapping2 = TypeMapping.Retrieve(returnType); if (mapping2.HasClassifier()) { PdOOM.BaseObject obj2 = ProperRef.Link(NamespaceMapping.Retrieve(aPckg), mapping2); operation.UseQualifiedDataType = false; operation.ReturnTypeObject = obj2; } else { operation.ReturnType = mapping2.Name; } if ((anInfTable != null) && anInfTable.Contains(info2)) { anInfTable.Impact(info2, operation); } if (LZ.Reverse.Info._bVBNet) { new CustomHandlerReturn(info2, anOper).Convert(); } bool flag2 = false; if (!info2.IsHideBySig && info2.GetBaseDefinition().Equals(info2)) { string name = info2.Name; if (!aType.BaseType.Equals(aType)) { BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; bool flag3 = false; foreach (MethodInfo info3 in aType.GetMethods(bindingAttr)) { if (info3.Name == name) { flag3 = true; break; } } if (flag3) { flag2 = true; } } } if (info2.GetBaseDefinition().Equals(info2)) { if (flag2) { if (LZ.Reverse.Info._bVBNet) { operation.SetExtendedAttribute("VB.NET.Shadowing", "Shadows"); } else { operation.SetExtendedAttribute("C#.new", "true"); } } else if (aMethod.IsHideBySig && LZ.Reverse.Info._bVBNet) { operation.SetExtendedAttribute("VB.NET.Shadowing", "Overloads"); } } else if (LZ.Reverse.Info._bVBNet) { operation.SetExtendedAttribute("VB.NET.Overrides", "true"); } else { operation.SetExtendedAttribute("C#.override", "true"); } } if (flag) { operation.Stereotype = "Constructor"; operation.ReturnType = ""; operation.InfluentObject = aCls; operation.Automatic = true; try { if (LZ.Reverse.Info._bVBNet) { operation.Name = operation.Code = "New"; } else { operation.Name = operation.Code = TypeInfoHelper.GetTypeName(aType); } return; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.FullName, aMethod.Name }); } return; } } if (anOper == null) { string aName = aMethod.Name; if (!LZ.Reverse.Info._bVBNet && ShortenOperator(aMethod.GetParameters().Length, ref aName)) { operation.Stereotype = "Operator"; } try { operation.Name = operation.Code = aName; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.FullName, aMethod.Name }); } } } }
private void CreateEvent(Type aType, Classifier aCls, EventInfo anEvent, PdOOM.BasePackage aPckg, ref AttributeTable aAttrTable, ref MethodTable aMthTable, ref InfluenceTable aInfTable) { if (!LZ.Reverse.Info._bVBNet) { bool flag; bool flag2; if (aType.GetField(anEvent.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null) { flag = false; flag2 = false; } else { flag = true; flag2 = true; } if (flag) { PdOOM.Attribute anObject = (PdOOM.Attribute) aCls.CreateObject(0x18112065, "", -1, true); anObject.Stereotype = "Event"; try { anObject.Name = anObject.Code = anEvent.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the event \"{1}\" on the type \"{0}\"", aType.FullName, anEvent.Name }); } } Type eventHandlerType = anEvent.EventHandlerType; this.ProcessType(eventHandlerType, false); TypeMapping mapping = TypeMapping.Retrieve(eventHandlerType); anObject.DataType = mapping.Name; if (!mapping.Delegate && LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** invalid delegate mapping for \"{0}\"", eventHandlerType.FullName }); } MethodInfo addMethod = anEvent.GetAddMethod(true); anObject.Visibility = GetMethodVisibility(addMethod); if (flag2) { aInfTable.Add(addMethod, anObject, "EventAdd"); addMethod = anEvent.GetRemoveMethod(true); aInfTable.Add(addMethod, anObject, "EventRemove"); } } if (!flag2) { MethodInfo aMethod = anEvent.GetAddMethod(true); aMthTable.Add(aMethod); aMethod = anEvent.GetRemoveMethod(true); aMthTable.Add(aMethod); } } }
private void CreateAttribute(TypeInfo ti, Classifier aCls, AttributeInfo aField, PdOOM.BasePackage aPckg) { CustomHandlerField field = new CustomHandlerField(aField, null); if (!field.ThroughProperty) { PdOOM.Attribute attribute = (PdOOM.Attribute)aCls.CreateObject(0x18112065, "", -1, true); if (aField.IsStatic) { attribute.Static = true; } try { attribute.Name = attribute.Code = aField.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the attribute \"{1}\" on the type \"{0}\"", aField.Code, aField.Name }); } } attribute.Visibility = GetTypeVisibility(aField.Modifier); //attribute.Persistent = !aField.IsNotSerialized; field.PdObj = attribute; field.Convert(); ////Type fieldType = aField.FieldType; ////if (fieldType.IsArray) ////{ //// attribute.Multiplicity = "*"; //// fieldType = fieldType.GetElementType(); ////} ////if (fieldType.IsGenericType && !fieldType.IsGenericTypeDefinition) ////{ //// fieldType = fieldType.GetGenericTypeDefinition(); ////} ////this.ProcessType(fieldType, false); ////TypeMapping mapping = TypeMapping.Retrieve(fieldType); ////if (mapping.HasClassifier()) ////{ //// PdOOM.BaseObject obj2 = ProperRef.Link(NamespaceMapping.Retrieve(aPckg), mapping); //// attribute.UseQualifiedDataType = false; //// attribute.DataTypeObject = obj2; ////} ////else { attribute.DataType = ti.Code; // mapping.Name; } } }
private void CreateProperty(Type aType, Classifier aCls, PropertyInfo aProperty, PdOOM.BasePackage aPckg, ref MethodTable aTable) { bool flag = aProperty.GetIndexParameters().GetLength(0) != 0; PdOOM.Attribute anAttr = (PdOOM.Attribute) aCls.CreateObject(0x18112065, "", -1, true); if (aProperty.CanRead) { if (aProperty.CanWrite) { anAttr.Frozen = "C"; } else { anAttr.Frozen = "R"; } } else { anAttr.Frozen = "A"; } anAttr.Stereotype = LZ.Reverse.Info._bVBNet ? "Property" : (flag ? "Indexer" : "Property"); Operation anOper = null; Operation operation2 = null; foreach (PdOOM.BaseObject obj2 in anAttr.DependentObjects) { if (obj2.ClassKind == 0x18112065) { obj2.delete(); } else if (obj2.ClassKind == 0x18112066) { Operation operation3 = (Operation) obj2; if (operation3.Stereotype == "Setter") { operation2 = operation3; continue; } if (operation3.Stereotype == "Getter") { anOper = operation3; } } } if (aProperty.CanRead) { anAttr.Visibility = GetMethodVisibility(aProperty.GetGetMethod(true)); } else if (aProperty.CanWrite) { anAttr.Visibility = GetMethodVisibility(aProperty.GetSetMethod(true)); } else { anAttr.Visibility = "-"; } Type propertyType = aProperty.PropertyType; if (propertyType.IsArray) { anAttr.Multiplicity = "*"; propertyType = propertyType.GetElementType(); } this.ProcessType(propertyType, false); TypeMapping mapping = TypeMapping.Retrieve(propertyType); if (mapping.HasClassifier()) { PdOOM.BaseObject obj3 = ProperRef.Link(NamespaceMapping.Retrieve(aPckg), mapping); anAttr.UseQualifiedDataType = false; anAttr.DataTypeObject = obj3; } else { anAttr.DataType = mapping.Name; } try { anAttr.Name = anAttr.Code = aProperty.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the property \"{1}\" on the type \"{0}\"", aType.FullName, aProperty.Name }); } } if (aProperty.CanRead) { if (anOper != null) { MethodInfo getMethod = aProperty.GetGetMethod(true); aTable.Add(getMethod); this.CreateMethod(aType, aCls, getMethod, aPckg, anOper, null); } else if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception around the setter for the property \"{1}\" on the type \"{0}\"", aType.FullName, aProperty.Name }); } } if (aProperty.CanWrite) { if (operation2 != null) { MethodInfo setMethod = aProperty.GetSetMethod(true); aTable.Add(setMethod); this.CreateMethod(aType, aCls, setMethod, aPckg, operation2, null); } else if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception around the setter for the property \"{1}\" on the type \"{0}\"", aType.FullName, aProperty.Name }); } } CustomHandlerProperty property = new CustomHandlerProperty(aProperty, anAttr); property.Convert(); if (LZ.Reverse.Info._bVBNet && property.Default) { anAttr.SetExtendedAttribute("VB.NET.Default", "true"); } bool flag2 = false; if (LZ.Reverse.Info._bVBNet) { bool flag3 = false; if (aProperty.CanRead && aProperty.GetGetMethod(true).IsHideBySig) { flag3 = true; } else if (aProperty.CanWrite && aProperty.GetSetMethod(true).IsHideBySig) { flag3 = true; } if (flag3 && !flag2) { anAttr.SetExtendedAttribute("VB.NET.Shadowing", "Overloads"); } } }
private void CreateMethod(TypeInfo aType, Classifier aCls, MethordInfo aMethod, PdOOM.BasePackage aPckg, Operation anOper, InfluenceTable anInfTable) { Operation operation; if (anOper != null) { operation = anOper; } else { operation = (Operation)aCls.CreateObject(0x18112066, "", -1, true); } operation.Static = aMethod.IsStatic; operation.Visibility = GetTypeVisibility(aMethod.Modifier); operation.ReturnType = aMethod.Type; //operation.Final = aMethod.IsFinal; if (aMethod.IsGenericMethod) { operation.Generic = true; foreach (TypeParameter parameter in operation.TypeParameters) { parameter.delete(); } ////foreach (Type type in aMethod.GetGenericArguments()) ////{ //// TypeParameter parameter2 = (TypeParameter)operation.CreateObject(0x1811207d, "", -1, true); //// this.ProcessType(type, false); //// TypeMapping mapping = TypeMapping.Retrieve(type); //// parameter2.Name = parameter2.Code = mapping.Name; //// operation.TypeParameters.Add(parameter2); ////} } if (aMethod.IsVirtual) { operation.SetExtendedAttribute("C++.virtual", "true"); } if (aMethod.IsAbstract) { operation.Abstract = true; } try { operation.Code = aMethod.Code; operation.Name = aMethod.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.Code, aMethod.Name }); } } new CustomHandlerMethod(aMethod, operation).Convert(); // 添加参数 foreach (ObjectInfo type in aMethod.Parameters) { AddParameter(operation, type, aPckg); } // 防止有重载方法前面改名失败 if (aMethod.Parameters.Count > 0 && operation.Code != aMethod.Code) { try { operation.Code = aMethod.Code; operation.Name = aMethod.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the operation \"{1}\" on the type \"{0}\"", aType.Code, aMethod.Name }); } } } }
private void CreateAttribute(TypeInfo ti, Classifier aCls, AttributeInfo aField, PdOOM.BasePackage aPckg) { CustomHandlerField field = new CustomHandlerField(aField, null); if (!field.ThroughProperty) { PdOOM.Attribute attribute = (PdOOM.Attribute)aCls.CreateObject(0x18112065, "", -1, true); if (aField.IsStatic) { attribute.Static = true; } try { attribute.Name = attribute.Code = aField.Name; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the attribute \"{1}\" on the type \"{0}\"", aField.Code, aField.Name }); } } attribute.Visibility = GetTypeVisibility(aField.Modifier); //attribute.Persistent = !aField.IsNotSerialized; attribute.Volatile = aField.IsVolatile; if (aField.IsPointer) { attribute.Multiplicity = "*"; } field.PdObj = attribute; field.Convert(); TypeInfo tiField = new TypeInfo(); ////System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[a-zA-Z_][a-zA-Z_0-9]*"); ////System.Text.RegularExpressions.Match m = reg.Match(aField.Type.Replace("unsigned","")); tiField.Code = tiField.Name = aField.Type; tiField.IsClass = true; tiField.Comment = aCls.Comment; this.AddClassifier(tiField, false); bool bCreate = true; TypeMapping mapping = TypeMapping.Retrieve(tiField, ref bCreate); if (mapping.HasClassifier()) { PdOOM.NamedObject objClassB = (PdOOM.NamedObject)ProperRef.Link(NamespaceMapping.Retrieve(aPckg), mapping); PdOOM.NamedObject objClassA = (PdOOM.NamedObject)attribute.Parent; attribute.UseQualifiedDataType = false; attribute.DataTypeObject = objClassA; Association ass = (Association)aPckg.CreateObject((int)PdOOM_Classes.cls_Association, "", -1, true); ass.ClassA = objClassA; ass.ClassB = objClassB; try { ass.Name = ass.Code = string.Format("ass_{0}_2_{1}_{2}", objClassA.Code, objClassB.Code, attribute.Code); if (tiField.Code == aField.FullType) { ass.RoleBMultiplicity = "1..1"; ass.RoleAIndicator = aField.IsPointer ? "A" : "C"; } ass.RoleAMultiplicity = ""; ass.RoleBName = aField.Name; ass.RoleANavigability = false; ass.RoleBNavigability = false; } catch (COMException) { if (LZ.Reverse.Info._bDebug) { LZ.Reverse.Info.Write(new string[] { "*** exception while naming the attribute \"{1}\" on the type \"{0}\"", aField.Code, aField.Name }); } } } ////else { attribute.DataType = aField.FullType; // mapping.Name; } } }