本文整理汇总了C#中System.Xml.Linq.XElement.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.SetAttribute方法的具体用法?C# XElement.SetAttribute怎么用?C# XElement.SetAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.SetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var businessFieldModel = fieldModel.WithAssertAndCast<BusinessDataFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.SystemInstance, businessFieldModel.SystemInstanceName);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.EntityNamespace, businessFieldModel.EntityNamespace);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.EntityName, businessFieldModel.EntityName);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.BdcField, businessFieldModel.BdcFieldName);
}
示例2: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<NoteFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.NumberOfLines > 0)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.NumLines, typedFieldModel.NumberOfLines);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.RichText, typedFieldModel.RichText.ToString().ToUpper());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.RichTextMode, typedFieldModel.RichTextMode);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.AppendOnly, typedFieldModel.AppendOnly.ToString().ToUpper());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.UnlimitedLengthInDocumentLibrary, typedFieldModel.UnlimitedLengthInDocumentLibrary.ToString().ToUpper());
}
示例3: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<DependentLookupFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Mult, typedFieldModel.AllowMultipleValues.ToString().ToUpper());
SPField primaryField = GetPrimaryField(typedFieldModel);
if (primaryField == null)
{
throw new SPMeta2Exception("PrimaryLookupField needs to be defined when creating a DependentLookupField");
}
fieldTemplate.SetAttribute(BuiltInFieldAttributes.FieldReference, primaryField.Id.ToString("B"));
}
示例4: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<NumberFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.MinimumValue.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Min, typedFieldModel.MinimumValue);
if (typedFieldModel.MaximumValue.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Max, typedFieldModel.MaximumValue);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Percentage, typedFieldModel.ShowAsPercentage.ToString().ToUpper());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Decimals, GetDecimalsValue(typedFieldModel.DisplayFormat));
}
示例5: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<UserFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Mult, typedFieldModel.AllowMultipleValues.ToString().ToUpper());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.ForcedDisplay, typedFieldModel.AllowDisplay.ToString().ToUpper());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Presence, typedFieldModel.Presence.ToString().ToUpper());
if (typedFieldModel.SelectionGroup.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.UserSelectionScope, typedFieldModel.SelectionGroup.ToString());
if (!string.IsNullOrEmpty(typedFieldModel.SelectionMode))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.UserSelectionMode, typedFieldModel.SelectionMode);
}
示例6: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.CurrencyLocaleId.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);
if (!string.IsNullOrEmpty(typedFieldModel.Formula))
{
// can't really validate it automatically
// Improve CalculatedFieldDefinition with field ref check
// https://github.com/SubPointSolutions/spmeta2/issues/648
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Crafting formula for a CalculatedField. Ensure FieldReferences are correct.");
// should be a new XML node
var formulaNode = new XElement(BuiltInFieldAttributes.Formula, typedFieldModel.Formula);
fieldTemplate.Add(formulaNode);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format,
(int)Enum.Parse(typeof(SPDateTimeFieldFormatType), typedFieldModel.DateFormat));
}
if (typedFieldModel.ShowAsPercentage.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Percentage, typedFieldModel.ShowAsPercentage.Value.ToString().ToUpper());
if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Decimals, NumberFieldModelHandler.GetDecimalsValue(typedFieldModel.DisplayFormat));
fieldTemplate.SetAttribute(BuiltInFieldAttributes.ResultType, typedFieldModel.OutputType);
if (typedFieldModel.FieldReferences.Count > 0)
{
var fieldRefsNode = new XElement("FieldRefs");
foreach (var fieldRef in typedFieldModel.FieldReferences)
{
var fieldRefNode = new XElement("FieldRef");
fieldRefNode.SetAttribute("Name", fieldRef);
fieldRefsNode.Add(fieldRefNode);
}
fieldTemplate.Add(fieldRefsNode);
}
}
示例7: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<ChoiceFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.EditFormat);
}
示例8: 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);
}
示例9: 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);
}
示例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<DateTimeFieldDefinition>("model", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(typedFieldModel.CalendarType))
{
var value = (CalendarType)Enum.Parse(typeof(CalendarType), typedFieldModel.CalendarType);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.CalType, (int)value);
}
if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.DisplayFormat);
if (!string.IsNullOrEmpty(typedFieldModel.FriendlyDisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.FriendlyDisplayFormat, typedFieldModel.FriendlyDisplayFormat);
}
示例12: 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);
}
示例13: ToXml
/// <summary>
/// Emits WiX XML.
/// </summary>
/// <returns></returns>
public override XContainer[] ToXml()
{
XNamespace bal = "http://schemas.microsoft.com/wix/BalExtension";
var root = new XElement("BootstrapperApplicationRef");
var app = new XElement(bal + "WixStandardBootstrapperApplication");
app.Add(this.MapToXmlAttributes());
if (LicensePath.IsNotEmpty() && LicensePath.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
{
root.SetAttribute("Id", "WixStandardBootstrapperApplication.RtfLicense");
app.SetAttribute("LicenseFile", LicensePath);
}
else
{
root.SetAttribute("Id", "WixStandardBootstrapperApplication.HyperlinkLicense");
if (LicensePath.IsEmpty())
{
//cannot use SetAttribute as we want to preserve empty attrs
app.Add(new XAttribute("LicenseUrl", ""));
}
else
{
if (LicensePath.StartsWith("http")) //online HTML file
{
app.SetAttribute("LicenseUrl", LicensePath);
}
else
{
app.SetAttribute("LicenseUrl", System.IO.Path.GetFileName(LicensePath));
root.AddElement("Payload").AddAttributes("SourceFile=" + LicensePath);
}
}
}
root.Add(app);
return new[] { root };
}
示例14: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());
if (typedFieldModel.CurrencyLocaleId.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);
// should be a new XML node
var formulaNode = new XElement(BuiltInFieldAttributes.Formula, typedFieldModel.Formula);
fieldTemplate.Add(formulaNode);
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, (int)Enum.Parse(typeof(DateTimeFieldFormatType), typedFieldModel.DateFormat));
if (typedFieldModel.ShowAsPercentage.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Percentage, typedFieldModel.ShowAsPercentage.Value.ToString().ToUpper());
if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Decimals, NumberFieldModelHandler.GetDecimalsValue(typedFieldModel.DisplayFormat));
fieldTemplate.SetAttribute(BuiltInFieldAttributes.ResultType, typedFieldModel.OutputType);
if (typedFieldModel.FieldReferences.Count > 0)
{
var fieldRefsNode = new XElement("FieldRefs");
foreach (var fieldRef in typedFieldModel.FieldReferences)
{
var fieldRefNode = new XElement("FieldRef");
fieldRefNode.SetAttribute("Name", fieldRef);
fieldRefsNode.Add(fieldRefNode);
}
fieldTemplate.Add(fieldRefsNode);
}
}
示例15: ProcessSPFieldXElement
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);
var typedFieldModel = fieldModel.WithAssertAndCast<MultiChoiceFieldDefinition>("model", value => value.RequireNotNull());
fieldTemplate.SetAttribute(BuiltInFieldAttributes.FillInChoice, typedFieldModel.FillInChoice);
if (typedFieldModel.Choices.Count > 0)
{
var choicesNode = new XElement("CHOICES");
foreach (var choice in typedFieldModel.Choices)
{
choicesNode.Add(new XElement("CHOICE", choice));
}
fieldTemplate.Add(choicesNode);
}
if (typedFieldModel.Mappings.Count > 0)
{
var mappingsNode = new XElement("MAPPINGS");
var currentValueIndex = 1;
foreach (var mappingValue in typedFieldModel.Mappings)
{
var mappingValueNode = new XElement("MAPPING", mappingValue);
mappingValueNode.SetAttributeValue("Value", currentValueIndex);
mappingsNode.Add(mappingValueNode);
currentValueIndex++;
}
fieldTemplate.Add(mappingsNode);
}
}