1 //---------------------------------------------------------------------
2 // <copyright file="WebControlParameterProxy.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner objsdev
8 //---------------------------------------------------------------------
10 using System.Collections.Generic;
13 using System.Web.UI.WebControls;
14 using System.Diagnostics;
16 using System.Globalization;
18 namespace System.Web.UI.WebControls
20 internal class WebControlParameterProxy
22 ParameterCollection _collection;
23 EntityDataSource _entityDataSource;
24 Parameter _parameter; // Can be null, that's why this class doesn't subclass Parameter
26 internal WebControlParameterProxy(string propertyName, ParameterCollection parameterCollection, EntityDataSource entityDataSource)
28 Debug.Assert(null != entityDataSource);
29 Debug.Assert(!String.IsNullOrEmpty(propertyName));
31 _parameter = EntityDataSourceUtil.GetParameter(propertyName, parameterCollection);
32 _collection = parameterCollection;
33 _entityDataSource = entityDataSource;
34 VerifyUniqueType(_parameter);
36 internal WebControlParameterProxy(Parameter parameter, ParameterCollection parameterCollection, EntityDataSource entityDataSource)
38 Debug.Assert(null != entityDataSource);
39 _parameter = parameter;
40 _collection = parameterCollection;
41 _entityDataSource = entityDataSource;
42 VerifyUniqueType(_parameter);
48 if (null != _parameter)
50 return _parameter.Name;
55 internal bool HasValue
59 return null != _parameter &&
63 internal bool ConvertEmptyStringToNull
67 if (null != _parameter)
69 return _parameter.ConvertEmptyStringToNull;
74 internal TypeCode TypeCode
78 if (null != _parameter)
80 return _parameter.Type;
82 return TypeCode.Empty;
85 internal DbType DbType
89 if (null != _parameter)
91 return _parameter.DbType;
100 Debug.Assert(this.TypeCode != TypeCode.Empty || this.DbType != DbType.Object, "Need to have TypeCode or DbType to get a ClrType");
101 if (this.TypeCode != TypeCode.Empty)
103 return EntityDataSourceUtil.ConvertTypeCodeToType(this.TypeCode);
105 return EntityDataSourceUtil.ConvertDbTypeToType(this.DbType);
109 internal object Value
113 if (_parameter != null)
115 object paramValue = EntityDataSourceUtil.GetParameterValue(_parameter.Name, _collection, _entityDataSource);
117 if (paramValue != null)
119 if (this.DbType == DbType.DateTimeOffset)
121 object value = (paramValue is DateTimeOffset)
123 : DateTimeOffset.Parse(this.Value.ToString(), CultureInfo.CurrentCulture);
126 else if (this.DbType == DbType.Time)
128 object value = (paramValue is TimeSpan)
130 : TimeSpan.Parse(paramValue.ToString(), CultureInfo.CurrentCulture);
133 else if (this.DbType == DbType.Guid)
135 object value = (paramValue is Guid)
137 : new Guid(paramValue.ToString());
149 private static void VerifyUniqueType(Parameter parameter)
151 if (parameter != null && parameter.Type == TypeCode.Empty && parameter.DbType == DbType.Object)
153 throw new InvalidOperationException(Strings.WebControlParameterProxy_TypeDbTypeMutuallyExclusive);
156 if (parameter != null && parameter.DbType != DbType.Object && parameter.Type != TypeCode.Empty)
158 throw new InvalidOperationException(Strings.WebControlParameterProxy_TypeDbTypeMutuallyExclusive);