public void FixupMethodOverrides() { foreach (Method m in methods.Where(m => !m.IsInterfaceDefaultMethod)) { for (var bt = this.GetBaseGen(); bt != null; bt = bt.GetBaseGen()) { var bm = bt.Methods.FirstOrDefault(mm => mm.Name == m.Name && mm.Visibility == m.Visibility && ParameterList.Equals(mm.Parameters, m.Parameters)); if (bm != null && bm.RetVal.FullName == m.RetVal.FullName) // if return type is different, it could be still "new", not "override". { m.IsOverride = true; break; } } } // Interface default methods can be overriden. We want to process them differently. foreach (Method m in methods.Where(m => m.IsInterfaceDefaultMethod)) { foreach (var bt in this.GetAllDerivedInterfaces()) { var bm = bt.Methods.FirstOrDefault(mm => mm.Name == m.Name && ParameterList.Equals(mm.Parameters, m.Parameters)); if (bm != null) { m.IsInterfaceDefaultMethodOverride = true; break; } } } foreach (Method m in methods) { if (m.Name == Name || ContainsProperty(m.Name, true) || HasNestedType(m.Name)) { m.Name = "Invoke" + m.Name; } if ((m.Name == "ToString" && m.Parameters.Count == 0) || (BaseGen != null && BaseGen.ContainsMethod(m, true))) { m.IsOverride = true; } } foreach (var nt in NestedTypes) { nt.FixupMethodOverrides(); } }
public void FixupMethodOverrides(CodeGenerationOptions opt) { foreach (var m in Methods.Where(m => !m.IsStatic && !m.IsInterfaceDefaultMethod)) { for (var bt = GetBaseGen(opt); bt != null; bt = bt.GetBaseGen(opt)) { var bm = bt.Methods.FirstOrDefault(mm => mm.Name == m.Name && mm.Visibility == m.Visibility && ParameterList.Equals(mm.Parameters, m.Parameters)); if (bm != null && bm.RetVal.FullName == m.RetVal.FullName) // if return type is different, it could be still "new", not "override". { m.IsOverride = true; break; } } } // Interface default methods can be overriden. We want to process them differently. var checkDimOverrideTargets = opt.SupportDefaultInterfaceMethods ? Methods : Methods.Where(m => m.IsInterfaceDefaultMethod); // We need to check all the implemented interfaces of all the base types. var allIfaces = new List <InterfaceGen> (); for (var gen = this; gen != null; gen = gen.BaseGen) { gen.GetAllDerivedInterfaces(allIfaces); } foreach (var m in checkDimOverrideTargets.Where(m => !m.IsStatic)) { foreach (var bt in allIfaces.Distinct()) { // We mark a method as an override if (1) it is a DIM, or (2) if the base method is DIM // (i.e. we don't mark as override if a class method "implements" normal iface method.) var bm = bt.Methods.FirstOrDefault(mm => (m.IsInterfaceDefaultMethod || !mm.IsAbstract) && mm.Name == m.Name && ParameterList.Equals(mm.Parameters, m.Parameters)); if (bm != null) { m.OverriddenInterfaceMethod = bm; break; } } } foreach (var m in Methods) { if (m.Name == Name || ContainsProperty(m.Name, true) || HasNestedType(m.Name)) { m.Name = "Invoke" + m.Name; } if ((m.Name == "ToString" && m.Parameters.Count == 0) || (BaseGen != null && BaseGen.ContainsMethod(m, true))) { m.IsOverride = true; } } foreach (var nt in NestedTypes) { nt.FixupMethodOverrides(opt); } }