当前位置: 首页>>代码示例>>C#>>正文


C# ITypeDescriptorContext.GetType方法代码示例

本文整理汇总了C#中ITypeDescriptorContext.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDescriptorContext.GetType方法的具体用法?C# ITypeDescriptorContext.GetType怎么用?C# ITypeDescriptorContext.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITypeDescriptorContext的用法示例。


在下文中一共展示了ITypeDescriptorContext.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertFrom

        /// <summary>
        ///     Convert a string like "Button.Click" into the corresponding RoutedEvent
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo,
                                           object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (s_ServiceProviderContextType == null)
            {
                // get typeof(MS.Internal.Xaml.ServiceProviderContext) via reflection
                Assembly a = typeof(IRootObjectProvider).Assembly;
                s_ServiceProviderContextType = a.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != s_ServiceProviderContextType)
            {
                // if the caller is not the XAML parser, don't answer.   This avoids
                // returning an arbitrary delegate to a (possibly malicious) caller.
                // See Dev11 629384.
                throw new ArgumentException(SR.Get(SRID.TextRange_InvalidParameterValue), "typeDescriptorContext");
            }
            IRootObjectProvider rootProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
            if (rootProvider != null && source is String)
            {
                IProvideValueTarget ipvt = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (ipvt != null)
                {
                    EventSetter setter = ipvt.TargetObject as EventSetter;
                    string handlerName;
                    if(setter != null && (handlerName = source as string) != null)
                    {
                        handlerName = handlerName.Trim();
                        return Delegate.CreateDelegate(setter.Event.HandlerType, rootProvider.RootObject, handlerName);
                    }
                }
            }

            throw GetConvertFromException(source);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:46,代码来源:EventSetterHandlerConverter.cs

示例2: EditValue

 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     string propertyGridName;
     object obj2 = context.GetType().GetProperty("OwnerGrid").GetValue(context, null);
     if ((obj2 != null) && (obj2 is PropertyGrid))
     {
         propertyGridName = ((PropertyGrid) obj2).Text;
     }
     else
     {
         return value;
     }
     string propertyName = context.PropertyDescriptor.Category;
     string categoryName = context.PropertyDescriptor.DisplayName;
     this.wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
     string key = PropertyComboBox.getComboBoxID(propertyGridName, propertyName, categoryName);
     if ((this.wfes != null) && PropertyComboBox.s_htLists.ContainsKey(key))
     {
         propertyList pi = (propertyList) PropertyComboBox.s_htLists[key];
         if (pi == null)
         {
             return value;
         }
         this.fillListBox(pi, value);
         this.lb.Sorted = pi.isAutoSort;
         this.lb.BorderStyle = BorderStyle.FixedSingle;
         this.lb.DoubleClick += new EventHandler(this.lb_DoubleClick);
         this.lb.Click += new EventHandler(this.lb_Click);
         this.wfes.DropDownControl(this.lb);
         this.setSelectedItem(pi, key);
         if (this.lb.SelectedItem != null)
         {
             value = this.lb.SelectedItem;
         }
     }
     return value;
 }
开发者ID:xiaoyj,项目名称:Space,代码行数:37,代码来源:UITypeComboBox.cs

示例3: TryGetPropertyGridAccessibleObject

        /// <summary>
        /// Gets the AccessibilityObject from a PropertyGrid.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The AccessibilityObject, or null if invalid or not of the correct type.</returns>
        static object TryGetPropertyGridAccessibleObject(ITypeDescriptorContext context)
        {
            const BindingFlags flags =
                BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance;

            if (context == null)
                return null;

            try
            {
                // Check for the PropertyDescriptorGridEntry type
                if (context.GetType().FullName == "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                {
                    // Get the AccessibileObject from the AcccessibilityObject property
                    var propAccessibilityObject = context.GetType().GetProperty("AccessibilityObject", flags);
                    if (propAccessibilityObject == null)
                        return null;

                    var accessibleObject = propAccessibilityObject.GetValue(context, null);
                    return accessibleObject;
                }
            }
            catch (InvalidCastException)
            {
                return null;
            }
            catch (TargetException)
            {
                return null;
            }
            catch (TargetInvocationException)
            {
                return null;
            }
            catch (ArgumentNullException)
            {
                return null;
            }
            catch (ArgumentException)
            {
                return null;
            }

            return null;
        }
