Beispiel #1
0
        public static PSModel AddModel(Type ElementType)
        {
            if (PSModel.AllModels.ContainsKey(ElementType.Name))
            {
                return(PSModel.AllModels[ElementType.Name]);
            }

            var psModel = new PSModel(ElementType.Name);

            // Add to dictionary now to avoid loops
            AllModels[ElementType.Name] = psModel;

            foreach (var pro in ElementType.GetProperties())
            {
                var proName = pro.Name;

                var psParam = new PSParameter(pro.Name, pro.PropertyType);
                psParam.GenerateModel();

                psParam.AddValidate(pro.GetCustomAttributes(true));

                // Add parameter to dictionary
                psModel.Parameters.Add(psParam);
            }


            if (psModel.Parameters.Count != 0)
            {
                return(psModel);
            }
            else
            {
                return(null);
            }
        }
        public bool GenerateModel()
        {
            if (this.IsObject)
            {
                this.HasModel = PSModel.AddModel(this.Type) != null;
            }

            return(this.HasModel);
        }