/// <summary> /// Handled serializable (run ISerializable method with actual parameters). /// </summary> /// <param name="serializable"></param> private void HandleSerializable(ISerializable serializable) { FormatterConverter formatterConverter = new FormatterConverter(); SerializationInfo serializationInfo = new SerializationInfo(serializable.GetType(), formatterConverter); StreamingContext streamingContext = new StreamingContext(StreamingContextStates.All); serializable.GetObjectData(serializationInfo, streamingContext); // TODO: Check and test ISerializable support. // Serialize additional data if (serializationInfo.MemberCount > 0) { foreach (SerializationEntry entry in serializationInfo) { this.WriteString(entry.Name); this.WriteType(entry.ObjectType, false); if (entry.ObjectType.IsPrimitive) { this.TryWritePrimitiveType <int>(entry.Value, entry.ObjectType, this.WriteInt); this.TryWritePrimitiveType <byte>(entry.Value, entry.ObjectType, this.WriteByte); this.TryWritePrimitiveType <long>(entry.Value, entry.ObjectType, this.WriteLong); this.TryWritePrimitiveType <float>(entry.Value, entry.ObjectType, this.WriteFloat); this.TryWritePrimitiveType <double>(entry.Value, entry.ObjectType, this.WriteDouble); this.TryWritePrimitiveType <short>(entry.Value, entry.ObjectType, this.WriteShort); this.TryWritePrimitiveType <char>(entry.Value, entry.ObjectType, this.WriteChar); this.TryWritePrimitiveType <bool>(entry.Value, entry.ObjectType, this.WriteBoolean); } else { this.WriteObject(entry.Value); } } } }
public void ObjectDescriptor_GetObjectData() { FormatterConverter formatConverter = new FormatterConverter(); SerializationInfo serializationInfo = new SerializationInfo(typeof(ObjectDescriptor), formatConverter); VirtualTestObject virtualTestObject = new VirtualTestObject() { BoundingRect = new Rect(10, 20, 30, 40) }; ObjectDescriptor descriptor = virtualTestObject.GetDescriptor(); StreamingContext context = new StreamingContext(); IdentifyPropertyGroup group = descriptor.GetItem <IdentifyPropertyGroup>(); Assert.AreEqual("10,20,30,40", group.Properties[UIAControlKeys.BoundingRectangle]); descriptor.GetObjectData(serializationInfo, context); string typeString = null; foreach (SerializationEntry entry in serializationInfo) { if (entry.Name == DescriptorKeys.NodeType) { typeString = (string)entry.Value; break; } else if (entry.Name == IdentifyPropertyGroup.Key) { group = (IdentifyPropertyGroup)entry.Value; break; } } Assert.AreEqual(NodeType.VirtualControl, typeString); Assert.AreEqual("10,20,30,40", group.Properties[UIAControlKeys.BoundingRectangle]); }
/// <summary> /// Deserializes the data on the provided stream and reconstitutes the graph of objects. /// </summary> /// <param name="serializationStream">The stream that contains the data to deserialize.</param> /// <returns>The top object of the deserialized graph.</returns> /// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception> public object Deserialize(Stream serializationStream) { if (null == serializationStream) { throw new ArgumentNullException("serializationStream", "The Stream serializationStream cannot be null."); } long initialStreamPosition = serializationStream.Position; XmlReader xmlReader = null; try { xmlReader = XmlReader.Create(serializationStream, this.createXmlReaderSettings()); if (!xmlReader.IsStartElement()) { throw new SerializationException("Root element is missing."); } this.registeredReferenceObjects.Clear(); IFormatterConverter converter = new FormatterConverter(); SerializationEntry graphEntry = this.deserialize(xmlReader, converter); return(graphEntry.Value); } finally { if (null != xmlReader) { serializationStream.Position = this.getStreamPosition(xmlReader, serializationStream, initialStreamPosition); xmlReader.Close(); } } }
public ObjectReader(Stream stream) { stream.Seek(0, SeekOrigin.Begin); Reader = new BinaryReader(stream); Converter = new FormatterConverter(); }
private Dictionary ToBencodexDictionary(ISerializable serializable) { var converter = new FormatterConverter(); var serializationInfo = new SerializationInfo(typeof(T), converter); serializable.GetObjectData(serializationInfo, Context); var entries = new List <KeyValuePair <IKey, IValue> >(); foreach (SerializationEntry entry in serializationInfo) { IValue v = entry.Value is ISerializable serializableValue ? ToBencodexDictionary(serializableValue) : ToBencodexValue(entry.Value); entries.Add( new KeyValuePair <IKey, IValue>( new Binary(Encoding.UTF8.GetBytes(entry.Name)), v ) ); } return(new Dictionary(entries)); }
/// <summary> /// Serializes an object, or graph of objects with the given root to the provided stream. /// </summary> /// <param name="serializationStream"> /// The stream where the formatter puts the serialized data. This stream can reference a variety /// of backing stores (such as files, network, memory, and so on). /// </param> /// <param name="graph"> /// The object, or root of the object graph, to serialize. All child objects of this root object /// are automatically serialized. /// </param> /// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception> /// <exception cref="T:System.ArgumentNullException">The <para>graph</para> cannot be null.</exception> public void Serialize(Stream serializationStream, object graph) { if (null == serializationStream) { throw new ArgumentNullException("serializationStream", "Stream serializationStream cannot be null."); } if (null == graph) { throw new ArgumentNullException("graph", "Object graph cannot be null."); } XmlWriter xmlWriter = null; try { xmlWriter = XmlWriter.Create(serializationStream, this.createXmlWriterSettings()); this.registeredReferenceObjects.Clear(); this.idGenerator = new ObjectIDGenerator(); IFormatterConverter converter = new FormatterConverter(); SerializationEntry graphEntry = this.createSerializationEntry(this.getName(graph.GetType()), graph, converter); this.serializeEntry(xmlWriter, graphEntry, converter); xmlWriter.WriteWhitespace(Environment.NewLine); } finally { if (null != xmlWriter) { xmlWriter.Flush(); } } }
public DotNetSerializableCodec( IFieldCodec <Type> typeCodec, IFieldCodec <string> stringCodec, IFieldCodec <object> objectCodec, IUntypedCodecProvider untypedCodecProvider) { this.typeCodec = typeCodec; this.untypedCodecProvider = untypedCodecProvider; var entrySerializer = new SerializationEntryCodec(stringCodec, objectCodec); var constructorFactory = new SerializationConstructorFactory(); var serializationCallbacks = new SerializationCallbacksFactory(); var formatterConverter = new FormatterConverter(); this.objectSerializer = new ObjectSerializer( entrySerializer, constructorFactory, serializationCallbacks, formatterConverter, this.streamingContext); this.valueTypeSerializerFactory = new ValueTypeSerializerFactory( entrySerializer, constructorFactory, serializationCallbacks, formatterConverter, this.streamingContext); }
public MainWindow() { int X; int Y; CursorInfo ci; ClientSize = new System.Drawing.Size(max_labels_row * size_of_label, (((num_of_cursors + (max_labels_row - (num_of_cursors % max_labels_row))) * size_of_label) / (max_labels_row * size_of_label)) * size_of_label); Text = "SWF Cursor Test App"; labels = new Label[num_of_cursors]; ci = new CursorInfo(); for (int i = 0; i < num_of_cursors; i++) { GetCursor(i, out ci); labels[i] = new Label(); labels[i].Location = new Point((i * size_of_label) % (max_labels_row * size_of_label), ((i * size_of_label) / (max_labels_row * size_of_label)) * size_of_label); labels[i].Size = new Size(size_of_label, size_of_label); labels[i].Text = ci.name; labels[i].BackColor = Color.FromArgb(i * 9, i * 9, i * 9); labels[i].ForeColor = Color.Red; labels[i].Cursor = ci.cursor; labels[i].Paint += new PaintEventHandler(MainWindow_Paint); this.Controls.Add(labels[i]); } // Get the GetDataObject method SerializationInfo si; FormatterConverter fc; fc = new FormatterConverter(); si = new SerializationInfo(typeof(Cursor), fc); ((ISerializable)ci.cursor).GetObjectData(si, new StreamingContext(StreamingContextStates.All)); Console.WriteLine("Member count: {0}", si.MemberCount); Console.WriteLine("Members: {0}", si.MemberCount); SerializationInfoEnumerator e; e = si.GetEnumerator(); while (e.MoveNext()) { Console.WriteLine("Member {0}", e.Name); } byte [] data = (byte [])si.GetValue("CursorData", typeof(byte [])); Console.WriteLine("CursorData:"); for (int i = 0; i < data.Length; i++) { Console.Write("{0:X2}, ", data[i]); } Console.WriteLine(""); Console.WriteLine("Result: {0}", si.ToString()); //ci.cursor.I KeyDown += new KeyEventHandler(MainWindow_KeyDown); }
public static void SerializeItem() { IFormatterConverter converter = new FormatterConverter(); IFormatter formatter = new BinaryFormatter(); SeDeClass seDeClass = new SeDeClass(); SeDeClass t = new SeDeClass(); SeDeTestClass seDeTestClass = new SeDeTestClass(); StreamingContext context = new StreamingContext(StreamingContextStates.All, "foo"); IFormatter formatter1 = new BinaryFormatter(null, context); seDeTestClass._id = 0; seDeTestClass.MyValue = "Just do a Test"; seDeClass._id = 0; seDeClass.MyValue = "Just do a Test"; FileStream fileStream1 = new FileStream("Test1.txt", FileMode.Create); FileStream fileStream2 = new FileStream("Test2.txt", FileMode.Create); FileStream fileStream3 = new FileStream("Test3.txt", FileMode.Create); formatter.Serialize(fileStream1, seDeClass); formatter.Serialize(fileStream2, seDeTestClass); formatter1.Serialize(fileStream3, seDeClass); fileStream1.Close(); fileStream2.Close(); fileStream3.Close(); }
public void GetObjectData() { Type type = typeof(HsqlDataSourceException); FormatterConverter converter = new FormatterConverter(); SerializationInfo info = new SerializationInfo(type, converter); StreamingContext context = new StreamingContext(); HsqlDataSourceException testSubject = new HsqlDataSourceException("foo", -1, "42001"); testSubject.GetObjectData(info, context); Console.WriteLine("Member Count: {0}", info.MemberCount); foreach (SerializationEntry item in info) { Console.WriteLine("Name: {0}, Type: {1}, Value: {2}", item.Name, item.ObjectType, item.Value); if (item.Name == "m_code") { Assert.AreEqual(-1, item.Value); } else if (item.Name == "m_state") { Assert.AreEqual("42001", item.Value); } else if (item.Name == "Message") { Assert.AreEqual("foo", item.Value); } } //Assert.Fail("TODO"); }
/// <summary> /// Determines the value of an object. /// </summary> /// <param name="reader">The XMLTextReader the read from.</param> /// <param name="converter"> /// The <see cref="System.Runtime.Serialization.FormatterConverter">converter</see> used to parse the values from the XML. /// </param> /// <param name="objectType">The type of the object to create.</param> /// <returns>The value of the object.</returns> private object DetermineValue( [NotNull] XmlTextReader reader, [NotNull] FormatterConverter converter, [NotNull] Type objectType) { object parsedObject; // check if the value can be directly determined or that the type is a complex type. if (objectType.IsPrimitive || objectType == typeof(string) || objectType.IsEnum || objectType == typeof(DateTime) || objectType == typeof(object)) { // directly parse // ReSharper disable once AssignNullToNotNullAttribute parsedObject = converter.Convert(reader.ReadString(), objectType); } else { // Initialize the object (recursive call) parsedObject = InitializeObject(reader, converter, objectType); } return(parsedObject); }
// Constructor. public BinaryFormatter() { this.context = new StreamingContext(StreamingContextStates.All); this.assemblyFormat = FormatterAssemblyStyle.Full; this.typeFormat = FormatterTypeStyle.TypesAlways; this.filterLevel = TypeFilterLevel.Full; this.converter = new FormatterConverter(); }
internal ObjectReader(Stream stream) { stream.Seek(0, SeekOrigin.Begin); Reader = new BinaryReader(stream); Converter = new FormatterConverter(); PopulateGuidLookup(); }
public ObjectState(SerializationInfo info, StreamingContext context) { IFormatterConverter converter = new FormatterConverter(); foreach (SerializationEntry entry in info) { Data[entry.Name] = (byte[])converter.Convert(entry.Value, entry.ObjectType); } }
/// <summary> /// Extends Convert so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// formatterconverter.Convert<int>(value); /// </example> /// </summary> public static T Convert <T>(this FormatterConverter formatterconverter, Object value) { if (formatterconverter == null) { throw new ArgumentNullException("formatterconverter"); } return((T)formatterconverter.Convert(value, typeof(T))); }
private static SerializationInfo GetSerializationInfo(T e) { var converter = new FormatterConverter(); var info = new SerializationInfo(typeof(T), converter); var context = new StreamingContext(StreamingContextStates.Clone); e.GetObjectData(info, context); return(info); }
object IDataSerializer.Deserialize(ISerializer serializer, string text) { var converter = new FormatterConverter(); var info = new SerializationInfo(this.ExceptionType, converter); var context = new StreamingContext(StreamingContextStates.Clone); var propserties = serializer.Deserialize(typeof(Dictionary <string, object>), text) as Dictionary <string, object>; this.GetSerializationInfo(propserties, info); return(Activator.CreateInstance(this.ExceptionType, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { info, context }, null)); }
public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) { this.surrogateSelector = selector; this.context = context; this.assemblyFormat = FormatterAssemblyStyle.Full; this.typeFormat = FormatterTypeStyle.TypesAlways; this.filterLevel = TypeFilterLevel.Full; this.converter = new FormatterConverter(); }
/// <summary> /// Converts the specified values. /// </summary> /// <param name="values">The values.</param> /// <returns>List<T>.</returns> public List <T> Convert(string[] values) { FormatterConverter converter = new FormatterConverter(); List <T> items = new List <T>(); foreach (var value in values) { items.Add((T)converter.Convert(value, typeof(T))); } return(items); }
private void setSerializationInfo(ref CryptographicException ex) { // Insert information about the exception into a serialized object. FormatterConverter formatConverter = new FormatterConverter(); SerializationInfo serializationInfo = new SerializationInfo(ex.GetType(), formatConverter); StreamingContext streamingContext = new StreamingContext(StreamingContextStates.All); ex.GetObjectData(serializationInfo, streamingContext); }
/// <summary> /// Initializes a new instance of the <see cref="DeserializationContext"/> class. /// </summary> /// <param name="context">The streaming context to use.</param> /// <param name="formatterConverter">The formatter converter to use.</param> /// <exception cref="System.ArgumentNullException">The formatterConverter parameter is null.</exception> public DeserializationContext(StreamingContext context, FormatterConverter formatterConverter) { if (formatterConverter == null) { throw new ArgumentNullException("formatterConverter"); } this.streamingContext = context; this.formatterConverter = formatterConverter; this.Reset(); }
public ItemStack clone() { IFormatterConverter converter = new FormatterConverter(); SerializationInfo info = new SerializationInfo(typeof(ItemStack), converter); StreamingContext context = default(StreamingContext); this.GetObjectData(info, context); ItemStack newStack = new ItemStack(info, context); return(newStack); }
public void CreateFromObjectData() { var converter = new FormatterConverter(); var info = new SerializationInfo(typeof(Date), converter); var context = new StreamingContext(); info.AddValue("Second", 24); info.AddValue("Minute", 02); info.AddValue("Hour", 14); var time = new Time(info, context); time.Should().Be(new Time(14, 02, 24)); }
public CrySerializer() { Converter = new FormatterConverter(); ObjectReferences = new Dictionary <int, ObjectReference>(); #if !UNIT_TESTING var debugCVar = CVar.Get("mono_realtimeScriptingDebug"); if (debugCVar != null) { IsDebugModeEnabled = (debugCVar.IVal != 0); } #endif }
public void CreateFromObjectData() { var converter = new FormatterConverter(); var info = new SerializationInfo(typeof(Date), converter); var context = new StreamingContext(); info.AddValue("Day", 19); info.AddValue("Month", 11); info.AddValue("Year", 2019); var date = new Date(info, context); date.Should().Be(new Date(2019, 11, 19)); }
/// <summary> /// Initializes a new instance of the <see cref="WellKnownStringComparerCodec"/> class. /// </summary> public WellKnownStringComparerCodec() { _ordinalComparer = StringComparer.Ordinal; _ordinalIgnoreCaseComparer = StringComparer.OrdinalIgnoreCase; _defaultEqualityComparer = EqualityComparer <string> .Default; _ordinalType = _ordinalComparer.GetType(); _ordinalIgnoreCaseType = _ordinalIgnoreCaseComparer.GetType(); _defaultEqualityType = _defaultEqualityComparer.GetType(); #if !NET6_0_OR_GREATER _streamingContext = new StreamingContext(StreamingContextStates.All); _formatterConverter = new FormatterConverter(); #endif }
/// <summary> /// Check if a value matches with the given data type. /// </summary> /// <param name="value">The value of which type to be checked upon.</param> /// <param name="dataType">The data type the value should match to.</param> /// <returns>true: valid; false: invalid</returns> public static bool IsValidDataType(object dataValue, string dataType) { bool ReturnValue = true; FormatterConverter DataFormatter = new FormatterConverter(); //Check if the value supplied can be converted to the given data type. //if not or if the data type is not defined in the following checks, //then invalidate the data value. try { switch (dataType.ToLower()) { case "char": DataFormatter.ToChar(dataValue); break; case "varchar": break; case "int": DataFormatter.ToInt32(dataValue); break; case "decimal": // TODO: Code review issue 24/05/2005 - KB // floats not allowed as datatypes case "float": case "money": DataFormatter.ToDecimal(dataValue); break; case "datetime": //22/07/05 LL - TIR0224 Allow various valid date formats ReturnValue = DateUtility.IsValidDate(dataValue.ToString()); break; default: ReturnValue = false; break; } } catch (Exception e) { string Error = e.ToString(); ReturnValue = false; } return(ReturnValue); }
public void GetObjectData() { var date = new Date(2019, 11, 19); var converter = new FormatterConverter(); var info = new SerializationInfo(typeof(Date), converter); var context = new StreamingContext(); date.GetObjectData(info, context); { info.GetValue("Day", typeof(int)).Should().Be(19); info.GetValue("Month", typeof(int)).Should().Be(11); info.GetValue("Year", typeof(int)).Should().Be(2019); } }
public void GetObjectData() { var time = new Time(14, 02, 24); var converter = new FormatterConverter(); var info = new SerializationInfo(typeof(Date), converter); var context = new StreamingContext(); time.GetObjectData(info, context); using (new AssertionScope()) { info.GetValue("Second", typeof(int)).Should().Be(24); info.GetValue("Minute", typeof(int)).Should().Be(02); info.GetValue("Hour", typeof(int)).Should().Be(14); }; }
/// <summary> /// Determines the value of an object. /// </summary> /// <param name="reader">The XML reader the read from.</param> /// <param name="converter">The converter used to parse the values from the XML.</param> /// <param name="objectType">The type of the object to create.</param> /// <returns>The value of the object.</returns> private object DetermineValue(XmlTextReader reader, FormatterConverter converter, Type objectType) { object parsedObject; // check if the value can be directly determined or that the type is a complex type. if (objectType.IsPrimitive || objectType == typeof(string) || objectType.IsEnum || objectType == typeof(DateTime) || objectType == typeof(object)) { // directly parse parsedObject = converter.Convert(reader.ReadString(), objectType); } else { // Initialize the object (recursive call) parsedObject = InitializeObject(reader, converter, objectType); } return(parsedObject); }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; FormatterConverter fmtcnv1 = null; Boolean fValue; Char chValue; SByte sbtValue; Byte btValue; Int16 i16Value; Int32 i32Value; Int64 i64Value; UInt16 ui16Value; UInt32 ui32Value; UInt64 ui64Value; Double dblValue; Single sglValue; DateTime dtValue; Decimal dcValue; Object oValue; Object oRtnValue; String strValue; TypeCode tpcd1; Object[] oTpCodeArr; TypeCode[] arrTpCodeArr; Object[] oArr = {false, (SByte)5, (Byte)5, (Int16)5, (Int32)5, (Int64)5, (UInt16)5, (UInt32)5, (UInt64)5, (Single)5.0, (Double)5.0, }; Type[] tpArr = {typeof(Boolean), typeof(SByte), typeof(Byte), typeof(Int16), typeof(Int32), typeof(Int64), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(Single), typeof(Double), }; try { do { strLoc="Loc_6573cd"; fmtcnv1 = new FormatterConverter(); strValue = "false"; fValue = false; iCountTestcases++; if(fmtcnv1.ToBoolean(strValue) != fValue) { iCountErrors++; Console.WriteLine("Err_0246sd! Wrong value returned, " + fmtcnv1.ToBoolean(strValue)); } i32Value = 5; fValue = true; iCountTestcases++; if(fmtcnv1.ToBoolean(i32Value) != fValue) { iCountErrors++; Console.WriteLine("Err_87430cd! Wrong value returned, " + fmtcnv1.ToBoolean(i32Value)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToBoolean(strValue); iCountErrors++; Console.WriteLine("Err_1065753cd! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_5739cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToBoolean(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; btValue = 5; iCountTestcases++; if(fmtcnv1.ToByte(i32Value) != btValue) { iCountErrors++; Console.WriteLine("Err_0753cfd! Wrong value returned, " + fmtcnv1.ToByte(i32Value)); } strValue = "5"; btValue = 5; iCountTestcases++; if(fmtcnv1.ToByte(strValue) != btValue) { iCountErrors++; Console.WriteLine("Err_0483fd! Wrong value returned, " + fmtcnv1.ToByte(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToByte(strValue); iCountErrors++; Console.WriteLine("Err_034752fsd! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04729cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; i32Value = 743290; fmtcnv1.ToByte(i32Value); iCountErrors++; Console.WriteLine("Err_047239fd! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_017s! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToByte(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; chValue = (Char)5; iCountTestcases++; if(fmtcnv1.ToChar(i32Value)!=chValue) { iCountErrors++; Console.WriteLine("Err_8475320vdef! Wrong value returned, " + fmtcnv1.ToChar(i32Value)); } strValue = "5"; chValue = (Char)53; iCountTestcases++; if(fmtcnv1.ToChar(strValue)!=chValue) { iCountErrors++; Console.WriteLine("Err_01237xs! Wrong value returned, " + fmtcnv1.ToChar(strValue) + " " + chValue); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToChar(strValue); iCountErrors++; Console.WriteLine("Err_048329fde! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1093cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; i32Value = 743290; fmtcnv1.ToChar(i32Value); iCountErrors++; Console.WriteLine("Err_0483vfd! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_017s! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToChar(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } strLoc="Loc_34732fd"; dtValue = DateTime.Now; strValue = dtValue.ToString(); iCountTestcases++; if(!fmtcnv1.ToDateTime(strValue).ToString().Equals(dtValue.ToString())) { iCountErrors++; Console.WriteLine("Err_0278423d! Wrong value returned, " + fmtcnv1.ToDateTime(strValue) + " " + dtValue); } strLoc="Loc_047gd"; try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToDateTime(strValue); iCountErrors++; Console.WriteLine("Err_34234dsf! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_dfsdfsfsng exception thrown, " + ex); } try { iCountTestcases++; i32Value = 743290; fmtcnv1.ToByte(i32Value); iCountErrors++; Console.WriteLine("Err_0453fd! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_10084523f! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToByte(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } strLoc="Loc_44732fd"; dcValue = (Decimal)123.23; strValue = "123.23"; if (!dcValue.ToString().Equals(strValue)) throw new Exception("Decimal ToString doesn't match expected value! Decimal: "+dcValue.ToString()); iCountTestcases++; if(fmtcnv1.ToDecimal(strValue)!=dcValue) { iCountErrors++; Console.WriteLine("Err_342fsd! Wrong value returned, " + fmtcnv1.ToDecimal(strValue) ); } strLoc="Loc_047gd"; try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToDecimal(strValue); iCountErrors++; Console.WriteLine("Err_342dfs! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_8342vds exception thrown, " + ex); } try { iCountTestcases++; dblValue = Double.MaxValue; fmtcnv1.ToDecimal(dblValue); iCountErrors++; Console.WriteLine("Err_1091212dsdas! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_10874cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToDecimal(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } strLoc="Loc_24732fd"; dblValue = 123.23; strValue = "123.23"; iCountTestcases++; if(fmtcnv1.ToDouble(strValue)!=dblValue) { iCountErrors++; Console.WriteLine("Err_10742cd! Wrong value returned, " + fmtcnv1.ToDouble(strValue) ); } strLoc="Loc_047gd"; try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToDouble(strValue); iCountErrors++; Console.WriteLine("Err_197wc! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1087wxs exception thrown, " + ex); } try { iCountTestcases++; fValue = true; Double d = fmtcnv1.ToDouble(fValue); if ( d != 1 ) { iCountErrors++; Console.WriteLine("FormatConvertor.ToDouble method returns unexpected value." + d); } }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_02834cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToDouble(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; i16Value = 5; iCountTestcases++; if(fmtcnv1.ToInt16(i32Value) != i16Value) { iCountErrors++; Console.WriteLine("Err_045fdc! Wrong value returned, " + fmtcnv1.ToInt16(i32Value)); } strValue = "5"; i16Value = 5; iCountTestcases++; if(fmtcnv1.ToInt16(strValue) != i16Value) { iCountErrors++; Console.WriteLine("Err_04523vdf! Wrong value returned, " + fmtcnv1.ToInt16(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToInt16(strValue); iCountErrors++; Console.WriteLine("Err_134782ds! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_107342dcs! Wrong exception thrown, " + ex); } try { iCountTestcases++; i32Value = Int32.MaxValue; fmtcnv1.ToInt16(i32Value); iCountErrors++; Console.WriteLine("Err_93742cvsd! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0134vsdf! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToInt16(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; i64Value = 5; iCountTestcases++; if(fmtcnv1.ToInt32(i64Value) != i32Value) { iCountErrors++; Console.WriteLine("Err_0753cfd! Wrong value returned, " + fmtcnv1.ToInt32(i64Value)); } strValue = "5"; i32Value = 5; iCountTestcases++; if(fmtcnv1.ToInt32(strValue) != i32Value) { iCountErrors++; Console.WriteLine("Err_197axs! Wrong value returned, " + fmtcnv1.ToInt32(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToInt32(strValue); iCountErrors++; Console.WriteLine("Err_1112s! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_dasda213! Wrong exception thrown, " + ex); } try { iCountTestcases++; i64Value = Int64.MaxValue; fmtcnv1.ToInt32(i64Value); iCountErrors++; Console.WriteLine("Err_2423cds! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0231das! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToInt32(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; i64Value = 5; iCountTestcases++; if(fmtcnv1.ToInt64(i32Value) != i64Value) { iCountErrors++; Console.WriteLine("Err_452cds! Wrong value returned, " + fmtcnv1.ToInt64(i32Value)); } strValue = "5"; i64Value = 5; iCountTestcases++; if(fmtcnv1.ToInt64(strValue) != i64Value) { iCountErrors++; Console.WriteLine("Err_234dcd! Wrong value returned, " + fmtcnv1.ToInt64(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToInt64(strValue); iCountErrors++; Console.WriteLine("Err_134! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_fdvw! Wrong exception thrown, " + ex); } try { iCountTestcases++; dblValue = Double.MaxValue; fmtcnv1.ToInt64(dblValue); iCountErrors++; Console.WriteLine("Err_23084ds! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1084d! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToInt64(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; sbtValue = 5; iCountTestcases++; if(fmtcnv1.ToSByte(i32Value) != sbtValue) { iCountErrors++; Console.WriteLine("Err_013248csd! Wrong value returned, " + fmtcnv1.ToSByte(i32Value)); } strValue = "5"; sbtValue = 5; iCountTestcases++; if(fmtcnv1.ToSByte(strValue) != sbtValue) { iCountErrors++; Console.WriteLine("Err_10732sx! Wrong value returned, " + fmtcnv1.ToSByte(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToSByte(strValue); iCountErrors++; Console.WriteLine("Err_632sa! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_6732ds! Wrong exception thrown, " + ex); } try { iCountTestcases++; i32Value = 743290; fmtcnv1.ToSByte(i32Value); iCountErrors++; Console.WriteLine("Err_003sw! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_13853ds! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToSByte(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; sglValue = 5.0f; iCountTestcases++; if(fmtcnv1.ToSingle(i32Value) != sglValue) { iCountErrors++; Console.WriteLine("Err_0527fds! Wrong value returned, " + fmtcnv1.ToSingle(i32Value)); } strValue = "5"; sglValue = 5; iCountTestcases++; if(fmtcnv1.ToSingle(strValue) != sglValue) { iCountErrors++; Console.WriteLine("Err_842fsd! Wrong value returned, " + fmtcnv1.ToSingle(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToSingle(strValue); iCountErrors++; Console.WriteLine("Err_3421da! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_34123! Wrong exception thrown, " + ex); } dblValue = Double.MaxValue; sglValue = Single.PositiveInfinity; iCountTestcases++; if(fmtcnv1.ToSingle(dblValue) != sglValue) { iCountErrors++; Console.WriteLine("Err_2231dfs! Wrong value returned, " + fmtcnv1.ToSingle(dblValue)); } try { iCountTestcases++; fmtcnv1.ToSingle(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; strValue = "5"; iCountTestcases++; if(!strValue.Equals(fmtcnv1.ToString(i32Value))) { iCountErrors++; Console.WriteLine("Err_93472fsd! Wrong value returned, " + fmtcnv1.ToString(i32Value)); } try { iCountTestcases++; fmtcnv1.ToString(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; ui16Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt16(i32Value) != ui16Value) { iCountErrors++; Console.WriteLine("Err_045fvd! Wrong value returned, " + fmtcnv1.ToUInt16(i32Value)); } strValue = "5"; ui16Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt16(strValue) != ui16Value) { iCountErrors++; Console.WriteLine("Err_1834dcvds! Wrong value returned, " + fmtcnv1.ToUInt16(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToUInt16(strValue); iCountErrors++; Console.WriteLine("Err_183cs! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_189ws! Wrong exception thrown, " + ex); } try { iCountTestcases++; i32Value = Int32.MaxValue; fmtcnv1.ToUInt16(i32Value); iCountErrors++; Console.WriteLine("Err_342fds! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_6454cd! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToUInt16(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; ui32Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt32(i64Value) != ui32Value) { iCountErrors++; Console.WriteLine("Err_7834vfd! Wrong value returned, " + fmtcnv1.ToUInt32(i64Value)); } strValue = "5"; ui32Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt32(strValue) != ui32Value) { iCountErrors++; Console.WriteLine("Err_1243vcd! Wrong value returned, " + fmtcnv1.ToUInt32(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToUInt32(strValue); iCountErrors++; Console.WriteLine("Err_1234csx! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_5634fsd! Wrong exception thrown, " + ex); } try { iCountTestcases++; i64Value = Int64.MaxValue; fmtcnv1.ToUInt32(i64Value); iCountErrors++; Console.WriteLine("Err_0453vdf! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0342vfdf! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToUInt32(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } i32Value = 5; ui64Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt64(i32Value) != ui64Value) { iCountErrors++; Console.WriteLine("Err_38503dc! Wrong value returned, " + fmtcnv1.ToUInt64(i32Value)); } strValue = "5"; ui64Value = 5; iCountTestcases++; if(fmtcnv1.ToUInt64(strValue) != ui64Value) { iCountErrors++; Console.WriteLine("Err_0173xs! Wrong value returned, " + fmtcnv1.ToUInt64(strValue)); } try { iCountTestcases++; strValue = "Hey man"; fmtcnv1.ToUInt64(strValue); iCountErrors++; Console.WriteLine("Err_013csd! Exception not thrown"); }catch(FormatException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_75421xs! Wrong exception thrown, " + ex); } try { iCountTestcases++; dblValue = Double.MaxValue; fmtcnv1.ToUInt64(dblValue); iCountErrors++; Console.WriteLine("Err_3472ds! Exception not thrown"); }catch(OverflowException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_vefe! Wrong exception thrown, " + ex); } try { iCountTestcases++; fmtcnv1.ToUInt64(null); iCountErrors++; Console.WriteLine("Err_84532fd! Exception not thrown"); }catch(ArgumentNullException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1382cs! Wrong exception thrown, " + ex); } iCountTestcases++; for(int i=0;i<oArr.Length; i++){ oValue = oArr[i]; for(int j=0;j<tpArr.Length; j++){ try{ oRtnValue = fmtcnv1.Convert(oValue, tpArr[j]); }catch(Exception ex){ if(ex.ToString().IndexOf("InvalidCastException")==-1) Console.WriteLine(i + " " + j + " " + ex); } } } iCountTestcases++; arrTpCodeArr = (TypeCode[])Enum.GetValues(typeof(TypeCode)); for(int i=0;i<oArr.Length; i++){ oValue = oArr[i]; for(int j=0;j<arrTpCodeArr.Length; j++){ tpcd1 = arrTpCodeArr[j]; try{ oRtnValue = fmtcnv1.Convert(oValue, tpcd1); }catch(Exception ex){ if(ex.ToString().IndexOf("InvalidCastException")==-1) Console.WriteLine(i + " " + j + " " + ex); } } } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }