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


C# Properties.AddRange方法代码示例

本文整理汇总了C#中Properties.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Properties.AddRange方法的具体用法?C# Properties.AddRange怎么用?C# Properties.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Properties的用法示例。


在下文中一共展示了Properties.AddRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeProperties

        /// <summary>
        /// Loads all properties from database into objects. If this method is re-called, it will re-query the database.
        /// </summary>
        /// <remarks>
        /// This optimizes sql calls. This will first check if all of the properties have been loaded. If not, 
        /// then it will query for all property types for the current version from the db. It will then iterate over each
        /// cmdPropertyData row and store the id and propertyTypeId in a list for lookup later. Once the records have been 
        /// read, we iterate over the cached property types for this ContentType and create a new property based on
        /// our stored list of proeprtyTypeIds. We then have a cached list of Property objects which will get returned
        /// on all subsequent calls and is also used to return a property with calls to getProperty.
        /// </remarks>
        private void InitializeProperties()
        {
            m_LoadedProperties = new Properties();

            if (ContentBase != null)
            {
                m_LoadedProperties.AddRange(ContentBase.Properties.Select(x => new Property(x)));
                return;
            }

            if (this.ContentType == null)
                return;

            //Create anonymous typed list with 2 props, Id and PropertyTypeId of type Int.
            //This will still be an empty list since the props list is empty.
            var propData = m_LoadedProperties.Select(x => new { Id = 0, PropertyTypeId = 0 }).ToList();

            string sql = @"select id, propertyTypeId from cmsPropertyData where [email protected]";

            using (IRecordsReader dr = SqlHelper.ExecuteReader(sql,
                SqlHelper.CreateParameter("@versionId", Version)))
            {
                while (dr.Read())
                {
                    //add the item to our list
                    propData.Add(new { Id = dr.Get<int>("id"), PropertyTypeId = dr.Get<int>("propertyTypeId") });
                }
            }

            foreach (PropertyType pt in this.ContentType.PropertyTypes)
            {
                if (pt == null)
                    continue;

                //get the propertyId
                var property = propData.LastOrDefault(x => x.PropertyTypeId == pt.Id);
                if (property == null)
                {
                    continue;
                    //var prop = Property.MakeNew(pt, this, Version);
                    //property = new {Id = prop.Id, PropertyTypeId = pt.Id};
                }
                var propertyId = property.Id;

                Property p = null;
                try
                {
                    p = new Property(propertyId, pt);
                }
                catch
                {
                    continue; //this remains from old code... not sure why we would do this?
                }

                m_LoadedProperties.Add(p);
            }
        }
开发者ID:kjetilb,项目名称:Umbraco-CMS,代码行数:68,代码来源:Content.cs


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