Example #1
0
        /// <summary>
        /// Genernations the object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pobSrc">The pob SRC.</param>
        /// <param name="penOpt">The pen opt.</param>
        /// <returns></returns>
        public static T GenernationObject <T>(object pobSrc, OptionTyp penOpt)
        {
            T lobDest = Activator.CreateInstance <T>();

            CopyProperties(pobSrc, lobDest, penOpt);
            return(lobDest);
        }
Example #2
0
        /// <summary>
        /// Gets the property.
        /// </summary>
        /// <param name="pobObj">The pob obj.</param>
        /// <param name="pstPropertyName">Name of the PST property.</param>
        /// <param name="penOpt">The pen opt.</param>
        /// <returns></returns>
        public static object GetProperty(object pobObj, string pstPropertyName, OptionTyp penOpt)
        {
            if (null == pobObj || string.IsNullOrEmpty(pstPropertyName))
            {
                throw new ArgumentNullException("one argument is null!");
            }
            bool         isIgnoreCase = ((penOpt & OptionTyp.IsIgnoreCase) == OptionTyp.IsIgnoreCase);
            Type         t            = pobObj.GetType();
            PropertyInfo objInfo      = null;

            if (isIgnoreCase)
            {
                PropertyInfo[] objInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                foreach (PropertyInfo p in objInfos)
                {
                    if (p.Name.ToUpperInvariant().Equals(pstPropertyName.ToUpperInvariant()))
                    {
                        objInfo = p;
                        break;
                    }
                }
            }
            else
            {
                objInfo = t.GetProperty(pstPropertyName, BindingFlags.Instance | BindingFlags.Public);
            }
            if (null == objInfo)
            {
                throw new MapPropertyException("no mapping property");
            }
            object val = objInfo.GetValue(pobObj, null);

            return(val);
        }
Example #3
0
        /// <summary>
        /// Genernations the object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pdiProperties">The pdi properties.</param>
        /// <param name="penOpt">The pen opt.</param>
        /// <returns></returns>
        public static T GenernationObject <T>(Dictionary <String, object> pdiProperties, OptionTyp penOpt)
        {
            T lobDest = Activator.CreateInstance <T>();

            SetProperties(pdiProperties, lobDest, penOpt);
            return(lobDest);
        }
Example #4
0
 /// <summary>
 /// Copies the properties with map.
 /// </summary>
 /// <param name="pobSrc">The pob SRC.</param>
 /// <param name="pobDest">The pob dest.</param>
 /// <param name="pstSrcPropertyNames">The PST SRC property names.</param>
 /// <param name="pstDestPropertyNames">The PST dest property names.</param>
 /// <param name="penOpt">The pen opt.</param>
 public static void CopyPropertiesWithMap(object pobSrc, object pobDest, string[] pstSrcPropertyNames, string[] pstDestPropertyNames, OptionTyp penOpt)
 {
     if (null == pobSrc || null == pobDest)
     {
         throw new ArgumentNullException("one argument is null!");
     }
     if (pstDestPropertyNames.Length != pstSrcPropertyNames.Length)
     {
         throw new ArgumentException("pstDestPropertyNames & pstSrcPropertyNames must same array length");
     }
     for (int i = 0; i < pstDestPropertyNames.Length; i++)
     {
         CopyProperty(pobSrc, pobDest, pstSrcPropertyNames[i], pstDestPropertyNames[i], penOpt);
     }
 }
Example #5
0
        /// <summary>
        /// Copies the properties with map.
        /// </summary>
        /// <param name="pobSrc">The pob SRC.</param>
        /// <param name="pobDest">The pob dest.</param>
        /// <param name="pdiMap">The pdi map.</param>
        /// <param name="penOpt">The pen opt.</param>
        public static void CopyPropertiesWithMap(object pobSrc, object pobDest, Dictionary <String, string> pdiMap, OptionTyp penOpt)
        {
            List <String> strSrc  = new List <String>();
            List <String> strDest = new List <String>();

            foreach (KeyValuePair <String, string> pair in pdiMap)
            {
                strSrc.Add(pair.Key);
                strDest.Add(pair.Value);
            }
            CopyPropertiesWithMap(pobSrc, pobDest, strSrc.ToArray(), strDest.ToArray(), penOpt);
        }
