static string GenerateProtoMessage(Type type) { string nestedMessages = string.Join(Environment.NewLine, type.GetNestedTypes().Select(nestedType => GenerateProtoMessage(nestedType))); FieldGenerator gen = new FieldGenerator(); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(SoulsFormats.HKX.HKArray <>)) { } IEnumerable <FieldInfo> fields = type.GetFields(/*BindingFlags.NonPublic |*/ BindingFlags.Public | BindingFlags.Instance).Where(field => !field.Name.Contains("__BackingField")); IEnumerable <PropertyInfo> properties = type.GetProperties(/*BindingFlags.NonPublic |*/ BindingFlags.Public | BindingFlags.Instance); string fieldString = string.Join(Environment.NewLine, fields.Where(field => !field.IsStatic).Select(field => GenerateProtoField(type, gen, field)).Concat(properties /*.Where(prop=>prop.GetMethod.IsPublic)*/.Select(prop => GenerateProtoProp(type, gen, prop)))); const string protoMessageFormat = @" message {0} {{ {1} {2} }}"; return(string.Format(protoMessageFormat, GenerateProtoTypeName(type, type), nestedMessages, fieldString)); }
static string GenerateProtoField(Type type, FieldGenerator gen, FieldInfo field) { return(GenerateProtoField(type, gen, field.FieldType, field.Name)); }
private static string GenerateProtoProp(Type type, FieldGenerator gen, PropertyInfo prop) { return(GenerateProtoField(type, gen, prop.PropertyType, prop.Name)); }
static string GenerateProtoField(Type message, FieldGenerator gen, Type type, string name) { var field = gen.GenerateField(type, name); return(string.Format("{0} {1} = {2};", GenerateProtoTypeName(message, field.type), field.name, field.id)); }