/// <summary> /// Creates the options for the specified generator mode. /// </summary> /// <param name="generatorMode">The generator mode.</param> /// <returns>MethodGeneratorOptions.</returns> /// <autogeneratedoc /> public static MethodGeneratorOptions Create(GeneratorMode generatorMode) { var m = matrix[generatorMode]; return(new MethodGeneratorOptions { Access = m[0], Modifiers = m[1], ReturnType = m[2], Name = m[3], Parameter = ParameterGeneratorOptions.Create(generatorMode) }); }
/// <summary> /// Generates code for the specified parameter information. /// </summary> /// <param name="parameterInfo">The parameter information.</param> /// <param name="options">The generator options.</param> /// <returns>System.String.</returns> public string Generate(ParameterInfo parameterInfo, ParameterGeneratorOptions options) { // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#method-parameters var sb = new StringBuilder(); //Attributes? // parameterInfo.IsIn; // parameterInfo.IsOut; // parameterInfo.IsRetval; // parameterInfo.IsLcid; // parameterInfo.HasDefaultValue; //TODO parameterInfo.DefaultValue; // parameterInfo.RawDefaultValue; // parameterInfo.IsOptional; var isThis = parameterInfo.Position == 0 && parameterInfo.Member.CustomAttributes.Any(a => a.AttributeType == typeof(ExtensionAttribute)); var isParams = parameterInfo.CustomAttributes.Any(a => a.AttributeType == typeof(ParamArrayAttribute)); var type = Generator.Generate(parameterInfo.ParameterType) + " "; var modifier = ""; if (type.StartsWith("ref ")) // (parameterInfo.ParameterType.IsByRef) { modifier = "ref "; type = type.Substring(4); } if (isThis) { modifier = "this "; } else if (parameterInfo.IsOut) { modifier = "out "; } else if (isParams) { modifier = "params "; } // "params" and "this" are relevant only for declare and compare switch (GeneratorMode) { case GeneratorMode.Compare: case GeneratorMode.CompareIgnoreReturnType: case GeneratorMode.Declare: break; default: if (isParams || isThis) { modifier = ""; } break; } if (options.Modifiers) { sb.Append(modifier); } if (options.Type) { sb.Append(type); } if (options.Name) { sb.Append(parameterInfo.Name); } //TODO default value return(sb.ToString().Trim()); }
/// <summary> /// Generates code for the specified parameter information. /// </summary> /// <param name="parameterInfo">The parameter information.</param> /// <returns>System.String.</returns> public string Generate(ParameterInfo parameterInfo) => Generate(parameterInfo, ParameterGeneratorOptions.Create(GeneratorMode));