本文整理汇总了C#中SPMeta2.Definitions.FieldDefinition.WithAssertAndCast方法的典型用法代码示例。如果您正苦于以下问题:C# FieldDefinition.WithAssertAndCast方法的具体用法?C# FieldDefinition.WithAssertAndCast怎么用?C# FieldDefinition.WithAssertAndCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPMeta2.Definitions.FieldDefinition
的用法示例。
在下文中一共展示了FieldDefinition.WithAssertAndCast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessFieldProperties
protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
{
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);
var typedField = field as SPFieldUser;
var typedFieldModel = fieldModel.WithAssertAndCast<UserFieldDefinition>("model", value => value.RequireNotNull());
typedField.AllowDisplay = typedFieldModel.AllowDisplay;
typedField.Presence = typedFieldModel.Presence;
typedField.AllowMultipleValues = typedFieldModel.AllowMultipleValues;
if (!string.IsNullOrEmpty(typedFieldModel.SelectionMode))
typedField.SelectionMode = (SPFieldUserSelectionMode)Enum.Parse(typeof(SPFieldUserSelectionMode), typedFieldModel.SelectionMode);
if (typedFieldModel.SelectionGroup.HasValue)
{
typedField.SelectionGroup = typedFieldModel.SelectionGroup.Value;
}
else if (!string.IsNullOrEmpty(typedFieldModel.SelectionGroupName))
{
var group = GetCurrentWeb().SiteGroups.OfType<SPGroup>().FirstOrDefault(g => g.Name.ToUpper() == typedFieldModel.SelectionGroupName.ToUpper());
typedField.SelectionGroup = group.ID;
}
}
示例2: ProcessFieldProperties
protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
{
var typedFieldModel = fieldModel.WithAssertAndCast<NoteFieldDefinition>("model", value => value.RequireNotNull());
// the XML update goes first
// then the rest of the normal props with base.ProcessFieldProperties(field, fieldModel);
// then specific to NoteField props
// as crazy as it sounds
// RichTextMode update
// https://github.com/SubPointSolutions/spmeta2/issues/673
if (!string.IsNullOrEmpty(typedFieldModel.RichTextMode))
{
var fieldXml = XDocument.Parse(field.SchemaXml);
fieldXml.Root.SetAttribute("RichTextMode", typedFieldModel.RichTextMode);
field.SchemaXml = fieldXml.ToString();
}
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);
var typedField = field.Context.CastTo<FieldMultiLineText>(field);
typedField.NumberOfLines = typedFieldModel.NumberOfLines;
typedField.AppendOnly = typedFieldModel.AppendOnly;
typedField.RichText = typedFieldModel.RichText;
}
示例3: PostProcessFieldDefinitionInstance
protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
{
var context = typedReverseHost.HostClientContext;
var typedField = context.CastTo<FieldLookup>(typedReverseHost.Field);
var typedDef = def.WithAssertAndCast<LookupFieldDefinition>("modelHost", m => m.RequireNotNull());
typedDef.AllowMultipleValues = typedField.AllowMultipleValues;
if (typedDef.AllowMultipleValues)
typedDef.FieldType = BuiltInFieldTypes.LookupMulti;
else
typedDef.FieldType = BuiltInFieldTypes.Lookup;
//typedDef.AppendOnly = typedField.AppendOnly;
//typedDef.RichText = typedField.RichText;
//typedDef.NumberOfLines = typedField.NumberOfLines;
//var xml = XDocument.Parse(typedField.SchemaXml);
//var fieldXml = xml.Root;
//var unlimValue = ConvertUtils.ToBool(fieldXml.GetAttributeValue("UnlimitedLengthInDocumentLibrary"));
//typedDef.UnlimitedLengthInDocumentLibrary = unlimValue.HasValue ? unlimValue.Value : false;
//var richTextMode = ConvertUtils.ToString(fieldXml.GetAttributeValue("RichTextMode"));
//typedDef.RichTextMode = richTextMode;
}
示例4: ProcessFieldProperties
protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
{
var site = HostSite;
var context = site.Context;
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);
var typedField = field.Context.CastTo<FieldLookup>(field);
var typedFieldModel = fieldModel.WithAssertAndCast<DependentLookupFieldDefinition>("model", value => value.RequireNotNull());
var primaryLookupField = GetPrimaryField(typedFieldModel);
typedField.Context.Load(primaryLookupField);
typedField.Context.ExecuteQueryWithTrace();
if (string.IsNullOrEmpty(typedField.PrimaryFieldId))
{
typedField.PrimaryFieldId = primaryLookupField.Id.ToString();
}
typedField.ReadOnlyField = true;
if (!string.IsNullOrEmpty(typedFieldModel.RelationshipDeleteBehavior))
{
var value = (RelationshipDeleteBehaviorType)Enum.Parse(typeof(RelationshipDeleteBehaviorType), typedFieldModel.RelationshipDeleteBehavior);
typedField.RelationshipDeleteBehavior = value;
}
// unsupported in CSOM yet
//dependentLookupField.UnlimitedLengthInDocumentLibrary = primaryLookupField.UnlimitedLengthInDocumentLibrary;
typedField.Direction = primaryLookupField.Direction;
}
示例5: ProcessFieldProperties
protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
{
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);
if (!string.IsNullOrEmpty(fieldModel.ValidationMessage))
field.ValidationMessage = fieldModel.ValidationMessage;
if (!string.IsNullOrEmpty(fieldModel.ValidationFormula))
field.ValidationFormula = fieldModel.ValidationFormula;
var typedFieldModel = fieldModel.WithAssertAndCast<DateTimeFieldDefinition>("model", value => value.RequireNotNull());
var typedField = field as SPFieldDateTime;
if (!string.IsNullOrEmpty(typedFieldModel.CalendarType))
typedField.CalendarType = (SPCalendarType)Enum.Parse(typeof(SPCalendarType), typedFieldModel.CalendarType);
if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
typedField.DisplayFormat = (SPDateTimeFieldFormatType)Enum.Parse(typeof(SPDateTimeFieldFormatType), typedFieldModel.DisplayFormat);
#if !NET35
if (!string.IsNullOrEmpty(typedFieldModel.FriendlyDisplayFormat))
typedField.FriendlyDisplayFormat = (SPDateTimeFieldFriendlyFormatType)Enum.Parse(typeof(SPDateTimeFieldFriendlyFormatType), typedFieldModel.FriendlyDisplayFormat);
#endif
}
示例6: CustomFieldTypeValidation
protected override void CustomFieldTypeValidation(AssertPair<FieldDefinition, Field> assert, Field spObject, FieldDefinition definition)
{
var typedObject = spObject.Context.CastTo<FieldLookup>(spObject);
var typedDefinition = definition.WithAssertAndCast<LookupFieldDefinition>("model", value => value.RequireNotNull());
// https://github.com/SubPointSolutions/spmeta2/issues/310
// AllowMultipleValues - TRUE - LookupMulti
// AllowMultipleValues - FALSE - Lookup
assert.ShouldBeEqual((p, s, d) =>
{
var srcProp = s.GetExpressionValue(m => m.FieldType);
var dstProp = d.GetExpressionValue(m => d.TypeAsString);
var isValid = typedDefinition.AllowMultipleValues
? typedObject.TypeAsString == "LookupMulti"
: typedObject.TypeAsString == "Lookup";
return new PropertyValidationResult
{
Tag = p.Tag,
Src = srcProp,
Dst = dstProp,
IsValid = isValid
};
});
}
示例7: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<CurrencyFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);
}
示例8: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<SummaryLinkFieldDefinition>("model", value => value.RequireNotNull());
//fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.EditFormat);
}
示例9: ProcessFieldProperties
protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
{
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<SummaryLinkFieldDefinition>("model", value => value.RequireNotNull());
var typedField = field as SummaryLinkField;
}
示例10: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<ComputedFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.EnableLookup.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.EnableLookup, typedFieldModel.EnableLookup.ToString().ToUpper());
}
示例11: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<TextFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.MaxLength.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.MaxLength, typedFieldModel.MaxLength.Value);
}
示例12: PostProcessFieldDefinitionInstance
protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
{
var context = typedReverseHost.HostClientContext;
var typedField = context.CastTo<FieldText>(typedReverseHost.Field);
var typedDef = def.WithAssertAndCast<TextFieldDefinition>("modelHost", m => m.RequireNotNull());
typedDef.MaxLength = typedField.MaxLength;
}
示例13: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<ImageFieldDefinition>("model", value => value.RequireNotNull());
// TODO
//fieldTemplate.SetAttribute(BuiltInFieldAttributes.RichText, typedFieldModel.RichText.ToString().ToUpper());
}
示例14: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<URLFieldDefinition>("model", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.DisplayFormat);
}
示例15: PostProcessFieldDefinitionInstance
protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
{
var context = typedReverseHost.HostClientContext;
var typedField = context.CastTo<FieldCurrency>(typedReverseHost.Field);
var typedDef = def.WithAssertAndCast<CurrencyFieldDefinition>("modelHost", m => m.RequireNotNull());
if (typedField.CurrencyLocaleId > 0)
typedDef.CurrencyLocaleId = typedField.CurrencyLocaleId;
}