我正在尝试使用属性和字符串填充列表
I am trying to populate a list with properties and strings
我正在尝试用 属性 个名称和值填充一个列表,这是我到目前为止的代码...
public class DirPropeties {
public string Name { get; set; }
public string Path { get; set; }
public string HiddenStatus { get; set; }
}
public static List<string> GetDirAttributes(string path, bool IsHidden = true)
{
List<DirPropeties> FolderArrayList = new List<DirPropeties>();
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] subdirectories = di.GetDirectories();
foreach (DirectoryInfo dir in subdirectories)
{
if (IsHidden)
{
//FolderArrayList.Add(dir.Name);
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
else if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
};
return FolderArrayList;
}
我是这样称呼它的....
List<string> DirectoryArrayList = new List<string>();
DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
我正在尝试像这样访问属性...
if (folderIndex >= DirectoryArrayList.Count) { break; }
var folder = DirectoryArrayList[folderIndex];
var label = new Label()
{
Text = folder.Name,
FontSize = 20,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center
};
我在 FolderArrayList 的 return 上收到以下错误...
无法将类型 'System.Collections.Generic.List' 隐式转换为 'System.Collections.Generic.List'
在 folder.Name 上我得到以下错误...
'string' 不包含 'Name'
的定义
任何人都可以帮助指导我解决这个问题需要做什么吗?
无需在此代码中的任何地方使用 List<string>
。变化
public static List<string> GetDirAttributes(string path, bool IsHidden = true)
到
public static List<DirPropeties> GetDirAttributes(string path, bool IsHidden = true)
也改
List<string> DirectoryArrayList = new List<string>();
DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
到
var DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
您还可以改进此代码
if (IsHidden)
{
//FolderArrayList.Add(dir.Name);
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
else if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
到
if (IsHidden || (dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
我正在尝试用 属性 个名称和值填充一个列表,这是我到目前为止的代码...
public class DirPropeties {
public string Name { get; set; }
public string Path { get; set; }
public string HiddenStatus { get; set; }
}
public static List<string> GetDirAttributes(string path, bool IsHidden = true)
{
List<DirPropeties> FolderArrayList = new List<DirPropeties>();
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] subdirectories = di.GetDirectories();
foreach (DirectoryInfo dir in subdirectories)
{
if (IsHidden)
{
//FolderArrayList.Add(dir.Name);
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
else if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
};
return FolderArrayList;
}
我是这样称呼它的....
List<string> DirectoryArrayList = new List<string>();
DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
我正在尝试像这样访问属性...
if (folderIndex >= DirectoryArrayList.Count) { break; }
var folder = DirectoryArrayList[folderIndex];
var label = new Label()
{
Text = folder.Name,
FontSize = 20,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center
};
我在 FolderArrayList 的 return 上收到以下错误...
无法将类型 'System.Collections.Generic.List' 隐式转换为 'System.Collections.Generic.List'
在 folder.Name 上我得到以下错误...
'string' 不包含 'Name'
的定义任何人都可以帮助指导我解决这个问题需要做什么吗?
无需在此代码中的任何地方使用 List<string>
。变化
public static List<string> GetDirAttributes(string path, bool IsHidden = true)
到
public static List<DirPropeties> GetDirAttributes(string path, bool IsHidden = true)
也改
List<string> DirectoryArrayList = new List<string>();
DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
到
var DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
您还可以改进此代码
if (IsHidden)
{
//FolderArrayList.Add(dir.Name);
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
else if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
到
if (IsHidden || (dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}