;;; csharp-yasnippet.el --- C# utility functions for yasnippet
(provide 'csharp-yasnippet)
(defun csharp--get-csproj-in-directory (dir)
(car (directory-files dir
:mach-regexp ".*\\.csproj"
:count 1)))
(defun csharp--find-csproj (dir)
(csharp--get-csproj-in-directory
(locate-dominating-file
dir #'csharp--get-csproj-in-directory)))
(defun csharp--find-current-csproj ()
(csharp--find-csproj buffer-file-name))
(defun csharp--extract-project-name ()
(interactive)
(let ((csproj (csharp--find-current-csproj)))
(file-name-base csproj)))
(defun csharp-file-path-to-namespace ()
(interactive)
(let* ((root (file-name-directory (csharp--find-current-csproj)))
(base (file-name-nondirectory buffer-file-name))
(project-name (csharp--extract-project-name))
(subdirectory
(replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t)))
(concat
project-name
(if (string= "" subdirectory)
""
(concat "." (substring subdirectory 0 -1))))))
;;; csharp-yasnippet.el ends here