public static bool _ConvertToString_System_ComponentModel_TypeConverter_System_ComponentModel_ITypeDescriptorContext_System_Globalization_CultureInfo_System_Object( ) { //class object System.ComponentModel.TypeConverter _System_ComponentModel_TypeConverter = new System.ComponentModel.TypeConverter(); //Parameters System.ComponentModel.ITypeDescriptorContext context = null; System.Globalization.CultureInfo culture = null; System.Object _value = null; //ReturnType/Value System.String returnVal_Real = null; System.String returnVal_Intercepted = null; //Exception System.Exception exception_Real = null; System.Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnVal_Real = _System_ComponentModel_TypeConverter.ConvertToString(context, culture, _value); } catch (System.Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnVal_Intercepted = _System_ComponentModel_TypeConverter.ConvertToString(context, culture, _value); } catch (System.Exception e) { exception_Intercepted = e; } return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
public static string GetColorString(Color color) { // Create the ColorConverter. System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Color)); return(converter.ConvertToString(color)); }
public static bool _ConvertToString_System_ComponentModel_TypeConverter_System_ComponentModel_ITypeDescriptorContext_System_Object( ) { //class object System.ComponentModel.TypeConverter _System_ComponentModel_TypeConverter = new System.ComponentModel.TypeConverter(); //Parameters System.ComponentModel.ITypeDescriptorContext context = null; System.Object _value = null; //ReturnType/Value System.String returnVal_Real = null; System.String returnVal_Intercepted = null; //Exception System.Exception exception_Real = null; System.Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnVal_Real = _System_ComponentModel_TypeConverter.ConvertToString(context,_value); } catch( System.Exception e ) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnVal_Intercepted = _System_ComponentModel_TypeConverter.ConvertToString(context,_value); } catch( System.Exception e ) { exception_Intercepted = e; } return( ( exception_Real.Messsage == exception_Intercepted.Message ) && ( returnValue_Real == returnValue_Intercepted ) ); }
private void btnSaveChanges_Click(object sender, RoutedEventArgs e) { System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(ddColor.Color); var dueDateColorData = converter.ConvertToString(ddColor.Color); System.ComponentModel.TypeConverter converter2 = System.ComponentModel.TypeDescriptor.GetConverter(ccMessage.Color); var messageTextColor = converter2.ConvertToString(ccMessage.Color); System.ComponentModel.TypeConverter converter3 = System.ComponentModel.TypeDescriptor.GetConverter(backgroundDueDate.Color); var BackgroundDueDateColor = converter3.ConvertToString(backgroundDueDate.Color); System.ComponentModel.TypeConverter converter4 = System.ComponentModel.TypeDescriptor.GetConverter(backgroundMessageColor.Color); var BackgroundMessageColor = converter4.ConvertToString(backgroundMessageColor.Color); string dueDate = ""; string companyLogo = ""; if (dpDueDate.SelectedDate != null) { dueDate = dpDueDate.SelectedDate.Value.ToString(); } if (!String.IsNullOrWhiteSpace(screenSettings.CompanyLogo)) { companyLogo = screenSettings.CompanyLogo; } screenSettings = new ScreenSaverSettings() { Message = txtMessage.Text, DueDateMessage = txtDueDateMessage.Text, DueDate = dueDate, CompanyLogo = companyLogo, DueDateTextColor = dueDateColorData, MessageTextColor = messageTextColor, BackgroundDueDateColor = BackgroundDueDateColor, BackgroundMessageColor = BackgroundMessageColor }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(screenSettings); try { var sw = new StreamWriter(@"c:\screen\data.enigma"); sw.Write(json); sw.Close(); } catch (Exception exp) { MessageBox.Show(exp.Message, "Unable to write to directory"); } this.Close(); }
// 获得一个描述字体的字符串 public static string GetFontString(Font font) { if (font == null) { return(""); // Convertor 会返回 (无) } // Create the FontConverter. System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font)); return(converter.ConvertToString(font)); }
private void tsmiFontSetting_Click(object sender, EventArgs e) { fontDialog.ShowDialog(); this.Font = fontDialog.Font; System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font)); var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["fontSettings"].Value = converter.ConvertToString(this.Font); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { if (destinationType == null) { throw new System.ArgumentNullException("destinationType"); } if (value is Padding) { if (destinationType == typeof(string)) { Padding padding = (Padding)value; if (culture == null) { culture = System.Globalization.CultureInfo.CurrentCulture; } string separator = culture.TextInfo.ListSeparator + " "; System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(int)); string[] strArray = new string[4]; int num = 0; strArray[num++] = converter.ConvertToString(context, culture, padding.Left); strArray[num++] = converter.ConvertToString(context, culture, padding.Top); strArray[num++] = converter.ConvertToString(context, culture, padding.Right); strArray[num++] = converter.ConvertToString(context, culture, padding.Bottom); return(string.Join(separator, strArray)); } if (destinationType == typeof(InstanceDescriptor)) { Padding padding2 = (Padding)value; if (padding2.ShouldSerializeAll()) { return(new InstanceDescriptor(typeof(Padding).GetConstructor(new System.Type[] { typeof(int) }), new object[] { padding2.All })); } return(new InstanceDescriptor(typeof(Padding).GetConstructor(new System.Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }), new object[] { padding2.Left, padding2.Top, padding2.Right, padding2.Bottom })); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public static void GetFieldInfoValuesLine(object data, out string fieldInfoValue) { List <string> stringData = new List <string>(); Type t = data.GetType(); System.Reflection.FieldInfo[] finfos = data.GetType().GetFields(); fieldInfoValue = ""; for (int i = 0; i < finfos.Length; i++) { if (getDescriptionNames(finfos[i]) == null) { continue; } if (finfos[i].Name == "ConfigId") { System.ComponentModel.TypeConverter typeConverter = getTypeConverter(finfos[i]); string valueString = typeConverter.ConvertToString(finfos[i].GetValue(data)); fieldInfoValue += valueString + ","; break; } } for (int i = 0; i < finfos.Length; i++) { if (finfos[i].Name == "ConfigId") { continue; } if (getDescriptionNames(finfos[i]) == null) { continue; } if (finfos[i].FieldType.IsClass || finfos[i].FieldType.IsGenericType) { if (finfos[i].FieldType != typeof(string)) { GetGeneraterAndCreate(finfos[i].FieldType.ToString(), finfos[i].GetValue(data)); } } System.ComponentModel.TypeConverter typeConverter = getTypeConverter(finfos[i]); string valueString = typeConverter.ConvertToString(finfos[i].GetValue(data)); fieldInfoValue += valueString + ","; } }
/// <summary> /// Converts a type to string if possible. This method supports an optional culture generically on any value. /// It calls the ToString() method on common types and uses a type converter on all other objects /// if available /// </summary> /// <param name="RawValue">The Value or Object to convert to a string</param> /// <param name="Culture">Culture for numeric and DateTime values</param> /// <returns>string</returns> public static string TypedValueToString(object RawValue, CultureInfo Culture) { Type ValueType = RawValue.GetType(); string Return = null; if (ValueType == typeof(string)) { Return = RawValue.ToString(); } else if (ValueType == typeof(int) || ValueType == typeof(decimal) || ValueType == typeof(double) || ValueType == typeof(float)) { Return = string.Format(Culture.NumberFormat, "{0}", RawValue); } else if (ValueType == typeof(DateTime)) { Return = string.Format(Culture.DateTimeFormat, "{0}", RawValue); } else if (ValueType == typeof(bool)) { Return = RawValue.ToString(); } else if (ValueType == typeof(byte)) { Return = RawValue.ToString(); } else if (ValueType.IsEnum) { Return = RawValue.ToString(); } else { // Any type that supports a type converter System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(ValueType); if (converter != null && converter.CanConvertTo(typeof(string))) { Return = converter.ConvertToString(null, Culture, RawValue); } else { // Last resort - just call ToString() on unknown type Return = RawValue.ToString(); } } return(Return); }
private string ConvertToString(System.Drawing.Font font) { try { if (font != null) { System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(System.Drawing.Font)); return(converter.ConvertToString(font)); } else { return(null); } } catch { System.Diagnostics.Debug.WriteLine("Unable to convert"); } return(null); }
public static string GetValueString(object value, System.ComponentModel.TypeConverter converter) { if (value == null) { return(string.Empty); } if (value is string) { return((string)value); } if (converter != null) { return(converter.ConvertToString(value)); } else { return(JF.Common.Convert.ConvertValue <string>(value)); } }
public void saveFont(Font font) { fontstr = converter.ConvertToString(font); }
/// <summary> /// 指定したオブジェクトを指定した型として文字列に変換します。 /// </summary> /// <param name="t">変換元のオブジェクトの型を指定します。</param> /// <param name="value">変換元のオブジェクトを指定します。</param> /// <returns>変換後の文字列を返します。</returns> public static string From(System.Type t, object value) { switch (Types.GetTypeCode(t)) { case TypeCodes.SByte: return(FromSByte((sbyte)value)); case TypeCodes.Byte: return(FromByte((byte)value)); case TypeCodes.Short: return(FromInt16((short)value)); case TypeCodes.UShort: return(FromUInt16((ushort)value)); case TypeCodes.Int: return(FromInt32((int)value)); case TypeCodes.UInt: return(FromUInt32((uint)value)); case TypeCodes.Long: return(FromInt64((long)value)); case TypeCodes.ULong: return(FromUInt64((ulong)value)); case TypeCodes.Decimal: return(FromDecimal((decimal)value)); case TypeCodes.Float: return(FromSingle((float)value)); case TypeCodes.Double: return(FromDouble((double)value)); case TypeCodes.Bool: return(FromBoolean((bool)value)); case TypeCodes.Char: return(FromChar((char)value)); case TypeCodes.String: return((string)value); case TypeCodes.Guid: return(FromGuid((System.Guid)value)); case TypeCodes.TimeSpan: return(FromTimeSpan((System.TimeSpan)value)); //.NET Framework 2.0 : System.Xml.XmlDateTimeSerializationMode を指定 case TypeCodes.DateTime: return(FromDateTime((System.DateTime)value)); case TypeCodes.IntPtr: return(FromInt64((long)(System.IntPtr)value)); case TypeCodes.UIntPtr: return(FromUInt64((ulong)(System.UIntPtr)value)); case TypeCodes.BoolArray: return(FromBooleanArray((bool[])value)); case TypeCodes.ByteArray: return(FromByteArray((byte[])value)); case TypeCodes.Type: return(((System.Type)value).FullName); default: // typeconv: if (t.IsEnum) { return(value.ToString()); //System.Enum } if (t.GetCustomAttributes(typeof(System.ComponentModel.TypeConverterAttribute), false).Length == 0) { goto serial; } System.ComponentModel.TypeConverter conv = System.ComponentModel.TypeDescriptor.GetConverter(t); if (conv.CanConvertTo(typeof(string)) && conv.CanConvertFrom(typeof(string))) { try{ return(conv.ConvertToString(value)); }catch {} } serial: if (t.GetCustomAttributes(typeof(System.SerializableAttribute), false).Length == 0) { goto op_implicit; } using (System.IO.MemoryStream memstr = new System.IO.MemoryStream()){ binF.Serialize(memstr, value); //--長さ int len; try{ len = (int)memstr.Length; }catch (System.Exception e) { throw new System.Exception("データの量が大きすぎるので文字列に変換できません", e); } //--文字列に変換 byte[] buff = new byte[len]; memstr.Position = 0; memstr.Read(buff, 0, len); return(System.Convert.ToBase64String(buff)); } op_implicit: System.Reflection.MethodInfo[] ms = t.GetMethods(BF_PublicStatic); for (int i = 0; i < ms.Length; i++) { if (ms[i].Name != "op_Implicit" || ms[i].ReturnType != typeof(string)) { continue; } System.Reflection.ParameterInfo[] ps = ms[i].GetParameters(); if (ps.Length != 1 || ps[0].ParameterType != t) { continue; } return((string)ms[i].Invoke(null, new object[] { value })); } throw new System.ArgumentException(string.Format(TOSTR_NOTSUPPORTEDTYPE, t), "t"); } }
/// <summary> /// 指定したオブジェクトを指定した型として文字列に変換します。 /// </summary> /// <param name="t">変換元のオブジェクトの型を指定します。</param> /// <param name="value">変換元のオブジェクトを指定します。</param> /// <returns>変換後の文字列を返します。</returns> public static string ToString(System.Type t, object value) { switch (t.FullName.GetHashCode() & 0x7fffffff) { case 0x038D0F82: if (t != typeof(System.Int16)) { goto default; } return(System.Convert.ToString((System.Int16)value)); case 0x6D318EFD: if (t != typeof(System.UInt16)) { goto default; } return(System.Convert.ToString((System.UInt16)value)); case 0x1B47F8B8: if (t != typeof(System.Int32)) { goto default; } return(System.Convert.ToString((System.Int32)value)); case 0x03FB8EF9: if (t != typeof(System.UInt32)) { goto default; } return(System.Convert.ToString((System.UInt32)value)); case 0x4A1B9AE7: if (t != typeof(System.Int64)) { goto default; } return(System.Convert.ToString((System.Int64)value)); case 0x61CC8EFB: if (t != typeof(System.UInt64)) { goto default; } return(System.Convert.ToString((System.UInt64)value)); case 0x4EE7D89D: if (t != typeof(System.SByte)) { goto default; } return(System.Convert.ToString((System.SByte)value)); case 0x2F001A17: if (t != typeof(System.Byte)) { goto default; } return(System.Convert.ToString((System.Byte)value)); case 0x1B1EFB13: if (t != typeof(System.Decimal)) { goto default; } return(System.Convert.ToString((System.Decimal)value)); case 0x44059415: if (t != typeof(System.Char)) { goto default; } return(System.Convert.ToString((System.Char)value)); case 0x3EACB635: if (t != typeof(System.Single)) { goto default; } return(System.Convert.ToString((System.Single)value)); case 0x0ED5FC72: if (t != typeof(System.Double)) { goto default; } return(System.Convert.ToString((System.Double)value)); case 0x71309BFC: if (t != typeof(System.Boolean)) { goto default; } return(System.Convert.ToString((System.Boolean)value)); case 0x5981F920: if (t != typeof(System.String)) { goto default; } return((string)value); case 0x1D77C984: if (t != typeof(System.IntPtr)) { goto default; } return(System.Convert.ToString((System.Int64)value)); case 0x65648F3B: if (t != typeof(System.UIntPtr)) { goto default; } return(System.Convert.ToString((System.UInt64)value)); case 0x29BD8EB6: if (t != typeof(System.Guid)) { goto default; } return(System.Xml.XmlConvert.ToString((System.Guid)value)); case 0x1FE98930: if (t != typeof(System.TimeSpan)) { goto default; } return(System.Xml.XmlConvert.ToString((System.TimeSpan)value)); case 0x4A398CD8: if (t != typeof(System.DateTime)) { goto default; } //.NET Framework 2.0 : System.Xml.XmlDateTimeSerializationMode を指定 return(System.Convert.ToString((System.DateTime)value)); case 0x7F721A17: if (t != typeof(System.Type)) { goto default; } return(((System.Type)value).FullName); case 0x0458EA59: if (t != typeof(System.Boolean[])) { goto default; } return(ToString((bool[])value)); default: // typeconv: if (t.IsEnum) { return(value.ToString()); //System.Enum } if (t.GetCustomAttributes(typeof(System.ComponentModel.TypeConverterAttribute), false).Length == 0) { goto serial; } System.ComponentModel.TypeConverter conv = System.ComponentModel.TypeDescriptor.GetConverter(t); if (conv.CanConvertTo(typeof(string)) && conv.CanConvertFrom(typeof(string))) { try{ return(conv.ConvertToString(value)); }catch {} } serial: if (t.GetCustomAttributes(typeof(System.SerializableAttribute), false).Length == 0) { goto op_implicit; } using (System.IO.MemoryStream memstr = new System.IO.MemoryStream()){ Convert.binF.Serialize(memstr, value); //--長さ int len; try{ len = (int)memstr.Length; }catch (System.Exception e) { throw new System.Exception("データの量が大きすぎるので文字列に変換できません", e); } //--文字列に変換 byte[] buff = new byte[len]; memstr.Position = 0; memstr.Read(buff, 0, len); return(System.Convert.ToBase64String(buff)); } op_implicit: System.Reflection.MethodInfo[] ms = t.GetMethods(BF_PublicStatic); for (int i = 0; i < ms.Length; i++) { if (ms[i].Name != "op_Implicit" || ms[i].ReturnType != typeof(string)) { continue; } System.Reflection.ParameterInfo[] ps = ms[i].GetParameters(); if (ps.Length != 1 || ps[0].ParameterType != t) { continue; } return((string)ms[i].Invoke(null, new object[] { value })); } throw new System.ArgumentException(string.Format(TOSTR_NOTSUPPORTEDTYPE, t), "t"); } #if NET1_1 switch (t.FullName.GetHashCode() & 0x7fffffff) { case 0x2DBDA61A: //case 0xE31638: if (t != typeof(System.Int16)) { goto default; } return(System.Convert.ToString((System.Int16)value)); case 0x1107D7EF: //case 0xE3166C: if (t != typeof(System.UInt16)) { goto default; } return(System.Convert.ToString((System.UInt16)value)); case 0x2DBDA65C: //case 0xE312F4: if (t != typeof(System.Int32)) { goto default; } return(System.Convert.ToString((System.Int32)value)); case 0x1107D829: //case 0xE316A0: if (t != typeof(System.UInt32)) { goto default; } return(System.Convert.ToString((System.UInt32)value)); case 0x2DBDA63F: //case 0xE316D4: if (t != typeof(System.Int64)) { goto default; } return(System.Convert.ToString((System.Int64)value)); case 0x1107D84A: //case 0xE31708: if (t != typeof(System.UInt64)) { goto default; } return(System.Convert.ToString((System.UInt64)value)); case 0x2EF00F97: //case 0xE315D0: if (t != typeof(System.SByte)) { goto default; } return(System.Convert.ToString((System.SByte)value)); case 0x244D3E44: //case 0xE31604: if (t != typeof(System.Byte)) { goto default; } return(System.Convert.ToString((System.Byte)value)); case 0x32C73145: //case 0xE317A4: if (t != typeof(System.Decimal)) { goto default; } return(System.Convert.ToString((System.Decimal)value)); case 0x244C7CD6: //case 0xE3159C: if (t != typeof(System.Char)) { goto default; } return(System.Convert.ToString((System.Char)value)); case 0x0EC74674: //case 0xE3173C: if (t != typeof(System.Single)) { goto default; } return(System.Convert.ToString((System.Single)value)); case 0x5E38073B: //case 0xE31770: if (t != typeof(System.Double)) { goto default; } return(System.Convert.ToString((System.Double)value)); case 0x604332EA: //case 0xE31568: if (t != typeof(System.Boolean)) { goto default; } return(System.Convert.ToString((System.Boolean)value)); case 0x0DE37C3B: //case 0xE31328: if (t != typeof(System.String)) { goto default; } return((string)value); case 0x6572ED4B: //case 0xE37678: if (t != typeof(System.IntPtr)) { goto default; } return(System.Convert.ToString((System.Int64)value)); case 0x3203515E: //case 0xE376AC: if (t != typeof(System.UIntPtr)) { goto default; } return(System.Convert.ToString((System.UInt64)value)); case 0x244AC511: //case 0xE376E0: if (t != typeof(System.Guid)) { goto default; } return(System.Xml.XmlConvert.ToString((System.Guid)value)); case 0x4BD7DD17: //case 0xE37714: if (t != typeof(System.TimeSpan)) { goto default; } return(System.Xml.XmlConvert.ToString((System.TimeSpan)value)); case 0x7F9DDECF: //case 0xE317D8: if (t != typeof(System.DateTime)) { goto default; } //.NET Framework 2.0 : System.Xml.XmlDateTimeSerializationMode を指定 return(System.Convert.ToString((System.DateTime)value)); case 0x24524716: //case 0xE37610: if (t != typeof(System.Type)) { goto default; } return(((System.Type)value).FullName); // case 0x2453BC7A://case 0xE37748: // if(t!=typeof(void))goto default; // break; case 0x7DDB9ECC: //case 0xE37778: if (t != typeof(System.Boolean[])) { goto default; } return(ToString((bool[])value)); // case 0x45EBBE0: // if(t!=typeof(System.Windows.Forms.SelectionRange))goto default; // return Convert.selectionRangeConv.ConvertToString(value); // case 0x244D9E9D://case 0xE311BC: // if(t!=typeof(System.Enum))goto default; // return System.Xml.XmlConvert.ToString((System.Int64)value); default: // typeconv: if (t.IsEnum) { return(value.ToString()); //System.Enum } if (t.GetCustomAttributes(typeof(System.ComponentModel.TypeConverterAttribute), false).Length == 0) { goto serial; } System.ComponentModel.TypeConverter conv = System.ComponentModel.TypeDescriptor.GetConverter(t); if (conv.CanConvertTo(typeof(string)) && conv.CanConvertFrom(typeof(string))) { try{ return(conv.ConvertToString(value)); }catch {} } serial: if (t.GetCustomAttributes(typeof(System.SerializableAttribute), false).Length == 0) { goto op_implicit; } using (System.IO.MemoryStream memstr = new System.IO.MemoryStream()){ Convert.binF.Serialize(memstr, value); //--長さ int len; try{ len = (int)memstr.Length; }catch (System.Exception e) { throw new System.Exception("データの量が大きすぎるので文字列に変換できません", e); } //--文字列に変換 byte[] buff = new byte[len]; memstr.Position = 0; memstr.Read(buff, 0, len); return(System.Convert.ToBase64String(buff)); } op_implicit: System.Reflection.MethodInfo[] ms = t.GetMethods(BF_PublicStatic); for (int i = 0; i < ms.Length; i++) { if (ms[i].Name != "op_Implicit" || ms[i].ReturnType != typeof(string)) { continue; } System.Reflection.ParameterInfo[] ps = ms[i].GetParameters(); if (ps.Length != 1 || ps[0].ParameterType != t) { continue; } return((string)ms[i].Invoke(null, new object[] { value })); } throw new System.ArgumentException(string.Format(TOSTR_NOTSUPPORTEDTYPE, t), "t"); } #endif }