本文整理汇总了C#中SPMeta2.Definitions.FieldDefinition类的典型用法代码示例。如果您正苦于以下问题:C# FieldDefinition类的具体用法?C# FieldDefinition怎么用?C# FieldDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDefinition类属于SPMeta2.Definitions命名空间,在下文中一共展示了FieldDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Step 1, define site field
var customerField = new FieldDefinition
{
Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
Title = "Customer Name",
InternalName = "cstm_CustomerName",
Description = "Name of the target customer.",
Group = "Hello SPMeta2",
FieldType = BuiltInFieldTypes.Text
};
// Step 2, define site model and artifact relationships - add field to the site
var siteModel = SPMeta2Model
.NewSiteModel(site =>
{
site.AddField(customerField);
});
// Step 3, deploy model via CSOM
using (var clientContext = new ClientContext(SampleConsts.CSOM_SiteUrl))
{
var csomProvisionService = new CSOMProvisionService();
csomProvisionService.DeployModel(SPMeta2.CSOM.ModelHosts.SiteModelHost.FromClientContext(clientContext), siteModel);
}
// Step 4, deploy model via SSOM
using (var site = new SPSite(SampleConsts.SSOM_SiteUrl))
{
var csomProvisionService = new SSOMProvisionService();
csomProvisionService.DeployModel(SPMeta2.SSOM.ModelHosts.SiteModelHost.FromSite(site), siteModel);
}
}
示例2: 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
};
});
}
示例3: 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;
}
}
示例4: PostProcessDefinitionTemplate
protected override void PostProcessDefinitionTemplate(FieldDefinition def)
{
base.PostProcessDefinitionTemplate(def);
def.Indexed = true;
def.DefaultValue = defaultValue;
}
示例5: Deploy_NewSiteField
public void Deploy_NewSiteField()
{
// Step 1, define site field
var customerNameField = new FieldDefinition
{
Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
Title = "Customer Name",
InternalName = "cstm_CustomerName",
Description = "Name of the target customer.",
Group = SampleConsts.DefaultMetadataGroup,
FieldType = BuiltInFieldTypes.Text
};
var customerDescriptionField = new FieldDefinition
{
Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
Title = "Customer Description",
InternalName = "cstm_CustomerDescription",
Description = "Description of the target customer.",
Group = SampleConsts.DefaultMetadataGroup,
FieldType = BuiltInFieldTypes.Note
};
// Step 2, define site model and artifact relationships - add field to the site
var model = SPMeta2Model
.NewSiteModel(site =>
{
site
.AddField(customerNameField)
.AddField(customerDescriptionField);
});
// Step 3, deploy model
DeploySiteModel(model);
}
示例6: 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;
}
示例7: AddContentTypeFieldLink
public static ModelNode AddContentTypeFieldLink(this ModelNode model, FieldDefinition definition, Action<ModelNode> action)
{
return AddContentTypeFieldLink(model, new ContentTypeFieldLinkDefinition
{
FieldId = definition.Id
}, action);
}
示例8: 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;
}
示例9: 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;
}
示例10: 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
}
示例11: 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);
}
示例12: 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;
}
示例13: CanSerializeAndDeserializeXML
public void CanSerializeAndDeserializeXML()
{
var obj = new FieldDefinition();
var service = new DefaultXMLSerializationService();
var strValue = service.Serialize(obj);
service.Deserialize(obj.GetType(), strValue);
}
示例14: 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);
}
示例15: ProcessCommonProperties
private static void ProcessCommonProperties(SPField siteField, FieldDefinition fieldModel)
{
siteField.Title = fieldModel.Title;
siteField.Group = fieldModel.Group;
// SPBug, description cannot be null
siteField.Description = fieldModel.Description ?? string.Empty;
}