Example #1
0
        /// <summary>
        /// ファイルからMessagePackデータをデシリアライズする
        /// </summary>
        /// <typeparam name="T">型</typeparam>
        /// <param name="path">ファイルパス</param>
        /// <returns>Task<typeparamref name="T"/></returns>
        public static async Task <T> DeserializeFileAsync <T>(string path)
        {
            using var stream = FileContentUtil.OpenRead(path, isAsync: true);

            if (stream == null)
            {
                return(default);
Example #2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                ShowFileMissingErrorMessage();
                return;
            }

            try
            {
                // String which contains whole file contents
                string fileContent = FileContentUtil.GetFileContent(filePath);

                // Get option values for generator options
                JsGeneratorOptions options = GetOptions();

                // Create compiler and execute content of file
                Assembly asm = BuildAssemblyUtil.CompileCode(fileContent);

                // Get all types from assembly using reflection
                List <Type> rawTypes = BuildAssemblyUtil.GetExportedTypes(asm);

                // Filter types, and take only parent ones (the ones that are not referenced in parent, and standalone one)
                // If referenced children will be generated automatically, so no need to duplicate stuff.
                List <Type> types = BuildAssemblyUtil.FilterExportedTypes(rawTypes);

                // Finally generate
                StringBuilder sbFinal = new StringBuilder();
                foreach (Type type in types)
                {
                    switch (options.ConversionType)
                    {
                    case EGenerateOptions.Javascript:
                        sbFinal.AppendLine(JsGenerator.Generate(new[] { type }, options));
                        break;

                    case EGenerateOptions.Ecma6:
                        sbFinal.AppendLine(Ecma6Generator.Generate(new[] { type }, options));
                        break;

                    case EGenerateOptions.KnockoutEcma6:
                        sbFinal.AppendLine(Ecma6KnockoutGenerator.Generate(new[] { type }, options));
                        break;

                    default:
                        throw new Exception(
                                  "Somehow Conversion type is not set or is out of bounds. I have no idea what happened.");
                    }
                }

                codeTextEditor.Text = sbFinal.ToString();
            }
            catch (Exception exception)
            {
                // Since we presumably should know what we are doing here, we are just showing message from exception
                // Would be good idea to log this somewhere tho.
                ShowErrorMessage(exception.Message);
            }
        }