Exemplo n.º 1
0
        protected override bool Match(ConventionInfo convention)
        {
            //Note: We don't map metadata, because ApplicationService does it.
            Type targetPropType = convention.TargetProp.Type;
            Type sourcePropType = convention.SourceProp.Type;

            if (sourcePropType != targetPropType)
            {
                return false;
            }

            return base.Match(convention);
        }
 protected override bool Match(ConventionInfo convention)
 {
     return String.Equals(convention.SourceProp.Name, convention.TargetProp.Name, StringComparison.InvariantCultureIgnoreCase);
 }
Exemplo n.º 3
0
 protected override object SetValue(ConventionInfo v)
 {
     return(v.SourceProp.Value == null ? null : (v.SourceProp.Value as IEnumerable <Entity>).Select(o => o.Id));
 }
Exemplo n.º 4
0
 protected override bool Match(ConventionInfo c)
 {
     return(c.SourceProp.Name == "CustomerCountries" &&
            c.TargetProp.Name == "Countries" &&
            c.SourceProp.Value != null);
 }
Exemplo n.º 5
0
 protected override object SetValue(ConventionInfo c)
 {
     return(c.SourceProp.Value.ToString());
 }
Exemplo n.º 6
0
            protected override void Inject(object source, object target)
            {
                if (!knownObjects.ContainsKey(source))
                {
                    knownObjects.Add(source, target);
                }
                foreach (var sp in source.GetType().GetProperties(
                             BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                         .Where(p => p.GetGetMethod(true) != null && p.GetIndexParameters().Count() == 0)
                         .OrderBy(p => p.HasAttribute <SerializationPriorityAttribute>() ? p.GetCustomAttribute <SerializationPriorityAttribute>().Priority : int.MaxValue))
                {
                    var tp = target.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.GetSetMethod(true) != null && p.GetIndexParameters().Count() == 0 && p.Name == sp.Name).SingleOrDefault();
                    if (tp != null)
                    {
                        var c = new ConventionInfo
                        {
                            Source = new ConventionInfo.TypeInfo {
                                Type = sp.DeclaringType
                            },
                            SourceProp = new ConventionInfo.PropInfo {
                                Name = sp.Name
                            },
                            Target = new ConventionInfo.TypeInfo {
                                Type = tp.DeclaringType
                            },
                            TargetProp = new ConventionInfo.PropInfo {
                                Name = tp.Name
                            },
                        };
                        if (Match(c))
                        {
                            bool doit  = true;
                            bool regen = false;
                            if (source is Component && ((Component)source).Hitpoints == 0)
                            {
                            }
                            if (source is IReferrable && sp.Name == "ID")
                            {
                                // do special things for IDs
                                var behavior = source == Root ? RootBehavior : SubordinateBehavior;
                                if (behavior == IDCopyBehavior.PreserveSource)
                                {
                                    doit = true;
                                }
                                else if (behavior == IDCopyBehavior.PreserveDestination)
                                {
                                    doit = false;
                                }
                                else if (behavior == IDCopyBehavior.Regenerate)
                                {
                                    doit  = false;
                                    regen = true;
                                }
                            }

                            object sv = null;

                            if (doit && CanCopyFully(sp) && DeepCopy)
                            {
                                sv = sp.GetValue(source, null);
                                if (sv == null)
                                {
                                    sp.SetValue(target, null, null);                                     // it's null, very simple
                                }
                                else if (!knownObjects.ContainsKey(sv))
                                {
                                    // copy object and use the copy
                                    var tv = CopyObject(source, sv);
                                    sp.SetValue(target, tv, null);
                                }
                                else
                                {
                                    sp.SetValue(target, knownObjects[sv], null);                                     // known object, don't bother copying again
                                }
                            }
                            else if (doit && CanCopySafely(sp))
                            {
                                sv = sp.GetValue(source, null);
                                if (knownObjects.ContainsKey(sv))
                                {
                                    sp.SetValue(target, knownObjects[sv]);                                     // use known copy
                                }
                                else
                                {
                                    sp.SetValue(target, sv, null);                                     // use original object
                                }
                            }

                            if (regen)
                            {
                                // reassign ID
                                var r = target as IReferrable;
                                if (r.HasValidID())
                                {
                                    r.ReassignID();
                                }
                            }
                        }
                    }
                }
                if (target is ICleanable)
                {
                    (target as ICleanable).Clean();
                }
            }
