Пример #1
0
 public void DeploySetters(Object output, MetaEntity entity, TypedObjectProvider provider)
 {
     foreach (TypePropertyMapItem item in provider.items)
     {
         if (item.metaProperty == null)
         {
         }
         else
         {
             MetaPropertySetter setter = entity.GetSetter(item.metaProperty.PropertyName);
             if (setter != null)
             {
                 Object setterValue = setter.Value;
                 if (setterValue != null)
                 {
                     if (item.converter != null)
                     {
                         setterValue = item.converter.Convert(setterValue);
                     }
                     SetPropertyValue(item.metaProperty, item.propertyInfo, setterValue, output, true);
                 }
             }
         }
     }
 }
        //public TypePropertyMap(Type _type, TaskPropertyDictionary schema, TypePropertyMapDefinition definition, IDataMiningTypeProvider typeProvider)
        //{
        //    type = _type;
        //    typeProvider = typeProvider;

        //    Dictionary<String, TypePropertyMapDefinitionItem> mappedProperties = new Dictionary<string, TypePropertyMapDefinitionItem>();
        //    Dictionary<MetaTablePropertyAliasEntry, PropertyInfo> reverseMap = new Dictionary<MetaTablePropertyAliasEntry, PropertyInfo>();

        //    MetaTablePropertyAliasList alist = new MetaTablePropertyAliasList();

        //    var prop = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);



        //    List<TaskPropertyEntry> taskProperties = new List<TaskPropertyEntry>();

        //    foreach (TypePropertyMapDefinitionItem item in definition.items)
        //    {

        //        var pi = prop.FirstOrDefault(x => x.Name.Equals(item.typePropertyName));

        //        //if (item.IsUID)
        //        //{
        //        //    TypeUIDProperty = prop.FirstOrDefault(x => x.Name.Equals(item.typePropertyName, StringComparison.InvariantCultureIgnoreCase));
        //        //    UIDMetaProperties.items.Add(item.metaPropertyNames);
        //        //}

        //        if (pi == null)
        //        {
        //            throw new Exception("Specified property name [" + item.typePropertyName + "] not found in type [" + type.Name + "]");
        //        }

        //        alist.items.Add(item.metaPropertyNames);

        //        taskProperties.AddRange(taskProperties.Where(x => item.metaPropertyNames.isMatch(x.propertyName)));

        //        mappedProperties.Add(item.typePropertyName, item);
        //        reverseMap.Add(item.metaPropertyNames, pi);
        //    }

        //    foreach (MetaTableProperty item in taskProperties.Select(x=>x.Meta))
        //    {
        //        MetaTablePropertyAliasEntry a = alist.Match(item.PropertyName);
        //        if (a != null)
        //        {
        //            var pi = reverseMap[a];
        //            propertyLinkABs.Add(item, pi);
        //            propertyLinkBAs.Add(pi,item);
        //        }
        //    }
        //    SetDefaultInstance();
        //}

        /// <summary>
        /// Sets values from <see cref="MetaEntity.Setters"/> items of <c>MetaEntity</c>
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="existing">The existing.</param>
        /// <param name="OverwriteExisting">if set to <c>true</c> [overwrite existing].</param>
        /// <returns></returns>
        public Object SetObjectByMetaEntitySetters(MetaEntity entity, Object existing = null, Boolean OverwriteExisting = true)
        {
            if (existing == null)
            {
                existing = type.getInstance(null);
            }

            foreach (KeyValuePair <MetaTableProperty, PropertyInfo> pair in propertyLinkABs)
            {
                MetaPropertySetter setter = entity.GetSetter(pair.Key.PropertyName);

                if (setter == null)
                {
                    continue;
                }

                SetPropertyValue(pair.Key, pair.Value, setter.Value, existing, OverwriteExisting);
            }

            return(existing);
        }