/// <summary> /// Make minor fixes after the implementation phase. /// </summary> public void FixUp(DexTargetPackage targetPackage) { var iMethod = method.GetBaseInterfaceMethod(); Mono.Cecil.TypeReference inheritedReturnType = null; //var iMethod = method.Overrides.Select(x => x.Resolve()).Where(x => x != null).FirstOrDefault(x => x.DeclaringType.IsInterface); if (iMethod != null) { inheritedReturnType = iMethod.ReturnType; } var baseMethod = method.GetBaseMethod(); if (baseMethod != null) { inheritedReturnType = baseMethod.ReturnType; } if (inheritedReturnType != null) { var inheritedTargetReturnType = inheritedReturnType.GetReference(targetPackage, compiler.Module); if (inheritedTargetReturnType.Descriptor != dmethod.Prototype.ReturnType.Descriptor) { dmethod.Prototype.Unfreeze(); dmethod.Prototype.ReturnType = inheritedTargetReturnType; dmethod.Prototype.Freeze(); //// update the original method's return type as well, //// to make sure the code generation later knows what it is handling. //// TODO: this seems to be a hack. shouldn't this have been handled //// during the IL-conversion phase? xMethod.SetInheritedReturnType(inheritedReturnType); } } }
/// <summary> /// Implement make minor fixes after the implementation phase. /// </summary> public void FixUp(DexTargetPackage targetPackage) { var iMethod = method.GetBaseInterfaceMethod(); //var iMethod = method.Overrides.Select(x => x.Resolve()).Where(x => x != null).FirstOrDefault(x => x.DeclaringType.IsInterface); if (iMethod != null) { dmethod.Prototype.ReturnType = iMethod.ReturnType.GetReference(targetPackage, compiler.Module); } var baseMethod = method.GetBaseMethod(); if (baseMethod != null) { dmethod.Prototype.ReturnType = baseMethod.ReturnType.GetReference(targetPackage, compiler.Module); } }
/// <summary> /// Does the given method require a bridge method? /// </summary> private static bool NeedsBridge(MethodDefinition method, out MethodDefinition baseMethod) { baseMethod = null; if (method.IsStatic || !method.IsVirtual) return false; baseMethod = method.GetBaseMethod(); if ((baseMethod == null) || (!baseMethod.ContainsGenericParameter)) return false; var paramCount = method.Parameters.Count; for (var i = 0; i < paramCount; i++) { var baseP = baseMethod.Parameters[i]; if (!baseP.ParameterType.ContainsGenericParameter) continue; var p = method.Parameters[i]; if (!p.ParameterType.ContainsGenericParameter) return true; } return false; }
private bool IsSerializedParameter(MethodDefinition method, ParameterReference @ref) { var paramDef = @ref.Resolve(); if (paramDef == null) { return(false); } if (paramDef.IsSerializedParameter.HasValue) { return(paramDef.IsSerializedParameter.Value); } bool isSerialized = paramDef.HasSerializedParameterAttribute(); if (!isSerialized) { // check inheritance var baseMethod = method.GetBaseMethod(); if (baseMethod != null) { isSerialized = IsSerializedParameter(baseMethod, baseMethod.Parameters[@ref.Index]); } } if (!isSerialized) { // check interfaces. isSerialized = method.GetBaseInterfaceMethods() .Any(im => IsSerializedParameter(im, im.Parameters[@ref.Index])); } paramDef.IsSerializedParameter = isSerialized; return(isSerialized); }