private static Profile CreateBlankProfile(string name, Version version, ProfileConverterOptions opts) { return(new Profile { Name = name, Version = version?.ToString(2), TypeMaps = opts.TypeMaps ?? new List <Dictionary <string, string> >(), // NRE ClassName = opts.Prefix.ToUpper().CheckMemberName(opts.Prefix) }); }
public static IEnumerable <Profile> ReadProfiles (IReader reader, IConstructor ctor, Stream input, ProfileConverterOptions opts) { var obj = reader.Load(input); Console.WriteLine("Reading enums..."); var enums = reader.ReadEnums(obj, opts).OrderBy(x => x.Name).ToArray(); Console.WriteLine("Reading functions..."); var functions = reader.ReadFunctions(obj, opts).OrderBy(x => x.Name).ToArray(); Console.WriteLine("Reading structs..."); var structs = reader.ReadStructs(obj, opts).OrderBy(x => x.Name).ToArray(); Console.WriteLine("Reading constants..."); var constants = reader.ReadConstants(obj, opts).OrderBy(x => x.Name).ToArray(); Console.WriteLine("Creating profiles..."); var profiles = enums.Select(x => (x.ProfileName, x.ProfileVersion)) .Concat(functions.Select(x => (x.ProfileName, x.ProfileVersion))) .Concat(structs.Select(x => (x.ProfileName, x.ProfileVersion))) .Distinct() .Select(x => CreateBlankProfile(x.ProfileName, x.ProfileVersion, opts)); foreach (var profile in profiles) { ctor.WriteEnums(profile, enums, opts); ctor.WriteFunctions(profile, functions, opts); ctor.WriteStructs(profile, structs, opts); ctor.WriteConstants(profile, constants, opts); foreach (var typeMap in profile.TypeMaps) { TypeMapper.Map ( typeMap, profile.Projects.Values.SelectMany(x => x.Interfaces.Values).SelectMany(x => x.Functions) ); } foreach (var typeMap in profile.TypeMaps) { TypeMapper.Map(typeMap, structs); } foreach (var constant in profile.Constants) { constant.Type = TypeMapper.MapOne(profile.TypeMaps, constant.Type); } Console.WriteLine($"Created profile \"{profile.Name}\" version {profile.Version}"); yield return(profile); } }