I need to get a linq query for custom class MyFileData
public class MyFileData
{
private string name;
private string last_mod;
private string file_type;
private long size;
public string Name
{
get { return name; }
set { name = value; }
}
public string LastMod
{
get { return last_mod; }
set { last_mod = value; }
}
public long Size
{
get { return size; }
set { size = value; }
}
public string FileType
{
get { return file_type;}
set { file_type = value; }
}
}
but I want as an output values of all properties without file_type like this
from file in files
select new MyFileData
{
Name = file.Name,
LastMod = file.LastMod,
Size = file.Size,
};
so the output without the "fileType"
[{"name":"desktop.ini","lastMod":"07.12.2019 10:12:42","size":174,"fileType":null}]
in this way
[{"name":"desktop.ini","lastMod":"07.12.2019 10:12:42","size":174}]
also I would like to group the files with the type of the extension like that
from file in files
group file by file.FileType;
but I get an error.
The files is IEnumerable<MyFileData> type.
Below whole endpoint map for the program:
app.MapGet($"/browse", (string? path, string? group, MyGetFilesInfo myGetFilesInfo) =>
{
IEnumerable<MyFileData> files = myGetFilesInfo.GetFiles(path);
if (group == "true")
{
return
from file in files
select file;
}
var query =
from file in files
select new MyFileData
{
Name = file.Name,
LastMod = file.LastMod,
Size = file.Size,
};
return JsonConvert.SerializeObject(query);
});