Exemplo n.º 1
0
        protected static void FillNullsFrom(ICloudObject thisObject, ICloudObject otherObject)
        {
            /* Fill otherObject null properties with
             * this object object properties.
             */

            var sourceProps = otherObject.GetType().GetRuntimeProperties()
                              .Where(x => x.CanWrite).ToList();
            var destProps = otherObject.GetType().GetRuntimeProperties()
                            .Where(x => x.CanWrite).ToList();

            foreach (var sourceProp in sourceProps)
            {
                var value = sourceProp.GetValue(thisObject, null);
                var p     = destProps.FirstOrDefault(x => x.Name == sourceProp.Name);

                if (p != null)
                {
                    var valueDst = p.GetValue(otherObject, null);

                    if (valueDst == null)
                    {
                        p.SetValue(otherObject, value, null);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public CloudnameAttribute GetCloudname()
        {
            MemberInfo memberInfo = _helpee.GetType();

            return(memberInfo.GetCustomAttributes(true)
                   .FirstOrDefault(attr => attr.GetType()
                                   == typeof(CloudnameAttribute)) as CloudnameAttribute);
        }
Exemplo n.º 3
0
        public void CopyTo(ICloudObject otherObject)
        {
            if (otherObject.GetType().IsAssignableFrom(_helpee.GetType()) ||
                _helpee.GetType().IsAssignableFrom(otherObject.GetType()))
            {
                var sourceProps = _helpee.GetType().GetRuntimeProperties()
                                  .Where(x => x.CanWrite).ToList();
                var destProps = otherObject.GetType().GetRuntimeProperties()
                                .Where(x => x.CanWrite).ToList();

                foreach (var sourceProp in sourceProps)
                {
                    var destProp = destProps.FirstOrDefault(
                        prop => (prop.Name == sourceProp.Name &&
                                 prop.GetType() == sourceProp.GetType()));

                    if (destProp != null)
                    {
                        destProp.SetValue(otherObject, sourceProp.GetValue(_helpee, null), null);
                    }
                }
            }
        }