Пример #1
0
 public PropertyMapEndpoint(PropertyInfo _property, PropertyMapLinkFlags _flags, Object DefaultInstance = null)
 {
     property = _property;
     IsIList  = _property.PropertyType.IsIList();
     if (DefaultInstance != null)
     {
         if (!IsIList)
         {
             DefaultValue    = property.GetValue(DefaultInstance, null);
             DefaultValueSet = true;
         }
     }
 }
        /// <summary>
        /// Adds the link.
        /// </summary>
        /// <param name="sourceProperty">The source property.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="flags">The flags.</param>
        /// <returns>Null if source or target property was not found</returns>
        public PropertyMapLink AddLink(String sourceProperty, String targetProperty, PropertyMapLinkFlags flags = PropertyMapLinkFlags.none)
        {
            PropertyInfo f_pi = null;
            PropertyInfo t_pi = null;


            if (Options.HasFlag(PropertyMapGenerationOptions.ignoreCase))
            {
                f_pi = fromProps.Search(sourceProperty, StringComparison.InvariantCultureIgnoreCase, true).FirstOrDefault();
                t_pi = toProps.Search(targetProperty, StringComparison.InvariantCultureIgnoreCase, true).FirstOrDefault();
            }
            else
            {
                if (!fromProps.ContainsKey(sourceProperty))
                {
                    return(null);
                }
                if (!toProps.ContainsKey(targetProperty))
                {
                    return(null);
                }

                f_pi = fromProps[sourceProperty]; //, StringComparison.InvariantCultureIgnoreCase, true).FirstOrDefault();
                t_pi = toProps[targetProperty];   //, StringComparison.InvariantCultureIgnoreCase, true).FirstOrDefault();
            }

            if (f_pi == null || t_pi == null)
            {
                return(null);
            }

            if (ContainsLink(f_pi, t_pi))
            {
                return(null);
            }


            PropertyMapLink link = PropertyMapLink.Create(f_pi, t_pi, this, flags);

            if (link != null)
            {
                Links.Add(link);
            }
            return(link);
        }
Пример #3
0
        public static PropertyMapLink Create(PropertyInfo source, PropertyInfo target, IPropertyMapSocket socket, PropertyMapLinkFlags flags = PropertyMapLinkFlags.none)
        {
            if (!target.CanWrite)
            {
                return(null);
            }
            if (!source.CanRead)
            {
                return(null);
            }
            if (!target.GetIndexParameters().isNullOrEmpty())
            {
                return(null);
            }
            if (!source.GetIndexParameters().isNullOrEmpty())
            {
                return(null);
            }

            if (flags == PropertyMapLinkFlags.none)
            {
                flags = socket.GeneralLinkOptions;
            }
            PropertyMapLink output = new PropertyMapLink();

            output.Source = new PropertyMapEndpoint(source, flags, socket.FromDefaultInstance);
            output.Target = new PropertyMapEndpoint(target, flags, socket.ToDefaultInstance);

            return(output);
        }