当前位置: 首页>>代码示例>>C#>>正文


C# Component.CreateProperty方法代码示例

本文整理汇总了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.
            }
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:29,代码来源:ComponentMapper.cs

示例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);
                }
            }
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:31,代码来源:JsonProductSerializer.cs


注:本文中的Component.CreateProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。