本文整理汇总了C#中SPFieldCollection.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# SPFieldCollection.OfType方法的具体用法?C# SPFieldCollection.OfType怎么用?C# SPFieldCollection.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPFieldCollection
的用法示例。
在下文中一共展示了SPFieldCollection.OfType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindField
private SPField FindField(SPFieldCollection fields, ListFieldLinkDefinition listFieldLinkModel)
{
if (listFieldLinkModel.FieldId.HasGuidValue())
{
return fields
.OfType<SPField>()
.FirstOrDefault(f => f.Id == listFieldLinkModel.FieldId.Value);
}
if (!string.IsNullOrEmpty(listFieldLinkModel.FieldInternalName))
{
return fields
.OfType<SPField>()
.FirstOrDefault(f => f.InternalName.ToUpper() == listFieldLinkModel.FieldInternalName.ToUpper());
}
throw new ArgumentException("FieldId or FieldInternalName should be defined");
}
示例2: HandleIncorectlyDeletedTaxonomyField
private void HandleIncorectlyDeletedTaxonomyField(FieldDefinition fieldModel,
SPFieldCollection fields)
{
var isTaxField =
fieldModel.FieldType.ToUpper() == BuiltInFieldTypes.TaxonomyFieldType.ToUpper()
|| fieldModel.FieldType.ToUpper() == BuiltInFieldTypes.TaxonomyFieldTypeMulti.ToUpper();
if (!isTaxField)
return;
var existingIndexedFieldName = fieldModel.Title.ToUpper() + "_";
var existingIndexedField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Title.ToUpper().StartsWith(existingIndexedFieldName));
if (existingIndexedField != null && existingIndexedField.Type == SPFieldType.Note)
existingIndexedField.Delete();
}
示例3: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
// special handle for taxonomy field
// incorectly removed tax field leaves its indexed field
// https://github.com/SubPointSolutions/spmeta2/issues/521
HandleIncorectlyDeletedTaxonomyField(fieldModel, fields);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields[fieldModel.Id];
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例4: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields[fieldModel.Id];
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例5: GetDependentLookupField
protected virtual SPFieldLookup GetDependentLookupField(SPFieldCollection fields, DependentLookupFieldDefinition definition)
{
var targetName = definition.InternalName.ToUpper();
return fields
.OfType<SPField>()
.FirstOrDefault(f => f.InternalName.ToUpper() == targetName) as SPFieldLookup;
}
示例6: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
// by ID?
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
// by internal name?
if (currentField == null && !string.IsNullOrEmpty(fieldModel.InternalName))
{
TraceService.Information((int)LogEventId.CoreCalls, "Could not find field by ID, fallback on InternalName");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => String.Equals(f.InternalName, fieldModel.InternalName,
StringComparison.OrdinalIgnoreCase));
}
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null && !string.IsNullOrEmpty(fieldModel.InternalName))
{
TraceService.Information((int)LogEventId.CoreCalls, "Could not find existing field by ID, fallback on InternalName");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => String.Equals(f.InternalName, fieldModel.InternalName,
StringComparison.OrdinalIgnoreCase));
}
if (currentField == null)
{
throw new SPMeta2Exception(
string.Format("Cannot find existing field neither by ID [{0}] or InternalName [{1}]. Definition:[{2}]",
fieldModel.Id, fieldModel.InternalName, fieldModel));
}
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}