private void GenerateColumnAddMethods(IndentedTextWriter writer, Type inputType, ComponentCatalog catalog, string className, out Type columnType) { columnType = null; foreach (var fieldInfo in inputType.GetFields()) { var inputAttr = fieldInfo.GetCustomAttributes(typeof(ArgumentAttribute), false).FirstOrDefault() as ArgumentAttribute; if (inputAttr == null || inputAttr.Visibility == ArgumentAttribute.VisibilityType.CmdLineOnly) { continue; } var type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(fieldInfo.FieldType); var isArray = type.IsArray; if (isArray) { type = type.GetElementType(); } if (type == typeof(JArray) || type == typeof(JObject)) { continue; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Var <>)) { continue; } var typeEnum = TlcModule.GetDataType(type); if (typeEnum != TlcModule.DataKind.Unknown) { continue; } if (type.IsSubclassOf(typeof(OneToOneColumn))) { columnType = GenerateOneToOneColumn(writer, className, columnType, fieldInfo, inputAttr, type, isArray); } else if (type.IsSubclassOf(typeof(ManyToOneColumn))) { columnType = GenerateManyToOneColumn(writer, className, columnType, fieldInfo, inputAttr, type, isArray); } } }
private void GenerateClasses(IndentedTextWriter writer, Type inputType, ComponentCatalog catalog, string currentNamespace) { foreach (var fieldInfo in inputType.GetFields()) { var inputAttr = fieldInfo.GetCustomAttributes(typeof(ArgumentAttribute), false).FirstOrDefault() as ArgumentAttribute; if (inputAttr == null || inputAttr.Visibility == ArgumentAttribute.VisibilityType.CmdLineOnly) { continue; } var type = fieldInfo.FieldType; type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(type); if (type.IsArray) { type = type.GetElementType(); } if (type == typeof(JArray) || type == typeof(JObject)) { continue; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Var <>)) { continue; } if (type == typeof(CommonInputs.IEvaluatorInput)) { continue; } if (type == typeof(CommonOutputs.IEvaluatorOutput)) { continue; } var typeEnum = TlcModule.GetDataType(type); if (typeEnum != TlcModule.DataKind.Unknown) { continue; } if (_generatedClasses.IsGenerated(type.FullName)) { continue; } GenerateEnums(writer, type, currentNamespace); GenerateClasses(writer, type, catalog, currentNamespace); var apiName = _generatedClasses.GetApiName(type, currentNamespace); string classBase = ""; if (type.IsSubclassOf(typeof(OneToOneColumn))) { classBase = $" : OneToOneColumn<{apiName}>, IOneToOneColumn"; } else if (type.IsSubclassOf(typeof(ManyToOneColumn))) { classBase = $" : ManyToOneColumn<{apiName}>, IManyToOneColumn"; } writer.WriteLine("[Obsolete]"); writer.WriteLine($"public sealed partial class {apiName}{classBase}"); writer.WriteLine("{"); writer.Indent(); _generatedClasses.MarkAsGenerated(type.FullName); GenerateInputFields(writer, type, catalog, currentNamespace); writer.Outdent(); writer.WriteLine("}"); writer.WriteLineNoTabs(); } }
private void GenerateEnums(IndentedTextWriter writer, Type inputType, string currentNamespace) { foreach (var fieldInfo in inputType.GetFields()) { var inputAttr = fieldInfo.GetCustomAttributes(typeof(ArgumentAttribute), false).FirstOrDefault() as ArgumentAttribute; if (inputAttr == null || inputAttr.Visibility == ArgumentAttribute.VisibilityType.CmdLineOnly) { continue; } var type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(fieldInfo.FieldType); if (_generatedClasses.IsGenerated(type.FullName)) { continue; } if (!type.IsEnum) { var typeEnum = TlcModule.GetDataType(type); if (typeEnum == TlcModule.DataKind.Unknown) { GenerateEnums(writer, type, currentNamespace); } continue; } var enumType = Enum.GetUnderlyingType(type); writer.WriteLine("[Obsolete]"); var apiName = _generatedClasses.GetApiName(type, currentNamespace); if (enumType == typeof(int)) { writer.WriteLine($"public enum {apiName}"); } else { Contracts.Assert(enumType == typeof(byte)); writer.WriteLine($"public enum {apiName} : byte"); } _generatedClasses.MarkAsGenerated(type.FullName); writer.WriteLine("{"); writer.Indent(); var names = Enum.GetNames(type); var values = Enum.GetValues(type); var lines = new List <string>(); for (int i = 0; i < names.Length; i++) { var name = names[i]; if (type.GetField(name).GetCustomAttribute <HideEnumValueAttribute>() != null) { continue; } var value = values.GetValue(i); if (enumType == typeof(int)) { lines.Add($"{name} = {(int)value}"); } else { Contracts.Assert(enumType == typeof(byte)); lines.Add($"{name} = {(byte)value}"); } } for (int i = 0; i < lines.Count - 1; i++) { writer.WriteLine($"{lines[i]},"); } writer.WriteLine($"{lines[lines.Count-1]}"); writer.Outdent(); writer.WriteLine("}"); writer.WriteLineNoTabs(); } }