Skip to content

Commit ca0c693

Browse files
committed
add dotnet_{api,version}
1 parent 9fd33f3 commit ca0c693

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

+stdlib/dotnet_api.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%% DOTNET_API major version integer .NET
2+
3+
function v = dotnet_api()
4+
5+
v = System.Environment.Version.Major;
6+
7+
end

+stdlib/dotnet_version.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%% DOTNET_VERSION version string
2+
3+
function v = dotnet_version()
4+
5+
vs = System.Environment.Version;
6+
7+
v = sprintf('%d.%d.%d', vs.Major, vs.Minor, vs.Build);
8+
9+
end

+stdlib/is_symlink.m

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
switch e.identifier
1313
case "MATLAB:UndefinedFunction"
1414
if stdlib.has_dotnet()
15-
ok = is_symlink_dotnet(p);
15+
if stdlib.dotnet_api >= 6
16+
ok = ~isempty(System.IO.FileInfo(p).LinkTarget);
17+
else
18+
attr = string(System.IO.File.GetAttributes(p).ToString());
19+
% https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributesN
20+
% ReparsePoint is for Linux, macOS, and Windows
21+
ok = contains(attr, 'ReparsePoint');
22+
end
1623
elseif stdlib.has_java()
1724
ok = java.nio.file.Files.isSymbolicLink(javaPathObject(stdlib.absolute(p)));
1825
else
@@ -29,23 +36,6 @@
2936
end
3037

3138

32-
function ok = is_symlink_dotnet(p)
33-
34-
try
35-
ok = ~isempty(System.IO.FileInfo(p).LinkTarget);
36-
catch e
37-
if strcmp(e.identifier, "MATLAB:noSuchMethodOrField")
38-
attr = string(System.IO.File.GetAttributes(p).ToString());
39-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributesN
40-
% ReparsePoint is for Linux, macOS, and Windows
41-
ok = contains(attr, 'ReparsePoint');
42-
else
43-
rethrow(e)
44-
end
45-
end
46-
47-
end
48-
4939
%!test
5040
%! if !ispc
5141
%! p = tempname();

0 commit comments

Comments
 (0)