Exemple #1
0
        /// <summary>
        /// Create record object from serialized record string
        /// </summary>
        /// <param name="recordString">serialized record string</param>
        /// <param name="recordfType">record type to create [WorkFlowTrackRecord or ActivityTrackRecord]</param>
        /// <returns></returns>
        public static BaseTrackRecord CreateObjectFromString(string recordString, Type recordfType)
        {
            BaseTrackRecord newRecord = (BaseTrackRecord)Activator.CreateInstance(recordfType);

            PropertyInfo[] pInfoArr = newRecord.GetType().GetProperties(BindingFlags.IgnoreCase
                                                                        | BindingFlags.Instance | BindingFlags.Public);
            foreach (var propInfo in pInfoArr)
            {
                Regex rx = new Regex(@"" + propInfo.Name + @"(\s*)=(\s*)""([^""]*)""",
                                     RegexOptions.IgnoreCase);

                Match m = rx.Match(recordString);
                if (m.Success && m.Groups.Count > 0)
                {
                    string val = m.Groups[m.Groups.Count - 1].ToString().Trim();
                    //get prop type
                    var targetType = TConverter.GetPropType(propInfo);
                    //Convert value to property type
                    object convertedValue = TConverter.ChangeType(targetType, val);
                    //set object value
                    propInfo.SetValue(newRecord, convertedValue, null);
                }
            }
            return(newRecord);
        }
        private static void ConvertXmlNodeAttribValueToObjProp(XmlAttribute att, ref BaseTrackRecord trackRecord)
        {
            PropertyInfo propInfo = trackRecord.GetType().GetProperty(att.Name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);

            if (propInfo != null)
            {
                //get prop type
                var targetType = TConverter.GetPropType(propInfo);
                //Convert value to property type
                object convertedValue = TConverter.ChangeType(targetType, att.Value);
                //set object value
                propInfo.SetValue(trackRecord, convertedValue, null);
            }
        }