Exemple #1
0
        public static void AddProperty <T>(this PropertyTarget target, string key, string displayName, string description, T initialValue, T[] standardValues = null)
        {
            DynTypeDescriptor.InstallTypeDescriptor(target);
            var td = DynTypeDescriptor.GetTypeDescriptor(target);

            if (td == null)
            {
                throw new Exception("Could not load type descriptor");
            }


            var pd = new DynPropertyDescriptor(target.GetType(), key, typeof(T), initialValue
                                               , new BrowsableAttribute(true)
                                               , new DisplayNameAttribute(displayName)
                                               , new DescriptionAttribute(description)
                                               );

            if (standardValues != null && standardValues.Length > 0)
            {
                pd.Attributes.Add(new TypeConverterAttribute(typeof(DynStandardValueConverter)), true);
                foreach (var value in standardValues)
                {
                    var sv = new DynStandardValue(value);
                    sv.DisplayName = value.ToString();
                    pd.StandardValues.Add(sv);
                }
            }

            td.GetProperties().Add(pd);
        }
Exemple #2
0
        private int CompareProperty(DynPropertyDescriptor xCpd, DynPropertyDescriptor yCpd)
        {
            int nCompResult = 0;

            switch (m_PropertySortOrder)
            {
                case SortOrder.None:
                    nCompResult = xCpd._ID.CompareTo(yCpd._ID);
                    break;

                case SortOrder.ByIdAscending:
                    nCompResult = xCpd.PropertyId.CompareTo(yCpd.PropertyId);
                    break;

                case SortOrder.ByIdDescending:
                    nCompResult = xCpd.PropertyId.CompareTo(yCpd.PropertyId) * -1;
                    break;

                case SortOrder.ByNameAscending:
                    nCompResult = string.Compare(xCpd.DisplayName, yCpd.DisplayName, StringComparison.Ordinal);
                    break;

                case SortOrder.ByNameDescending:
                    nCompResult = string.Compare(xCpd.DisplayName, yCpd.DisplayName, StringComparison.Ordinal) * -1;
                    break;
            }
            return nCompResult;
        }
 public override PropertyDescriptorCollection GetProperties()
 {
     if (m_pdc.Count == 0)
     {
         var pdc = base.GetProperties();
         foreach (PropertyDescriptor pd in pdc)
         {
             if (!(pd is DynPropertyDescriptor))
             {
                 DynPropertyDescriptor dynPd;
                 if (pd.PropertyType.IsEnum)
                 {
                     dynPd = new EnumPropertyDescriptor(pd);
                 }
                 else if (pd.PropertyType == typeof(bool))
                 {
                     dynPd = new BooleanPropertyDescriptor(pd);
                 }
                 else
                 {
                     dynPd = new DynPropertyDescriptor(pd);
                 }
                 m_pdc.Add(dynPd);
             }
             else
             {
                 m_pdc.Add(pd);
             }
         }
     }
     return(m_pdc);
 }
Exemple #4
0
        public int Compare(object x, object y)
        {
            DynPropertyDescriptor xCpd = x as DynPropertyDescriptor;
            DynPropertyDescriptor yCpd = y as DynPropertyDescriptor;

            if (xCpd == null || yCpd == null)
            {
                return 0;
            }
            xCpd.AppendCount = 0;
            yCpd.AppendCount = 0;
            int nCompResult = 0;
            switch (m_CategorySortOrder)
            {
                case SortOrder.None:
                    nCompResult = 0;
                    break;

                case SortOrder.ByIdAscending:
                    nCompResult = xCpd.CategoryId.CompareTo(yCpd.CategoryId);
                    break;

                case SortOrder.ByIdDescending:
                    nCompResult = xCpd.CategoryId.CompareTo(yCpd.CategoryId) * -1;
                    break;

                case SortOrder.ByNameAscending:
                    nCompResult = string.Compare(xCpd.Category, yCpd.Category, StringComparison.Ordinal);
                    break;

                case SortOrder.ByNameDescending:
                    nCompResult = string.Compare(xCpd.Category, yCpd.Category, StringComparison.Ordinal) * -1;
                    break;
            }
            if (nCompResult == 0)
            {
                nCompResult = CompareProperty(xCpd, yCpd);
            }
            return nCompResult;
        }