Example #6
0
 /// <summary>
 /// Copies the properties.
 /// </summary>
 /// <param name="pobSrc">The pob SRC.</param>
 /// <param name="pobDest">The pob dest.</param>
 /// <param name="penOpt">The pen opt.</param>
 public static void CopyProperties(object pobSrc, object pobDest, OptionTyp penOpt)
 {
     SetProperties(GetProperties(pobSrc), pobDest, penOpt);
 }
Example #7
0
        /// <summary>
        /// Sets the property.
        /// </summary>
        /// <param name="pobObj">The pob obj.</param>
        /// <param name="pstPropertyName">Name of the PST property.</param>
        /// <param name="pobValue">The pob value.</param>
        /// <param name="penOpt">The pen opt.</param>
        public static void SetProperty(object pobObj, string pstPropertyName, object pobValue, OptionTyp penOpt)
        {
            if (null == pobObj || string.IsNullOrEmpty(pstPropertyName))
            {
                throw new ArgumentNullException("one argument is null!");
            }
            bool         isIgnoreCase            = ((penOpt & OptionTyp.IsIgnoreCase) == OptionTyp.IsIgnoreCase);
            bool         isConvert               = ((penOpt & OptionTyp.IsConvert) == OptionTyp.IsConvert);
            bool         isThrowConvertException = ((penOpt & OptionTyp.IsThrowConvertException) == OptionTyp.IsThrowConvertException);
            Type         t       = pobObj.GetType();
            PropertyInfo objInfo = null;

            if (isIgnoreCase)
            {
                PropertyInfo[] objInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                foreach (PropertyInfo p in objInfos)
                {
                    if (p.Name.ToUpperInvariant().Equals(pstPropertyName.ToUpperInvariant()))
                    {
                        objInfo = p;
                        break;
                    }
                }
            }
            else
            {
                objInfo = t.GetProperty(pstPropertyName, BindingFlags.Instance | BindingFlags.Public);
            }
            if (null == objInfo)
            {
                throw new MapPropertyException("no mapping property");
            }
            object descVal = null;

            if (null == pobValue || !isConvert)
            {
                descVal = pobValue;
            }
            else
            {
                Type srcPropertyType  = pobValue.GetType();
                Type destPropertyType = objInfo.PropertyType;
                if (srcPropertyType.Equals(destPropertyType))
                {
                    descVal = pobValue;
                }
                else
                {
                    MethodInfo methodinfo = typeof(Convert).GetMethod("To" + destPropertyType.Name, new Type[] { srcPropertyType });
                    try
                    {
                        descVal = methodinfo.Invoke(null, new object[] { pobValue });
                    }
                    catch
                    {
                        if (isThrowConvertException)
                        {
                            throw new ConvertException("can't convert");
                        }
                        descVal = null;
                    }
                }
            }
            objInfo.SetValue(pobObj, descVal, null);
        }
Example #8
0
 /// <summary>
 /// Copies the property.
 /// </summary>
 /// <param name="pobSrc">The pob SRC.</param>
 /// <param name="pobDest">The pob dest.</param>
 /// <param name="pstSrcPropertyName">Name of the PST SRC property.</param>
 /// <param name="pstDestPropertyName">Name of the PST dest property.</param>
 /// <param name="penOpt">The pen opt.</param>
 public static void CopyProperty(object pobSrc, object pobDest, string pstSrcPropertyName, string pstDestPropertyName, OptionTyp penOpt)
 {
     SetProperty(pobDest, pstDestPropertyName, GetProperty(pobSrc, pstSrcPropertyName, penOpt), penOpt);
 }
Example #9
0
 /// <summary>
 /// Sets the properties.
 /// </summary>
 /// <param name="pdiProperties">The pdi properties.</param>
 /// <param name="pobObj">The pob obj.</param>
 /// <param name="penOpt">The pen opt.</param>
 public static void SetProperties(Dictionary <String, object> pdiProperties, object pobObj, OptionTyp penOpt)
 {
     foreach (KeyValuePair <String, object> pair in pdiProperties)
     {
         try
         {
             SetProperty(pobObj, pair.Key, pair.Value, penOpt);
         }
         catch (MapPropertyException) { }
     }
 }