コード例 #1
0
ファイル: Helpers.cs プロジェクト: pmq20/mono_forked
 public static EnumType ConvertEnum <EnumType> (string value, string attrName)
 {
     try {
         EnumConverter cvt = new EnumConverter(typeof(EnumType));
         return((EnumType)cvt.ConvertFromInvariantString(value));
     } catch (Exception) {
         throw new ApplicationException(
                   String.Format("Failed to parse the '{0}' attribute '{1}'", attrName, value));
     }
 }
コード例 #2
0
        public SettingsMapping(XPathNavigator nav)
        {
            _sectionTypeName = nav.GetAttribute("sectionType", String.Empty);
            _mapperTypeName  = nav.GetAttribute("mapperType", String.Empty);

            EnumConverter cvt = new EnumConverter(typeof(SettingsMappingPlatform));

            _platform = (SettingsMappingPlatform)cvt.ConvertFromInvariantString(nav.GetAttribute("platform", String.Empty));

            LoadContents(nav);
        }
コード例 #3
0
        internal static SettingsSerializeAs GetSerializeAs(string serializeAs)
        {
            var converter = new EnumConverter(typeof(SettingsSerializeAs));

            if (!String.IsNullOrEmpty(serializeAs))
            {
                return((SettingsSerializeAs)converter.ConvertFromInvariantString(serializeAs));
            }

            return(default(SettingsSerializeAs));
        }
コード例 #4
0
ファイル: Editor_InProc.cs プロジェクト: m0nguss/roslyn
        public void EditWinFormButtonProperty(string buttonName, string propertyName, string propertyValue, string propertyTypeName = null)
        {
            using (var waitHandle = new ManualResetEvent(false))
            {
                var designerHost           = (IDesignerHost)GetDTE().ActiveWindow.Object;
                var componentChangeService = (IComponentChangeService)designerHost;

                object GetEnumPropertyValue(string typeName, string value)
                {
                    var type      = Type.GetType(typeName);
                    var converter = new EnumConverter(type);

                    return(converter.ConvertFromInvariantString(value));
                }

                bool EqualToPropertyValue(object newValue)
                {
                    if (propertyTypeName == null)
                    {
                        return((newValue as string)?.Equals(propertyValue) == true);
                    }
                    else
                    {
                        var enumPropertyValue = GetEnumPropertyValue(propertyTypeName, propertyValue);
                        return(newValue?.Equals(enumPropertyValue) == true);
                    }
                }

                void ComponentChanged(object sender, ComponentChangedEventArgs e)
                {
                    if (e.Member.Name == propertyName && EqualToPropertyValue(e.NewValue))
                    {
                        waitHandle.Set();
                    }
                }

                componentChangeService.ComponentChanged += ComponentChanged;

                try
                {
                    InvokeOnUIThread(() =>
                    {
                        var button     = designerHost.Container.Components[buttonName];
                        var properties = TypeDescriptor.GetProperties(button);
                        var property   = properties[propertyName];
                        if (propertyTypeName == null)
                        {
                            property.SetValue(button, propertyValue);
                        }
                        else
                        {
                            var enumPropertyValue = GetEnumPropertyValue(propertyTypeName, propertyValue);
                            property.SetValue(button, enumPropertyValue);
                        }
                    });
                    waitHandle.WaitOne();
                }
                finally
                {
                    componentChangeService.ComponentChanged -= ComponentChanged;
                }
            }
        }