Пример #1
0
        protected internal override void Scaffold()
        {
            ModelMetadata codeModelModelMetadatum;

            if (!base.Model.ViewTemplate.IsModelRequired)
            {
                codeModelModelMetadatum = new CodeModelModelMetadata();
                base.Model.IsReferenceScriptLibrariesSelected = false;
            }
            else if (base.Model.DataContextType == null)
            {
                codeModelModelMetadatum = (base.Model.ModelType == null ? new CodeModelModelMetadata() : new CodeModelModelMetadata(base.Model.ModelType.CodeType));
            }
            else
            {
                IEntityFrameworkService service = base.Context.ServiceProvider.GetService <IEntityFrameworkService>();
                codeModelModelMetadatum = service.AddRequiredEntity(base.Context, base.Model.DataContextType.TypeName, base.Model.ModelType.TypeName);
            }
            try
            {
                this.GenerateView(codeModelModelMetadatum, base.Model.SelectionRelativePath);
            }
            finally
            {
                base.Context.AddTelemetryData("MvcViewScaffolderOptions", (uint)this.GetTelemetryOptions());
                base.Context.AddTelemetryData("MvcViewTemplateName", base.Model.ViewTemplate.Name);
            }
        }
 public CodeModelModelMetadata(CodeType model)
 {
     if (model == null)
     {
         throw new ArgumentNullException("model");
     }
     base.Properties  = CodeModelModelMetadata.GetModelProperties(model).ToArray <PropertyMetadata>();
     base.PrimaryKeys = (
         from mp in CodeModelModelMetadata.GetModelProperties(model)
         where mp.IsPrimaryKey
         select mp).ToArray <PropertyMetadata>();
 }
        private static IList <PropertyMetadata> GetModelProperties(CodeType codeType)
        {
            IList <PropertyMetadata> propertyMetadatas = new List <PropertyMetadata>();

            foreach (CodeProperty codeProperty in CodeTypeExtensions.GetPublicMembers(codeType).OfType <CodeProperty>())
            {
                if (!CodePropertyExtensions.HasPublicGetter(codeProperty) || CodePropertyExtensions.IsIndexerProperty(codeProperty) || !CodeModelModelMetadata.IsBindableType(codeProperty.Type))
                {
                    continue;
                }
                propertyMetadatas.Add(new CodeModelPropertyMetadata(codeProperty));
            }
            return(propertyMetadatas);
        }