public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     object[] objArray1 = null;
     if (context != null)
     {
         IComponent component1 = context.Instance as IComponent;
         if (component1 != null)
         {
             ISite site1 = component1.Site;
             if (site1 != null)
             {
                 IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost));
                 if (host1 != null)
                 {
                     IDesigner designer1          = host1.GetDesigner(component1);
                     DesignerDataSourceView view1 = this.GetView(designer1);
                     if (view1 != null)
                     {
                         IDataSourceViewSchema schema1 = null;
                         try
                         {
                             schema1 = view1.Schema;
                         }
                         catch (Exception exception1)
                         {
                             IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService));
                             if (service1 != null)
                             {
                                 service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString());
                             }
                         }
                         if (schema1 != null)
                         {
                             IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields();
                             if (schemaArray1 != null)
                             {
                                 objArray1 = new object[schemaArray1.Length];
                                 for (int num1 = 0; num1 < schemaArray1.Length; num1++)
                                 {
                                     objArray1[num1] = schemaArray1[num1].Name;
                                 }
                             }
                         }
                     }
                     if (((objArray1 == null) && (designer1 != null)) && (designer1 is IDataSourceProvider))
                     {
                         IDataSourceProvider provider1   = designer1 as IDataSourceProvider;
                         IEnumerable         enumerable1 = null;
                         if (provider1 != null)
                         {
                             enumerable1 = provider1.GetResolvedSelectedDataSource();
                         }
                         if (enumerable1 != null)
                         {
                             PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1);
                             if (collection1 != null)
                             {
                                 ArrayList list1 = new ArrayList();
                                 foreach (PropertyDescriptor descriptor1 in collection1)
                                 {
                                     list1.Add(descriptor1.Name);
                                 }
                                 objArray1 = list1.ToArray();
                             }
                         }
                     }
                 }
             }
         }
     }
     return(new TypeConverter.StandardValuesCollection(objArray1));
 }
Exemplo n.º 2
0
        /// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValues"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Gets the fields present within the selected data source if information about them is available.
        ///    </para>
        /// </devdoc>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            object[]   names                 = null;
            String     dataMember            = null;
            bool       autoGenerateFields    = false;
            bool       autoGenerateFieldsSet = false;
            ObjectList objectList            = null;

            if (context != null)
            {
                ArrayList list = new ArrayList();

                PropertyDescriptorCollection props = null;

                IComponent component = context.Instance as IComponent;
                if (component is IDeviceSpecificChoiceDesigner)
                {
                    Object             owner = ((ChoicePropertyFilter)component).Owner;
                    PropertyDescriptor pd    =
                        ((ICustomTypeDescriptor)component).GetProperties()[_dataMemberPropertyName];
                    Debug.Assert(pd != null, "Cannot get DataMember");

                    if (owner is ObjectList)
                    {
                        autoGenerateFields    = ((ObjectList)owner).AutoGenerateFields;
                        autoGenerateFieldsSet = true;
                    }

                    component = ((IDeviceSpecificChoiceDesigner)component).UnderlyingControl;

                    // See if owner already has a DataMember
                    dataMember = (String)pd.GetValue(owner);
                    Debug.Assert(dataMember != null);
                    if (dataMember == String.Empty)
                    {
                        // Get it from underlying object.
                        dataMember = (String)pd.GetValue(component);
                        Debug.Assert(dataMember != null);
                    }
                }

                if (component != null)
                {
                    objectList = component as ObjectList;

                    if (objectList != null)
                    {
                        foreach (ObjectListField field in objectList.Fields)
                        {
                            list.Add(field.Name);
                        }

                        if (!autoGenerateFieldsSet)
                        {
                            autoGenerateFields = objectList.AutoGenerateFields;
                        }
                    }

                    if (objectList == null || autoGenerateFields)
                    {
                        ISite componentSite = component.Site;
                        if (componentSite != null)
                        {
                            IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost));
                            if (designerHost != null)
                            {
                                IDesigner designer = designerHost.GetDesigner(component);

                                if (designer is IDataSourceProvider)
                                {
                                    IEnumerable dataSource = null;
                                    if (dataMember != null && dataMember != String.Empty)
                                    {
                                        DataBindingCollection dataBindings =
                                            ((HtmlControlDesigner)designer).DataBindings;
                                        DataBinding binding = dataBindings[_dataSourcePropertyName];
                                        if (binding != null)
                                        {
                                            dataSource =
                                                DesignTimeData.GetSelectedDataSource(
                                                    component,
                                                    binding.Expression,
                                                    dataMember);
                                        }
                                    }
                                    else
                                    {
                                        dataSource =
                                            ((IDataSourceProvider)designer).GetResolvedSelectedDataSource();
                                    }

                                    if (dataSource != null)
                                    {
                                        props = DesignTimeData.GetDataFields(dataSource);
                                    }
                                }
                            }
                        }
                    }
                }

                if (props != null)
                {
                    foreach (PropertyDescriptor propDesc in props)
                    {
                        list.Add(propDesc.Name);
                    }
                }

                names = list.ToArray();
                Array.Sort(names);
            }
            return(new StandardValuesCollection(names));
        }
            public StringCollection GetStandardValues(Component component)
            {
                StringCollection fields = new StringCollection();

                if (component != null)
                {
                    ISite site1 = component.Site;
                    if (site1 != null)
                    {
                        IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost));
                        if (host1 != null)
                        {
                            IDesigner designer1          = host1.GetDesigner(component);
                            DesignerDataSourceView view1 = ((DataBoundControlDesigner)designer1).DesignerView;
                            if (view1 != null)
                            {
                                IDataSourceViewSchema schema1 = null;
                                try
                                {
                                    schema1 = view1.Schema;
                                }
                                catch (Exception exception1)
                                {
                                    IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService));
                                    if (service1 != null)
                                    {
                                        service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString());
                                    }
                                }
                                if (schema1 != null)
                                {
                                    IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields();
                                    if (schemaArray1 != null)
                                    {
                                        for (int num1 = 0; num1 < schemaArray1.Length; num1++)
                                        {
                                            fields.Add(schemaArray1[num1].Name);
                                        }
                                    }
                                }
                            }
                            if (((fields.Count == 0) && (designer1 != null)) && (designer1 is IDataSourceProvider))
                            {
                                IDataSourceProvider provider1   = designer1 as IDataSourceProvider;
                                IEnumerable         enumerable1 = null;
                                if (provider1 != null)
                                {
                                    enumerable1 = provider1.GetResolvedSelectedDataSource();
                                }
                                if (enumerable1 != null)
                                {
                                    PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1);
                                    if (collection1 != null)
                                    {
                                        foreach (PropertyDescriptor descriptor1 in collection1)
                                        {
                                            fields.Add(descriptor1.Name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(fields);
            }