Exemplo n.º 1
0
        public static string ModelPropertyList(object obj, string lineDelimeter, string[] includes, string[] excludes)
        {
            Type t     = obj.GetType();
            var  props = t.GetProperties();
            var  sb    = new StringBuilder();

            foreach (var p in props)
            {
                if (excludes != null && Array.Exists(excludes, element => element == p.Name))
                {
                    continue;
                }
                if (includes != null && !Array.Exists(includes, element => element == p.Name))
                {
                    continue;
                }
                JIgnore ignoreAttr = AttrHelper.GetAttribute <JIgnore>(t, p.Name);
                if (ignoreAttr != null)
                {
                    continue;
                }
                string desc = GetPropertyJDescriptionOrName(p);
                object v    = Dm.Instance.GetCustomPropertyValue(obj, p.Name, true, -1, -1);
                if (v != null)
                {
                    sb.Append(desc + ": " + v);
                    if (lineDelimeter != null)
                    {
                        sb.Append(lineDelimeter);
                    }
                    sb.AppendLine();
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        override public void ProcessView()
        {
            if (SourceObjectType != null)
            {
                string descr = ModelHelper.GetEntityJDescriptionOrName(SourceObjectType);
                SetNewCaption(descr + " " + FrwCRUDRes.SimplePropertyWindow_Props);
            }
            if (tempSourceObject != null)
            {
                if (tempSourceObject.GetType().Equals(SourceObjectType) == false)
                {
                    throw new ArgumentException("SourceObject not of SourceObjectType");
                }

                bag1                  = new PropertyBag();
                bag1.GetValue        += new PropertySpecEventHandler(this.bag1_GetValue);
                bag1.SetValue        += new PropertySpecEventHandler(this.bag1_SetValue);
                bag1.ValueModified   += Bag1_ValueModified;
                bag1.SourceObject     = tempSourceObject;
                bag1.SourceObjectType = SourceObjectType;

                PropertyInfo[] propsList = AttrHelper.GetBasePropertiesFirst(tempSourceObject.GetType());
                PropertyInfo   pName     = AttrHelper.GetProperty <JNameProperty>(tempSourceObject.GetType());
                if (pName != null)
                {
                    propsList = propsList.OrderBy(x => x != pName).ToArray();
                }

                PropertySpec props = null;
                foreach (PropertyInfo p in propsList)
                {
                    if (AttrHelper.IsGenericListTypeOf(p.PropertyType, typeof(IField)))
                    {
                        IList itemDatas = (IList)p.GetValue(tempSourceObject);
                        if (itemDatas != null)
                        {
                            foreach (var it in itemDatas)
                            {
                                IField itemdata = (IField)it;
                                string group    = null;

                                props = new PropertySpec(ITEM_ATTRIBUTE_PREFIX + itemdata.FieldSysname, typeof(string), group,
                                                         itemdata.Name);
                                props.PropTag = itemdata;
                                if (viewMode == ViewMode.View || viewMode == ViewMode.ViewContent)
                                {
                                    props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) };
                                }
                                bag1.Properties.Add(props);
                            }
                        }
                    }
                    else
                    {
                        JReadOnly readOnlyAttr = AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, p.Name);
                        JIgnore   ignoreAttr   = AttrHelper.GetAttribute <JIgnore>(SourceObjectType, p.Name);

                        if (ignoreAttr != null)
                        {
                            continue;
                        }

                        string desc         = ModelHelper.GetPropertyJDescriptionOrName(p);
                        bool   isCustomEdit = false;
                        if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, p.Name))
                        {
                            isCustomEdit = true;
                        }
                        Type pType = null;
                        if (isCustomEdit)
                        {
                            pType = typeof(string);              //disabled comboboxes for list type fields
                        }
                        else
                        {
                            pType = p.PropertyType;
                        }
                        props         = new PropertySpec(desc, pType, null, desc);
                        props.PropTag = p.Name;
                        if (readOnlyAttr != null || viewMode == ViewMode.View || viewMode == ViewMode.ViewContent)
                        {
                            props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) };
                        }
                        if (isCustomEdit)
                        {
                            //not only for edit
                            props.EditorTypeName = typeof(CustomPropertyEditor).ToString();
                        }

                        bag1.Properties.Add(props);
                    }

                    this.propertyGrid1.SelectedObjects = new object[] { bag1 };
                }
            }
            else
            {
                this.propertyGrid1.SelectedObjects = null;
            }
        }