Пример #1
0
 public void GenerateAssemblyFile()
 {
     using (var fs = GenerateOutputFile("CefAssembly.cs"))
     {
         using (var cs = new CSharpCodeWriter(fs))
         {
             cs.WriteDefaultUsingDirectives();
             cs.BeginNamespace(_settings.Namespace);
             cs.BeginClass("CefAssembly", false);
             cs.WriteLine("public const string Name = \"libcef.dll\";");
             cs.EndClass();
             cs.EndNamespace();
         }
     }
 }
Пример #2
0
        private void ParseFile(FileSystemInfo file)
        {
            string content;
            using (var f = File.OpenRead(file.FullName))
            {
                using (var sr = new StreamReader(f))
                {
                    content = sr.ReadToEnd();
                }
            }
            var name = CSharpCodeConverter.ConvertFileName(file.Name);
            using (var fs = GenerateOutputFile(name))
            {
                using (var cw = new CSharpCodeWriter(fs))
                {
                    cw.WriteDefaultUsingDirectives();
                    cw.BeginNamespace(_settings.Namespace);

                    var methods = FindNativeMethods(content);
                    if (methods.Count > 0)
                    {
                        GenerateClass(cw, methods, name, _settings.ClassNameSuffix);
                        cw.WriteLine(string.Empty);
                    }

                    var structs = FindStructures(content);
                    if (structs.Count > 0)
                    {
                        var prefix = DeterminePrefix(name);
                        GenerateStruct(cw, structs, prefix, name.Split('.').First());
                        cw.WriteLine(string.Empty);
                    }

                    var enums = FindEnums(content);
                    if (enums.Count > 0)
                    {
                        var prefix = DeterminePrefix(name);
                        GenerateEnum(cw, enums, prefix);
                        cw.WriteLine(string.Empty);
                    }

                    cw.EndNamespace();
                }
            }
        }
Пример #3
0
        private static void GenerateEnum(CSharpCodeWriter cw, IEnumerable<string> enums, string prefix = "")
        {
            foreach (var @enum in enums)
            {
                var name = CSharpCodeConverter.ExtractEnumName(@enum);
                cw.BeginEnum(prefix + name);

                var entries = FindEnumEntries(@enum);
                foreach (var convert in entries.Select(CSharpCodeConverter.ConvertEnumEntry)) {
                    cw.WriteLine(convert);
                }

                cw.EndEnum();
            }
        }
Пример #4
0
        private void GenerateStruct(CSharpCodeWriter cw, IEnumerable<string> structs, string prefix = "", string className = "")
        {
            var delegates = new List<string>();
            foreach (var @struct in structs)
            {
                var name = CSharpCodeConverter.ExtractStructName(@struct);
                cw.BeginStruct(prefix + name);

                var members = FindStructMembers(@struct);
                foreach (var member in members)
                {
                    IEnumerable<string> attributes;
                    bool isFunctionPointer;
                    var convertedMember = CSharpCodeConverter.ConvertMember(member, out isFunctionPointer, out attributes);
                    foreach (var attribute in attributes)
                    {
                        cw.Write(attribute);
                    }
                    cw.WriteLine(convertedMember);
                    if (isFunctionPointer)
                    {
                        delegates.Add(member);
                    }
                }

                cw.EndStruct();
                cw.WriteLine(string.Empty);
            }

            var container = className + "Delegates";
            cw.BeginClass(container);

            foreach (var @delegate in delegates)
            {
                string name;
                var @d = CSharpCodeConverter.CreateDelegate(@delegate, out name).Trim();

                var original = name;

                var number = 1;
                while (_delegateArchive.ContainsKey(name))
                {
                    var c = number.ToString().First();
                    name = name.TrimEnd(c) + (number+=1);
                }

                if (_delegateArchive.ContainsKey(name))
                    continue;

                @d = @d.Replace(original, name);

                cw.WriteLine(@d);
                _delegateArchive.Add(name, @d);
            }

            cw.EndClass();
        }
Пример #5
0
 private static void GenerateClass(CSharpCodeWriter cw, IEnumerable<string> methods, string name, string suffix)
 {
     cw.BeginClass(name.Split('.')[0], true, suffix);
     var enumerable = methods as string[] ?? methods.ToArray();
     foreach (var method in enumerable)
     {
         cw.WriteMethod(method);
         if (enumerable.Last() != method)
         {
             cw.WriteLine(string.Empty);
         }
     }
     cw.EndClass();
 }