开发者ID:wtfcolt,项目名称:game,代码行数:50,代码来源:ITypeDescriptorContextExtensions.cs

示例4: GetStandardValues

 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     PropertyInfo propInfo = context.GetType().GetProperty("OwnerGrid");
     PropertyGrid propGrid = propInfo.GetValue(context, null) as PropertyGrid;
     snConfig snConfig = propGrid.Tag as snConfig;
     List<String> retVal = new List<String>();
     foreach (object action in snConfig.devices.Items)
     {
         PropertyInfo namePropertyInfo = action.GetType().GetProperty("name");
         String name = namePropertyInfo.GetValue(action, null) as String;
         retVal.Add(name);
     }
     return new StandardValuesCollection(retVal);
 }
开发者ID:rgeyer,项目名称:SpaceNavigatorHIDCapture,代码行数:14,代码来源:snconfig.cs

示例5: EditValue

        public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService wfes = (IWindowsFormsEditorService)provider.GetService(
                typeof(IWindowsFormsEditorService));

            if (wfes != null)
            {
                SliderForm sliderForm = new SliderForm();
                // type+category+displayedName
                String key = context.PropertyDescriptor.ComponentType.Name + context.PropertyDescriptor.Category + context.PropertyDescriptor.DisplayName;
                bool maxOK = false, minOK = false;
                if (maximumValue.ContainsKey(key))
                {
                    sliderForm.trackBar.Maximum = maximumValue[key];
                    maxOK = true;
                }
                if (minimumValue.ContainsKey(key))
                {
                    sliderForm.trackBar.Minimum = minimumValue[key];
                    minOK = true;
                }

                if (!minOK || !maxOK)
                {
                    CustomPropertyGrid parentGrid;
                    PropertyInfo piOwnerGrid = context.GetType().GetProperty("OwnerGrid");
                    Object grid = piOwnerGrid.GetValue(context, null);
                    if ((grid != null) && (grid is CustomPropertyGrid))
                    {
                        parentGrid = (CustomPropertyGrid)grid;
                    }
                    else
                    {
                        parentGrid = null;
                    }
                    if (parentGrid != null)
                    {
                        // try and get the parameter info to check for constraints - to set min and max
                        IXPathNavigable iNav = parentGrid.Controller.GetParametersForComponent(parentGrid.SelectedID);
                        XPathNavigator nav = iNav.CreateNavigator();
                        XPathNodeIterator constraints = nav.Select("ComponentParameters/Parameter[@category='" + context.PropertyDescriptor.Category +
                            "']/Parameter[@displayedName='" + context.PropertyDescriptor.DisplayName + "']/Constraints/Constraint");

                        foreach (XPathNavigator constraint in constraints)
                        {
                            String constraintName = constraint.GetAttribute(ConfigFileConstants.constraintName, "");
                            String constraintValue = constraint.GetAttribute(ConfigFileConstants.constraintValue, "");
                            Int32 parse;
                            if (constraintName.Equals(ConfigFileConstants.maxConstraint))
                            {
                                parse = Int32.Parse(constraintValue);
                                sliderForm.trackBar.Maximum = parse;
                                maximumValue.Add(key, parse); // save so we don't have to reprocess this every time
                            }
                            else if (constraintName.Equals(ConfigFileConstants.minConstraint))
                            {
                                parse = Int32.Parse(constraintValue);
                                sliderForm.trackBar.Minimum = parse;
                                minimumValue.Add(key, parse);
                            }
                        }
                    }
                }

                sliderForm.trackBar.Value = (int)value;
                sliderForm.wfes = wfes;

                wfes.DropDownControl(sliderForm);

                value = sliderForm.trackBar.Value;
            }
            return value;
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:74,代码来源:SliderEditor.cs


注:本文中的ITypeDescriptorContext.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。