Ejemplo n.º 1
0
        private static void CopyByDest(IDictionary <string, string> src, object dest, bool throwOnNotExist)
        {
            IReflector r = Reflector.Bind(dest);

            foreach (var property in r.FindAllPropertyNames())
            {
                if (src.ContainsKey(property))
                {
                    try
                    {
                        Type   pType = r.GetPropertyType(property);
                        object val   = TypeCast.ChangeToTypeOrNullableType(src[property], pType);
                        r.SetPropertyValue(property, val);
                    }
                    catch (Exception ex)
                    {
                        throw ex.CreateWrapException <CopyException>();
                    }
                }
                else
                {
                    if (throwOnNotExist)
                    {
                        ExceptionHelper.ThrowSourceKeyOrPropertyNotExist(property);
                    }
                    else
                    {
                        _log.Warning("Source dictionary does not have key [{0}].", property);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void CopyByBoth(object src, object dest)
        {
            IReflector rSrc  = Reflector.Bind(src);
            IReflector rDest = Reflector.Bind(dest);

            foreach (var pName in rSrc.FindAllPropertyNames())
            {
                if (rDest.ExistProperty(pName))
                {
                    rDest.SetPropertyValue(pName, rSrc.GetPropertyValue(pName));
                }
            }
        }
Ejemplo n.º 3
0
        private static void CopyByDest(object src, object dest, bool throwOnNotExist)
        {
            IReflector rSrc  = Reflector.Bind(src);
            IReflector rDest = Reflector.Bind(dest);

            foreach (var pName in rDest.FindAllPropertyNames())
            {
                if (!rSrc.ExistProperty(pName))
                {
                    if (throwOnNotExist)
                    {
                        ExceptionHelper.ThrowSourceKeyOrPropertyNotExist(pName);
                    }
                }

                rDest.SetPropertyValue(pName, rSrc.GetPropertyValue(pName));
            }
        }