コード例 #1
0
        public GridViewExtension GridView(Action <LOSGridSettings> method)
        {
            Action <LOSGridSettings> tmpMethod = (Action <LOSGridSettings>)method.Clone();
            var tmpInstance = new LOSGridSettings();

            tmpInstance.Columns.IsInit = true;
            method.Invoke(tmpInstance);
            if (tmpInstance.DataSource == null || !tmpInstance.DataSource.GetType().IsGenericType)
            {
                throw new InvalidOperationException("Cannot bind data source without generic type");
            }
            var modelType       = tmpInstance.DataSource.GetType().GetGenericArguments()[0];
            var settingInstance = new LOSGridSettings(ModelExtensionsHelper.GetModelMetadataForModel(modelType), HtmlHelper.ViewContext);

            tmpMethod?.Invoke(settingInstance);
            var gridView = new GridViewExtension(settingInstance, HtmlHelper.ViewContext);

            gridView = gridView.Bind(settingInstance.DataSource);
            return(gridView);
        }