2 // DynamicDataExtensions.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Marek Habersack <mhabersack@novell.com>
8 // Copyright (C) 2008-2009 Novell Inc. http://novell.com
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Generic;
34 using System.Collections.Specialized;
35 using System.Globalization;
36 using System.Security.Permissions;
37 using System.Security.Principal;
38 using System.Web.Caching;
40 using System.Web.UI.WebControls;
41 using System.Web.DynamicData.ModelProviders;
43 namespace System.Web.DynamicData
45 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 public static class DynamicDataExtensions
48 public static object ConvertEditedValue (this IFieldFormattingOptions formattingOptions, string value)
50 // Not a surprise anymore...
51 if (formattingOptions == null)
52 throw new NullReferenceException ();
54 if (String.IsNullOrEmpty (value)) {
55 if (formattingOptions.ConvertEmptyStringToNull)
58 string nullDisplayText = formattingOptions.NullDisplayText;
59 if (!String.IsNullOrEmpty (nullDisplayText) && String.Compare (value, nullDisplayText, StringComparison.Ordinal) == 0)
67 public static void EnablePersistedSelection (this BaseDataBoundControl dataBoundControl)
69 throw new NotImplementedException ();
73 public static void ExpandDynamicWhereParameters (this IDynamicDataSource dataSource)
75 throw new NotImplementedException ();
79 public static IDynamicDataSource FindDataSourceControl (this Control current)
81 throw new NotImplementedException ();
85 public static Control FindFieldTemplate (this Control control, string columnName)
87 throw new NotImplementedException ();
90 public static MetaTable FindMetaTable (this Control current)
92 // .NET doesn't perform the check, we will
94 throw new NullReferenceException ();
96 while (current != null) {
97 DataBoundControl dbc = current as DataBoundControl;
99 IDynamicDataSource dds = dbc.DataSourceObject as IDynamicDataSource;
101 return dds.GetTable ();
104 current = current.NamingContainer;
111 public static string FormatEditValue (this IFieldFormattingOptions formattingOptions, object fieldValue)
113 throw new NotImplementedException ();
117 public static string FormatValue (this IFieldFormattingOptions formattingOptions, object fieldValue)
119 throw new NotImplementedException ();
122 static string GetDataSourceId (IDynamicDataSource dataSource)
124 Control c = dataSource as Control;
131 public static MetaTable GetTable (this IDynamicDataSource dataSource)
133 if (dataSource == null)
136 string entitySetName = dataSource.EntitySetName;
137 if (String.IsNullOrEmpty (entitySetName)) {
138 // LAMESPEC: MSDN says we should throw in this case, but .NET calls
139 // DynamicDataRouteHandler.GetRequestMetaTable(HttpContext
140 // httpContext) instead (eventually)
141 MetaTable ret = DynamicDataRouteHandler.GetRequestMetaTable (HttpContext.Current);
143 throw new InvalidOperationException ("The control '" + GetDataSourceId (dataSource) +
144 "' does not have a TableName property and a table name cannot be inferred from the URL.");
147 Type contextType = dataSource.ContextType;
148 if (contextType == null)
149 throw new InvalidOperationException ("The ContextType property of control '" + GetDataSourceId (dataSource) + "' must specify a data context");
151 return MetaModel.GetModel (contextType).GetTable (entitySetName);
155 public static void LoadWithForeignKeys (this LinqDataSource dataSource, Type rowType)
157 throw new NotImplementedException ();