本文整理汇总了C#中Component.CreateProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Component.CreateProperty方法的具体用法?C# Component.CreateProperty怎么用?C# Component.CreateProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Component
的用法示例。
在下文中一共展示了Component.CreateProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncComponent
private static void SyncComponent(Component component, IComponentInfo schema)
{
component.Schema = schema;
// Delete existing properties that don't have a corresponding definition.
// and are not system properties (starting with $) or hidden ones (starting with _)
component.Properties
.Where(p => !p.Name.StartsWith("$") && !p.Name.StartsWith("_") && !schema.Properties.Any(info => info.Name == p.Name))
.ToArray()
.ForEach(p => p.Delete());
// Initialize all the new properties. Existing ones are not modified.
foreach (var propertySchema in schema.Properties)
{
var property = component.Properties.FirstOrDefault(x => x.Name == propertySchema.Name);
if (property != null)
{
property.Schema = propertySchema;
}
else
{
property = component.CreateProperty(propertySchema.Name);
property.Schema = propertySchema;
}
// NOTE: unlike original NuPattern, we don't eagerly evaluate default values,
// neither do we persist them.
}
}
示例2: DeserializeComponent
private void DeserializeComponent(Component component, JObject json)
{
var lineInfo = json as IJsonLineInfo;
if (lineInfo != null && lineInfo.HasLineInfo())
component.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);
foreach (var jprop in json.Properties().Where(x =>
!x.Name.StartsWith("$") && x.HasValues && x.Value.Type != JTokenType.Object))
{
var jvalue = jprop.Value as JValue;
if (jvalue != null)
{
var value = jvalue.Value;
var str = value as string;
Guid guid;
// See if it's a Guid.
if (str != null && str.StartsWith("{") && str.EndsWith("}") &&
Guid.TryParse(str, out guid))
{
value = guid;
}
var property = component.CreateProperty(jprop.Name);
property.Value = value;
lineInfo = jvalue as IJsonLineInfo;
if (lineInfo != null && lineInfo.HasLineInfo())
property.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);
}
}
}