Ejemplo n.º 1
0
        public static T CopyProperties <T>(this object source, ref T result)
        {
            var sourceProperties = source.GetType().GetProperties().ToArray();
            var resultProperties = result.GetType().GetProperties().ToArray();

            for (int i = 0; i < sourceProperties.Length; i++)
            {
                System.Reflection.PropertyInfo sourceProperty = sourceProperties[i];
                if (sourceProperty.Name.ToLower() == "id")
                {
                    continue;
                }
                if (sourceProperty.GetType() == typeof(RateSegment) ||
                    sourceProperty.GetType() == typeof(Branch) ||
                    sourceProperty.GetType() == typeof(ReservationStatus))
                {
                    continue;
                }
                var resultProperty = resultProperties.FirstOrDefault(p => p.Name == sourceProperty.Name && sourceProperty.PropertyType == sourceProperty.PropertyType);
                if (resultProperty != null)
                {
                    resultProperty.SetValue(result, sourceProperty.GetValue(source));
                }

                //for (int j = 0; j < resultProperties.Length; j++)
                //{
                //    System.Reflection.PropertyInfo childProperty = resultProperties[j];
                //    if (sourceProperty.Name == childProperty.Name && sourceProperty.PropertyType == childProperty.PropertyType)
                //    {
                //        childProperty.SetValue(result, sourceProperty.GetValue(source));
                //        break;
                //    }
                //}
            }
            return(result);
        }
Ejemplo n.º 2
0
 //THIS DOESNT WORK - REMOVED FROM THE CHECK FUNCTION FOR NOW
 bool ProcessStructVariableTypes(object input, int inputType)
 {
     if (inputType == 0)
     {
         System.Reflection.PropertyInfo p = input as System.Reflection.PropertyInfo;
         Debug.Log("name: " + p.Name + " attributes: " + p.Attributes + " declaring type: " + p.DeclaringType + " accessors: " + p.GetAccessors() + " attributes: " + p.GetCustomAttributes(true) + " getmethod: " + p.GetGetMethod() + " setmethod: " + p.GetSetMethod() + " type: " + p.GetType() + " membertype: " + p.MemberType + " module: " + p.Module + " proptype: " + p.PropertyType + " reftype: " + p.ReflectedType);
         CompleteVariableSetup(16);
         return(false);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public GetterProperty(object target, string property)
        {
            var typ = typeof(T);

            // if there's a property with that name - use that property
            var eprp = typ.GetProperties().Where(i => i.Name == property);

            if (eprp.Any())
            {
                PRP = eprp.First();
                if (!(PRP.PropertyType is T))
                {
                    throw new ArgumentException(string.Format("Property '{0}' of type '{1}' ", PRP, PRP.GetType().Name));
                }
                return;
            }

            // if there's a field with that name - use that field
            var efld = typ.GetFields().Where(i => i.Name == property);

            if (efld.Any())
            {
                FLD = efld.First();
                return;
            }

            if (PRP == null)
            {
                throw new ArgumentException(string.Format("Type '{0}' doesn't contain property '{1}'", typ.Name, property));
            }
        }