私は PHP 出身ですが、データ構造を適切に処理する方法を理解していないと思います。SPFieldCollection.Addのドキュメントには、どのような種類の引数が必要かが明確に記載されているため、次のようなクラスを作成しました。
namespace SPAPI.Lists.Add
{
class AddParams
{
public SPFieldType type { get; set; }
public bool required { get; set; }
}
}
そこから、次のことを行うリストを作成しました。
public Create(SPFeatureReceiverProperties properties, Dictionary<string, List<AddParams>> columns, string name, string description, SPListTemplateType type)
{
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
{
SPWeb web = siteCollection.RootWeb;
web.Lists.Add(name, description, type);
web.Update();
// Add the new list and the new content.
SPList spList = web.Lists[name];
foreach(KeyValuePair<string, List<AddParams>> col in columns){
spList.Fields.Add(col.Key, col.Value[0], col.Value[1]);
}
// More Code ...
}
}
問題は、厳密な定義により、一方が aではなく、他方がa ではないため、 が好きcol.Value[0]
ではないことです。私は正しいアイデアを持っていると思いますが、これを機能させる方法についてのガイダンスを探しています。col.Value[1]
SPFieldType
boolean
C# には型ヒントがあるため、AddParams
クラスを使用して型を確認すると想定しました。
アイデアは、一連のパラメーターを渡し、それらのパラメーターに基づいて新しいリストを作成することです。
これは、SP 開発の質問というよりも、C# の質問とデータ構造の反復に関する質問です。