Exemplo n.º 1
0
        private static void GetCommentInfo(string inputFile, CopyrightTemplate companyTemplate, Action <string> errorAction = null)
        {
            const string commentSpecFile = "CommentSpecification.json";

            try
            {
                var ext = Path.GetExtension(inputFile);
                using (var resource = CopyrightUtil.ResourceStream(commentSpecFile))
                {
                    if (resource != null)
                    {
                        var serializer   = new DataContractJsonSerializer(typeof(CommentSpec[]));
                        var commentSpecs = (CommentSpec[])serializer.ReadObject(resource);
                        var commentSpec  = commentSpecs.Find(ext);
                        if (commentSpec == null)
                        {
                            errorAction?.Invoke($"Unsupported file: {inputFile}");
                        }
                        Console.WriteLine($"Using {commentSpec?.Name} extension specification");
                        companyTemplate.CommentSpec = commentSpec;
                    }
                }
            }
            catch (Exception e)
            {
                errorAction?.Invoke(e.Message);
            }
        }