/// <summary> /// Deserializes xml markup from file into an QvxTableHeaderQvxFieldHeader object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output QvxTableHeaderQvxFieldHeader object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out QvxTableHeaderQvxFieldHeader obj, out System.Exception exception) { exception = null; obj = default(QvxTableHeaderQvxFieldHeader); try { obj = LoadFromFile(fileName); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
/// <summary> /// Deserializes workflow markup into an QvxTableHeaderQvxFieldHeader object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output QvxTableHeaderQvxFieldHeader object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out QvxTableHeaderQvxFieldHeader obj, out System.Exception exception) { exception = null; obj = default(QvxTableHeaderQvxFieldHeader); try { obj = Deserialize(xml); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
public static bool LoadFromFile(string fileName, out QvxTableHeaderQvxFieldHeader obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
/// <summary> /// Deserializes xml markup from file into an QvxTableHeaderQvxFieldHeader object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output QvxTableHeaderQvxFieldHeader object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out QvxTableHeaderQvxFieldHeader obj, out System.Exception exception) { exception = null; obj = default(QvxTableHeaderQvxFieldHeader); try { obj = LoadFromFile(fileName); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public static bool Deserialize(string xml, out QvxTableHeaderQvxFieldHeader obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }
/// <summary> /// Deserializes workflow markup into an QvxTableHeaderQvxFieldHeader object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output QvxTableHeaderQvxFieldHeader object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out QvxTableHeaderQvxFieldHeader obj, out System.Exception exception) { exception = null; obj = default(QvxTableHeaderQvxFieldHeader); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }
private static void QvxFieldHeaderFromObject(ref List <QvxTableHeaderQvxFieldHeader> result, string prefix, ref string code1, ref string code2, Type t, ref int?blocksize, Dictionary <string, List <QvxBaseAttribute> > overrideAttributes) { string intprefix = prefix.Replace(".", "__"); if (result == null) { result = new List <QvxTableHeaderQvxFieldHeader>(); } if (result == null) { throw new ArgumentNullException("result"); } var valueList = new List <Tuple <Type, string, List <Attribute>, bool> >(); foreach (FieldInfo item in t.GetFields()) { code1 += " MethodInfo " + intprefix + item.Name + " = T_" + intprefix + ".GetField(\"" + item.Name + "\").GetGetMethod();\r\n"; valueList.Add( new Tuple <Type, string, List <Attribute>, bool>( item.FieldType, item.Name, (from c in item.GetCustomAttributes(true) select c as Attribute).ToList(), false)); } foreach (PropertyInfo item in t.GetProperties()) { code1 += " MethodInfo " + intprefix + item.Name + " = T_" + intprefix + ".GetProperty(\"" + item.Name + "\").GetGetMethod();\r\n"; if (item.CanRead) { valueList.Add( new Tuple <Type, string, List <Attribute>, bool>( item.PropertyType, item.Name, (from c in item.GetCustomAttributes(true) select c as Attribute).ToList(), true)); } } // Add designtime QvxAttributes if (overrideAttributes != null) { foreach (var item in valueList) { var localname = intprefix.Replace("base__", "") + item.Item2; if (overrideAttributes.ContainsKey(localname)) { var extAttrList = overrideAttributes[localname]; if (extAttrList != null) { item.Item3.AddRange(extAttrList); } } } } foreach (var item in valueList) { if (item.Item3.Contains(QvxIgnoreAttribute.Yes)) { continue; } string getValue = intprefix + item.Item2 + ".Invoke(" + intprefix + "item," + (item.Item4 ? "null" : "new object[] {" + intprefix + "item}") + ")"; if (!(item.Item1.Namespace != null && item.Item1.Namespace.StartsWith("System")) && !item.Item1.IsEnum && !item.Item3.Contains(QvxSubClassAsStringAttribute.Yes)) { code1 += " Type T_" + intprefix + item.Item2 + "__ = " + intprefix + item.Item2 + ".ReturnType;\r\n"; code2 = " var " + intprefix + item.Item2 + "__item = " + getValue + ";\r\n" + code2; QvxFieldHeaderFromObject(ref result, prefix + item.Item2 + ".", ref code1, ref code2, item.Item1, ref blocksize, overrideAttributes); } else { var subfieldAtt = (from c in item.Item3 where c.GetType().IsAssignableFrom(typeof(QvxSubfieldAttribute)) select c).FirstOrDefault() as QvxSubfieldAttribute; var enumerable = (from c in item.Item1.GetInterfaces() where c.Name == typeof(IEnumerable <>).Name select c).FirstOrDefault(); QvxTableHeaderQvxFieldHeader fieldHeader = null; if (subfieldAtt != null && enumerable != null) { #region Subfield Types fieldHeader = NetType2QvxType.MapFieldType(typeof(string)); string subfieldLen = subfieldAtt.SubFieldDevider.Length.ToString(); var genericArg = enumerable.GetGenericArguments().ToList(); if (genericArg.Count == 1) { string EnumerableType = genericArg[0].FullName; code2 += " tmpValue = " + getValue + ";\r\n"; code2 += " sb = new StringBuilder();\r\n"; code2 += " foreach (var item in (IEnumerable<" + EnumerableType + ">)tmpValue)\r\n"; code2 += " sb.Append(item.ToString()+\"" + subfieldAtt.SubFieldDevider + "\");\r\n"; code2 += " if (sb.Length > 0) sb.Remove(sb.Length-" + subfieldLen + "," + subfieldLen + ");\r\n"; code2 += " sbuf =Encoding.UTF8.GetBytes(sb.ToString());\r\n"; code2 += " bw.Write((Int32)sbuf.Length);\r\n"; code2 += " bw.Write(sbuf);\r\n"; } #endregion } else { #region Normal Types Type nullAbleType = Nullable.GetUnderlyingType(item.Item1); Type type = nullAbleType ?? item.Item1; string stype = ""; fieldHeader = NetType2QvxType.MapFieldType(type); if (NetType2QvxType.BinaryWriterTypes.Contains(type)) { stype = type.Name; } // TODO: second QVX for nested Tables if ((nullAbleType != null) | stype == "") { fieldHeader.NullRepresentation = QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA; code2 += " tmpValue = " + getValue + ";\r\n"; code2 += " if (tmpValue == null)\r\n"; code2 += " bw.Write((byte)1);\r\n"; code2 += " else\r\n"; code2 += " {\r\n"; code2 += " bw.Write((byte)0);\r\n"; if (stype != "") { code2 += " bw.Write((tmpValue as Nullable<" + stype + ">).Value);\r\n"; } else { if (type == typeof(byte[])) { code2 += " sbuf =(byte[])tmpValue;\r\n"; } else if (type == typeof(Char[])) { code2 += " sbuf =Encoding.UTF8.GetBytes((Char[])tmpValue);\r\n"; } else { code2 += " sbuf =Encoding.UTF8.GetBytes(tmpValue.ToString());\r\n"; } code2 += " bw.Write((Int32)sbuf.Length);\r\n"; code2 += " bw.Write(sbuf);\r\n"; } code2 += " }\r\n"; } else { if (type != typeof(Char)) { var functioncall = ""; if (type == typeof(DateTime)) { functioncall = ".ToOADate()"; } code2 += " bw.Write(((" + stype + ")" + getValue + ")" + functioncall + ");\r\n"; } else { code2 += " sbuf =Encoding.UTF8.GetBytes(" + getValue + "+\"\");\r\n"; code2 += " bw.Write((Int32)sbuf.Length);\r\n"; code2 += " bw.Write(sbuf);\r\n"; } } #endregion } // TODO: block write Qvx (check fixed size,...) QvxMaxLengthAttribute MaxSizeAttribute = null; foreach (var itemAttribute in item.Item3) { if (itemAttribute is QvxMaxLengthAttribute) { MaxSizeAttribute = itemAttribute as QvxMaxLengthAttribute; } } if (blocksize != null) { if (fieldHeader.Extent == QvxFieldExtent.QVX_FIX | MaxSizeAttribute != null) { if (fieldHeader.NullRepresentation == QvxNullRepresentation.QVX_NULL_FLAG_WITH_UNDEFINED_DATA | fieldHeader.NullRepresentation == QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA) { blocksize += 1; } if (fieldHeader.Extent == QvxFieldExtent.QVX_FIX | fieldHeader.Extent == QvxFieldExtent.QVX_COUNTED) { blocksize += fieldHeader.ByteWidth; } if (fieldHeader.Extent != QvxFieldExtent.QVX_FIX) { blocksize += MaxSizeAttribute.MaxLength; } } else { blocksize = null; } } fieldHeader.FieldFormat.ApplyCustomAttributes(item.Item3); fieldHeader.FieldName = prefix + item.Item2; result.Add(fieldHeader); } } }
public static bool LoadFromFile(string fileName, out QvxTableHeaderQvxFieldHeader obj) { System.Exception exception = null; return(LoadFromFile(fileName, out obj, out exception)); }
public static bool Deserialize(string xml, out QvxTableHeaderQvxFieldHeader obj) { System.Exception exception = null; return(Deserialize(xml, out obj, out exception)); }