예제 #1
0
        public virtual ActionResult PropertyItemHtml(object data, string propertyPath, int depth, string pathPrefix)
        {
            ViewData["propertyPath"] = (pathPrefix ?? "") + propertyPath;
            ViewData["addDepth"]     = depth - 1;
            string parentPath   = propertyPath.Contains(".") ? propertyPath.UpToLast(".") : "";
            string propertyName = (propertyPath.Contains(".") ? propertyPath.LastAfter(".") : propertyPath).UpTo("[");
            Type   parentType   = ReflectionX.GetPropertyTypeByPath(data.GetType(), parentPath);
            IList  list         = ReflectionX.GetPropertyValueByPath(data, propertyPath, true) as IList;
            var    listProp     = ReflectionX.GetPropertyByPath(data.GetType(), propertyPath);
            Type   listType     = listProp.PropertyType;

            if (listType.GetType().IsArray)
            {
                list    = (IList)Array.CreateInstance(ReflectionX.ElementType(listType), 1);
                list[0] = CreateInstance(listType.GetElementType());
            }
            else
            {
                list = (IList)Activator.CreateInstance(listType);
                list.Add(CreateInstance(ReflectionX.ElementType(listType)));
            }

            ViewData["list"] = list;
            var metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, parentType, propertyName);

            ViewData["CollectionAdditionalValues"] = metadata.AdditionalValues;

            RouteData.DataTokens.Add("CancelProcessingHtml", true);
            return(PartialView(ConfigHelper.GetViewPath("LyniconPropertyItem.cshtml"), data));
        }
        private void AddTypeInner(Type t)
        {
            if (t.GetInterface("IList") != null)
            {
                t = ReflectionX.ElementType(t);
            }

            if (TypeProperties.ContainsKey(t.AssemblyQualifiedName))
            {
                return;
            }

            var typeDict = new Dictionary <string, string>();

            TypeProperties.Add(t.AssemblyQualifiedName, typeDict);
            foreach (var prop in t.GetPersistedProperties())
            {
                if (typeDict.ContainsKey(prop.Name))
                {
                    log.Error("Property " + prop.Name + " repeated on type " + t.FullName);
                    continue;
                }
                typeDict.Add(prop.Name, prop.PropertyType.AssemblyQualifiedName);
                if (!prop.PropertyType.FullName.StartsWith("System."))
                {
                    AddTypeInner(prop.PropertyType);
                }
            }
        }
예제 #3
0
 public override void List(System.Reflection.PropertyInfo pi, System.Collections.IList val)
 {
     if (val == null)
     {
         NullProperty = pi;
     }
     else
     {
         NullProperty = new NoNullObjectCheck().Run(ReflectionX.ElementType(val)) ?? NullProperty;
     }
 }