public void Generate(GenerationInfo generationInfo, ClassBase implementor) { Method complement = null; /* we are generated by the get Method, if there is one */ if (IsSetter || IsGetter) { if (Modifiers != "new " && ContainerType.GetPropertyRecursively(Name.Substring(3)) != null) { return; } complement = GetComplement(); if (complement != null && IsSetter) { if (Parameters.AccessorReturnType == complement.ReturnType) { return; } _call = string.Format("({0}{1})", IsStatic ? "" : ContainerType.CallByName() + (Parameters.Count > 0 ? ", " : ""), Body.GetCallString(false)); complement = null; IsSetter = false; } /* some setters take more than one arg */ if (complement != null && !complement.IsSetter) { complement = null; } } generationInfo.CurrentMember = Name; GenerateImport(generationInfo.Writer); if (complement != null && _returnValue.CsType == complement.Parameters.AccessorReturnType) { complement.GenerateImport(generationInfo.Writer); } if (IsDeprecated) { generationInfo.Writer.WriteLine("\t\t[Obsolete]"); } generationInfo.Writer.Write("\t\t"); if (Protection != "") { generationInfo.Writer.Write("{0} ", Protection); } GenerateDeclCommon(generationInfo.Writer, implementor); if (IsGetter || IsSetter) { generationInfo.Writer.Write("\t\t\t"); generationInfo.Writer.Write(IsGetter ? "get" : "set"); GenerateBody(generationInfo, implementor, "\t"); } else { GenerateBody(generationInfo, implementor, ""); } if (IsGetter || IsSetter) { if (complement != null && _returnValue.CsType == complement.Parameters.AccessorReturnType) { generationInfo.Writer.WriteLine(); generationInfo.Writer.Write("\t\t\tset"); complement.GenerateBody(generationInfo, implementor, "\t"); } generationInfo.Writer.WriteLine(); generationInfo.Writer.WriteLine("\t\t}"); } else { generationInfo.Writer.WriteLine(); } if (Parameters.HasOptional && !(IsGetter || IsSetter)) { GenerateOverloads(generationInfo.Writer); } generationInfo.Writer.WriteLine(); Statistics.MethodCount++; }
public void Generate(GenerationInfo generationInfo) { var streamWriter = generationInfo.Writer; generationInfo.CurrentMember = CName; GenerateImport(streamWriter); if (IsStatic) { GenerateStatic(generationInfo); } else { streamWriter.WriteLine("\t\t{0} {1}{2} ({3}) {4}", Protection, Safety, _name, Signature, _needsChaining ? ": base (IntPtr.Zero)" : ""); streamWriter.WriteLine("\t\t{"); if (_needsChaining) { streamWriter.WriteLine($"\t\t\tif (GetType () != typeof ({_name})) {{"); if (Parameters.Count == 0) { streamWriter.WriteLine("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);"); streamWriter.WriteLine("\t\t\t\treturn;"); } else { var names = new List <string>(); var values = new List <string>(); foreach (var parameter in Parameters) { if (ContainerType.GetPropertyRecursively(parameter.StudlyName) != null) { names.Add(parameter.Name); values.Add(parameter.Name); } else if (parameter.PropertyName != string.Empty) { names.Add(parameter.PropertyName); values.Add(parameter.Name); } } streamWriter.WriteLine("\t\t\t\tvar vals = new List<GLib.Value> ();"); streamWriter.WriteLine("\t\t\t\tvar names = new List<string> ();"); for (var i = 0; i < names.Count; i++) { var parameter = Parameters[i]; var indent = "\t\t\t\t"; if (parameter.Generatable is ClassBase && !(parameter.Generatable is StructBase)) { streamWriter.WriteLine($"{indent}if ({parameter.Name} != null) {{"); indent += "\t"; } streamWriter.WriteLine($"{indent}names.Add (\"{names[i]}\");"); streamWriter.WriteLine($"{indent}vals.Add (new GLib.Value ({values[i]}));"); if (parameter.Generatable is ClassBase && !(parameter.Generatable is StructBase)) { streamWriter.WriteLine("\t\t\t\t}"); } } streamWriter.WriteLine("\t\t\t\tCreateNativeObject (names.ToArray (), vals.ToArray ());"); streamWriter.WriteLine("\t\t\t\treturn;"); } streamWriter.WriteLine("\t\t\t}"); } Body.Initialize(generationInfo, false, false, ""); if (ContainerType is ObjectGen) { streamWriter.WriteLine("\t\t\towned = true;"); } streamWriter.WriteLine("\t\t\t{0} = {1}({2});", ContainerType.AssignToName, CName, Body.GetCallString(false)); Body.Finish(streamWriter, ""); Body.HandleException(streamWriter, ""); } streamWriter.WriteLine("\t\t}"); streamWriter.WriteLine(); Statistics.CtorCount++; }