【发布时间】:2018-03-18 03:23:46
【问题描述】:
我是一名初学者,如果您能帮助我找出代码中的问题,我将不胜感激。代码特别令人困惑,主要是因为它源自框架。 cmets应该可以让我们有点理解。
// Create an IBindable List
public static List<IBindable> KyzerBindables = new List<IBindable>();
// Attach elements to a list, for better control over all of them
internal static void AttachBindablesToList(IReadOnlyList<Drawable> children)
{
// For all the children classes located in Drawable list
for (int i = 0; i < children.Count; i++) // children.Count returns 4
{
// For all of the SettingsSubsection which are present in the Drawable array
for (int l = 0; l < (children[i] as SettingsSubsection).Children.Count; l++) // (children[i] as Subsection).Children.Count returns 0.
{
// Get a specific element
var element = (children[i] as SettingsSubsection).Children[l];
// if is a SettingsCheckbox
if (element.GetType() == typeof(SettingsCheckbox))
KyzerBindables.Add((element as SettingsCheckbox).Bindable);
}
}
}
// in another class
public class KyzerSection: SettingsSection
{
public KyzerSection()
{
Children = new Drawable[]
{
new KyzerMiscellaneous(),
};
...AttachElementsToList(Children);
}
}
public class KyzerMiscellaneous: SettingsSubsection
{
[BackgroundDependencyLoader] // Calls load, framework thing.
private void load(OsuConfigManager config)
{
Children = new Drawable[]
{
new SettingsCheckbox
{
LabelText = "Something here",
Bindable = new BindableBool(false),
}
};
}
}
我的问题是,第二个 for 循环甚至没有为 AttachBindablesToList 启动。无论出于何种特殊原因,它都没有收到计数。我不确定自己做错了什么。
编辑:
如果 GitHub 存储库问题以任何方式可以解决一些问题,请随时导航到那里并检查包含这些更改的提交。 https://github.com/Frontear/osuKyzer/issues/3
【问题讨论】:
-
我很抱歉。我不小心发布了。
-
这里并不神秘。如果
children.Count为0,则列表中没有元素。使用断点来帮助更好地确定发生了什么 -
我用更多信息更新了我的问题。
-
你有没有单步调试过代码?
-
是的,多次。如果 GitHub 存储库问题以任何方式可以解决一些问题,请随时导航到那里并检查包含这些更改的提交。 github.com/Frontear/osuKyzer/issues/3
标签: c# frameworks game-engine