Exemplo n.º 7
0
 protected override object SetValue(ConventionInfo c)
 {
     // don't override these values
     return(c.TargetProp.Value);
 }
        protected override object SetValue(ConventionInfo c)
        {
            //for value types and string just return the value as is
            if (c.SourceProp.Type.IsValueType || c.SourceProp.Type == typeof(string))
            {
                return(c.SourceProp.Value);
            }

            //handle arrays
            if (c.SourceProp.Type.IsArray)
            {
                var arr   = c.SourceProp.Value as Array;
                var clone = arr.Clone() as Array;

                for (int index = 0; index < arr.Length; index++)
                {
                    var a = arr.GetValue(index);
                    if (a.GetType().IsValueType || a.GetType() == typeof(string))
                    {
                        continue;
                    }
                    clone.SetValue(Activator.CreateInstance(a.GetType()).InjectFrom <CloneInjection>(a), index);
                }
                return(clone);
            }


            if (c.SourceProp.Type.IsGenericType)
            {
                //handle IEnumerable<> also ICollection<> IList<> List<>
                if (c.SourceProp.Type.GetGenericTypeDefinition().GetInterfaces().Contains(typeof(IEnumerable)))
                {
                    var t = c.SourceProp.Type.GetGenericArguments()[0];
                    if (t.IsValueType || t == typeof(string))
                    {
                        return(c.SourceProp.Value);
                    }

                    /*
                     * var tlist = typeof(List<>).MakeGenericType(t);
                     * //var list = Activator.CreateInstance(tlist);
                     * dynamic list = Activator.CreateInstance(tlist);
                     *
                     * var addMethod = tlist.GetMethod("Add");
                     * foreach (var o in c.SourceProp.Value as IEnumerable) {
                     *  var e = Activator.CreateInstance(t).InjectFrom<CloneInjection>(o);
                     *  //addMethod.Invoke(list, new[] { e }); // in 4.0 you can use dynamic and just do list.Add(e);
                     *  list.Add(e);
                     * }
                     * */
                    var     tlist = typeof(List <>).MakeGenericType(t);
                    dynamic list  = Activator.CreateInstance(tlist);
                    return(list);
                }

                //unhandled generic type, you could also return null or throw
                return(c.SourceProp.Value);
            }

            //for simple object types create a new instace and apply the clone injection on it
            return(Activator.CreateInstance(c.SourceProp.Type)
                   .InjectFrom <CloneInjection>(c.SourceProp.Value));
        }
Exemplo n.º 9
0
        protected override bool Match(ConventionInfo c)
        {
            _comparison = StringComparison.OrdinalIgnoreCase;

            return(base.Match(c));
        }
Exemplo n.º 10
0
        protected override bool Match(ConventionInfo c)
        {
            var result = AuditNames.Contains(c.TargetProp.Name);

            return(result);
        }
Exemplo n.º 11
0
 protected override bool Match(ConventionInfo c)
 {
     return(c.SourceProp.Type == typeof(double) && c.TargetProp.Type == typeof(float));
 }
Exemplo n.º 12
0
        private static object MapLists(ConventionInfo conventionInfo)
        {
            var genericArgument = conventionInfo.TargetProp.Type.GetGenericArguments()[0];

            return(MapLists(genericArgument, conventionInfo.SourceProp.Value));
        }
Exemplo n.º 13
0
 protected override bool Match(ConventionInfo c)
 {
     return(c.SourceProp.Name == c.TargetProp.Name && c.SourceProp.Type == typeof(string) && allowedProperties.Contains(c.SourceProp.Name));
 }
Exemplo n.º 14
0
 protected override object SetValue(ConventionInfo c)
 {
     return(((Entity)c.SourceProp.Value).Id);
 }
Exemplo n.º 15
0
 protected override bool Match(ConventionInfo c)
 {
     return(c.TargetProp.Name == c.SourceProp.Name + "Id" &&
            c.SourceProp.Type.IsSubclassOf(typeof(Entity)) && c.TargetProp.Type == typeof(int) &&
            c.SourceProp.Value != null);
 }