Пример #1
0
        public void Connect(IWindowlessControl control)
        {
            Type type = GetType();

            WindowlessControlHost.RecurseWindowlessControls(control, (current) =>
            {
                if (string.IsNullOrEmpty(current.Name))
                {
                    return(true);
                }

                PropertyInfo prop = type.GetProperty(current.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if (prop != null)
                {
                    if (prop.GetValue(this, null) != null)
                    {
                        throw new InvalidOperationException(string.Format("Unable to connect to property {0}. The value is non-null", current.Name));
                    }
                    prop.SetValue(this, current, null);
                    return(true);
                }

                FieldInfo field = type.GetField(current.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if (field != null)
                {
                    if (field.GetValue(this) != null)
                    {
                        throw new InvalidOperationException(string.Format("Unable to connect to field {0}. The value is non-null", current.Name));
                    }
                    field.SetValue(this, current);
                }
                return(true);
            },
                                                            null);
        }