コード例 #1
0
        private void LoadSettings(object[] objects)
        {
            if (objects == null || objects.Length == 0)
            {
                this.Visible = false;
                this.SuspendLayout();
                mControls.Clear();
                this.ClearUI();
                this.ResumeLayout();
                return;
            }
            if (objects.Length == 1)
            {
                LoadSettings(objects[0]);
                return;
            }

            this.Visible = true;
            string parentType = "";

            List <Control> temp = new List <Control>();
            Dictionary <Type, TypeDescription> representedTypes = new Dictionary <Type, TypeDescription>();

            foreach (object obj in objects)
            {
                Type t = obj.GetType();
                if (mTypeDescriptions.ContainsKey(t) == false)
                {
                    mTypeDescriptions[t] = new TypeDescription(t);
                }
                representedTypes[t] = mTypeDescriptions[t];
            }

            Dictionary <KeyValuePair <string, Type>, int> mergedPropertyList = new Dictionary <KeyValuePair <string, Type>, int>();

            Dictionary <Type, TypeDescription> .Enumerator it = representedTypes.GetEnumerator();
            while (it.MoveNext())
            {
                if (representedTypes.Count == 1)
                {
                    parentType = it.Current.Key.Name;
                }

                foreach (PropertyInfo p in it.Current.Value.mPropertyInfoList)
                {
                    KeyValuePair <string, Type> info = new KeyValuePair <string, Type>(p.Name, p.PropertyType);
                    if (!mergedPropertyList.ContainsKey(info))
                    {
                        mergedPropertyList[info] = 0;
                    }
                    mergedPropertyList[info]++;
                }
                //it.Current.
            }

            List <ReflectedPropertyMultiBinder> mMultiBinders = new List <ReflectedPropertyMultiBinder>();

            Dictionary <KeyValuePair <string, Type>, int> .Enumerator itProps = mergedPropertyList.GetEnumerator();
            while (itProps.MoveNext())
            {
                if (itProps.Current.Value == representedTypes.Count)
                {
                    //mPropsByName
                    ReflectedPropertyMultiBinder b = new ReflectedPropertyMultiBinder(objects, itProps.Current.Key.Key, itProps.Current.Key.Value, representedTypes);
                    mMultiBinders.Add(b);
                }
            }


            mProps = new List <HighLevelProperty>();
            foreach (ReflectedPropertyMultiBinder b in mMultiBinders)
            {
                Dictionary <Type, TypeDescription> .Enumerator repTypes = representedTypes.GetEnumerator();
                while (repTypes.MoveNext())
                {
                    ApplyMetadata(b, repTypes.Current.Key.Name);
                }

                if (b.MetaData.ContainsKey("Ignore") && (bool)(b.MetaData["Ignore"]) == true)
                {
                    continue;
                }



                HighLevelProperty p = GetHighLevelProperty(b, parentType);//, t.Name);
                mProps.Add(p);
                string  bindName;
                Control c = p.GetEditor(out bindName);

                if (b.MetaData.ContainsKey("Alias"))
                {
                    c.Name = b.MetaData["Alias"].ToString();
                }
                else
                {
                    c.Name = b.GetName();
                }

                //Set editor properties:
                Type edtiorType = c.GetType();
                foreach (string s in b.MetaData.Keys)
                {
                    if (s.Contains("EditorProperty."))
                    {
                        string       editorProp         = s.Replace("EditorProperty.", "");
                        PropertyInfo editorPropertyInfo = edtiorType.GetProperty(editorProp);
                        object       convertedValue     = b.MetaData[s];
                        convertedValue = Convert.ChangeType(convertedValue, editorPropertyInfo.PropertyType);
                        editorPropertyInfo.SetValue(c, convertedValue, null);
                    }
                }

                //c.Name = b.GetName();
                temp.Add(c);
            }

            mControls.Clear();
            this.SuspendLayout();
            this.AddControls(temp);
            this.ResumeLayout();
        }
コード例 #2
0
        private void LoadSettings(object obj)
        {
            List <ReflectedPropertyBinder> mBinders = new List <ReflectedPropertyBinder>();

            if (obj == null)
            {
                this.Visible = false;
                this.SuspendLayout();

                //ClearUI();
                ClearUI();

                mControls.Clear();
                this.ResumeLayout();
                return;
            }

            if (obj is LambdaObject)
            {
                LoadSettings((LambdaObject)obj);
                return;
            }
            if (obj is LamdaObjectProperty)
            {
                LamdaObjectProperty lambdaprop = (LamdaObjectProperty)obj;
                this.ApplyMetaDataToType(lambdaprop.GetName(), lambdaprop.GetName(), lambdaprop.MetaData);
                LoadSettings((LambdaObject)lambdaprop.GetValue());
                return;
            }

            this.Visible = true;


            List <Control> temp = new List <Control>();

            Type t = obj.GetType();

            if (mTypeDescriptions.ContainsKey(t) == false)
            {
                mTypeDescriptions[t] = new TypeDescription(t);
            }

            mBinders = new List <ReflectedPropertyBinder>();
            foreach (PropertyInfo p in mTypeDescriptions[t].mPropertyInfoList)
            {
                ReflectedPropertyBinder b = new ReflectedPropertyBinder(obj, p);
                mBinders.Add(b);
            }
            mProps = new List <HighLevelProperty>();
            foreach (ReflectedPropertyBinder b in mBinders)
            {
                ApplyMetadata(b, t.Name);
                HighLevelProperty p = GetHighLevelProperty(b, t.Name);

                if (b.MetaData.ContainsKey("UpdateEvent"))
                {
                    p.Changed += new HighLevelProperty.HighLevelPropertyEvent(p_Changed);
                }

                p.Changed += new HighLevelProperty.HighLevelPropertyEvent(p_AnyChanged);

                if (b.MetaData.ContainsKey("Ignore") && (bool)(b.MetaData["Ignore"]) == true)
                {
                    continue;
                }

                mProps.Add(p);
                string  bindName;
                Control c = p.GetEditor(out bindName);

                if (b.MetaData.ContainsKey("Alias"))
                {
                    c.Name = b.MetaData["Alias"].ToString();
                }
                else
                {
                    c.Name = b.GetName();
                }

                //Set editor properties:
                Type edtiorType = c.GetType();
                foreach (string s in b.MetaData.Keys)
                {
                    if (s.Contains("EditorProperty."))
                    {
                        string       editorProp         = s.Replace("EditorProperty.", "");
                        PropertyInfo editorPropertyInfo = edtiorType.GetProperty(editorProp);
                        object       convertedValue     = b.MetaData[s];
                        convertedValue = Convert.ChangeType(convertedValue, editorPropertyInfo.PropertyType);
                        editorPropertyInfo.SetValue(c, convertedValue, null);
                    }
                }


                temp.Add(c);
            }

            //saving the ui changes for the end.  why is this so slow?
            this.SuspendLayout();
            mControls.Clear();

            this.AddControls(temp);

            this.ResumeLayout();
        }