Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Configuration / ConfigUtil.cs / 1 / ConfigUtil.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Configuration {
using System;
using System.Threading;
using System.Configuration;
using System.Xml;
using System.Web.Compilation;
using System.Web.Util;
internal class ConfigUtil {
private ConfigUtil() {
}
internal static void CheckBaseType(Type expectedBaseType, Type userBaseType, string propertyName, ConfigurationElement configElement) {
// Make sure the base type is valid
if (!expectedBaseType.IsAssignableFrom(userBaseType)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_type_to_inherit_from,
userBaseType.FullName,
expectedBaseType.FullName), configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement,
XmlNode node, bool checkAptcaBit, bool ignoreCase) {
// We should get either a propertyName/configElement or node, but not both.
// They are used only for error reporting.
Debug.Assert((propertyName != null) != (node != null));
Type val;
try {
val = BuildManager.GetType(typeName, true /*throwOnError*/, ignoreCase);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
if (node != null) {
throw new ConfigurationErrorsException(e.Message, e, node);
}
else {
if (configElement != null) {
throw new ConfigurationErrorsException(e.Message, e,
configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
else {
throw new ConfigurationErrorsException(e.Message, e);
}
}
}
// If we're not in full trust, only allow types that have the APTCA bit (ASURT 139687),
// unless the checkAptcaBit flag is false
if (checkAptcaBit) {
if (node != null) {
HttpRuntime.FailIfNoAPTCABit(val, node);
}
else {
HttpRuntime.FailIfNoAPTCABit(val,
configElement != null ? configElement.ElementInformation : null,
propertyName);
}
}
return val;
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement) {
return GetType(typeName, propertyName, configElement, true /*checkAptcaBit*/);
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit) {
return GetType(typeName, propertyName, configElement, checkAptcaBit, false);
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit, bool ignoreCase) {
return GetType(typeName, propertyName, configElement, null /*node*/, checkAptcaBit, ignoreCase);
}
internal static Type GetType(string typeName, XmlNode node) {
return GetType(typeName, node, false /*ignoreCase*/);
}
internal static Type GetType(string typeName, XmlNode node, bool ignoreCase) {
return GetType(typeName, null, null, node, true /*checkAptcaBit*/, ignoreCase);
}
internal static void CheckAssignableType(Type baseType, Type type, ConfigurationElement configElement, string propertyName) {
if (!baseType.IsAssignableFrom(type)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Type_doesnt_inherit_from_type, type.FullName, baseType.FullName),
configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static void CheckAssignableType(Type baseType, Type baseType2, Type type, ConfigurationElement configElement, string propertyName) {
if (!baseType.IsAssignableFrom(type) && !baseType2.IsAssignableFrom(type)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Type_doesnt_inherit_from_type, type.FullName, baseType.FullName),
configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static bool IsTypeHandlerOrFactory(Type t) {
return typeof(IHttpHandler).IsAssignableFrom(t)
|| typeof(IHttpHandlerFactory).IsAssignableFrom(t);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Configuration {
using System;
using System.Threading;
using System.Configuration;
using System.Xml;
using System.Web.Compilation;
using System.Web.Util;
internal class ConfigUtil {
private ConfigUtil() {
}
internal static void CheckBaseType(Type expectedBaseType, Type userBaseType, string propertyName, ConfigurationElement configElement) {
// Make sure the base type is valid
if (!expectedBaseType.IsAssignableFrom(userBaseType)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Invalid_type_to_inherit_from,
userBaseType.FullName,
expectedBaseType.FullName), configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement,
XmlNode node, bool checkAptcaBit, bool ignoreCase) {
// We should get either a propertyName/configElement or node, but not both.
// They are used only for error reporting.
Debug.Assert((propertyName != null) != (node != null));
Type val;
try {
val = BuildManager.GetType(typeName, true /*throwOnError*/, ignoreCase);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
if (node != null) {
throw new ConfigurationErrorsException(e.Message, e, node);
}
else {
if (configElement != null) {
throw new ConfigurationErrorsException(e.Message, e,
configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
else {
throw new ConfigurationErrorsException(e.Message, e);
}
}
}
// If we're not in full trust, only allow types that have the APTCA bit (ASURT 139687),
// unless the checkAptcaBit flag is false
if (checkAptcaBit) {
if (node != null) {
HttpRuntime.FailIfNoAPTCABit(val, node);
}
else {
HttpRuntime.FailIfNoAPTCABit(val,
configElement != null ? configElement.ElementInformation : null,
propertyName);
}
}
return val;
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement) {
return GetType(typeName, propertyName, configElement, true /*checkAptcaBit*/);
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit) {
return GetType(typeName, propertyName, configElement, checkAptcaBit, false);
}
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit, bool ignoreCase) {
return GetType(typeName, propertyName, configElement, null /*node*/, checkAptcaBit, ignoreCase);
}
internal static Type GetType(string typeName, XmlNode node) {
return GetType(typeName, node, false /*ignoreCase*/);
}
internal static Type GetType(string typeName, XmlNode node, bool ignoreCase) {
return GetType(typeName, null, null, node, true /*checkAptcaBit*/, ignoreCase);
}
internal static void CheckAssignableType(Type baseType, Type type, ConfigurationElement configElement, string propertyName) {
if (!baseType.IsAssignableFrom(type)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Type_doesnt_inherit_from_type, type.FullName, baseType.FullName),
configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static void CheckAssignableType(Type baseType, Type baseType2, Type type, ConfigurationElement configElement, string propertyName) {
if (!baseType.IsAssignableFrom(type) && !baseType2.IsAssignableFrom(type)) {
throw new ConfigurationErrorsException(
SR.GetString(SR.Type_doesnt_inherit_from_type, type.FullName, baseType.FullName),
configElement.ElementInformation.Properties[propertyName].Source,
configElement.ElementInformation.Properties[propertyName].LineNumber);
}
}
internal static bool IsTypeHandlerOrFactory(Type t) {
return typeof(IHttpHandler).IsAssignableFrom(t)
|| typeof(IHttpHandlerFactory).IsAssignableFrom(t);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XslNumber.cs
- TextClipboardData.cs
- WebServiceTypeData.cs
- XmlSchemaSimpleTypeUnion.cs
- COAUTHINFO.cs
- AutomationPeer.cs
- OleCmdHelper.cs
- listviewsubitemcollectioneditor.cs
- TimeSpan.cs
- OdbcConnectionFactory.cs
- NavigationExpr.cs
- CheckBox.cs
- AnimatedTypeHelpers.cs
- ToolboxItemCollection.cs
- SecurityPolicySection.cs
- QueuePropertyVariants.cs
- FileDialogCustomPlaces.cs
- ReadOnlyCollection.cs
- DbTransaction.cs
- PolyLineSegment.cs
- ValidationErrorEventArgs.cs
- MetadataSerializer.cs
- DataGridViewTopRowAccessibleObject.cs
- FactoryRecord.cs
- DebuggerService.cs
- StoryFragments.cs
- VersionConverter.cs
- ChangeDirector.cs
- DataGridViewCellLinkedList.cs
- PopupEventArgs.cs
- DBCSCodePageEncoding.cs
- MultiBindingExpression.cs
- AutomationElementCollection.cs
- IRCollection.cs
- NamespaceImport.cs
- PTProvider.cs
- PrimitiveXmlSerializers.cs
- HandlerBase.cs
- SimpleHandlerBuildProvider.cs
- LogicalTreeHelper.cs
- RectangleHotSpot.cs
- LoginDesigner.cs
- DependencyPropertyChangedEventArgs.cs
- GridItem.cs
- HighContrastHelper.cs
- ApplicationBuildProvider.cs
- LocationUpdates.cs
- Item.cs
- DummyDataSource.cs
- HtmlInputSubmit.cs
- CanonicalFontFamilyReference.cs
- IODescriptionAttribute.cs
- WithParamAction.cs
- GroupItemAutomationPeer.cs
- CaseStatementProjectedSlot.cs
- TypeUsage.cs
- Matrix.cs
- Frame.cs
- DiagnosticsConfiguration.cs
- TableSectionStyle.cs
- TimeoutException.cs
- XPathDocumentIterator.cs
- CachedBitmap.cs
- SocketException.cs
- SqlCharStream.cs
- TableAdapterManagerHelper.cs
- ItemMap.cs
- formatter.cs
- XmlAnyElementAttributes.cs
- ScrollItemProviderWrapper.cs
- DependencyObject.cs
- FieldTemplateUserControl.cs
- CodeGenerator.cs
- DesignerTransactionCloseEvent.cs
- XmlQueryOutput.cs
- ComponentChangedEvent.cs
- _ServiceNameStore.cs
- Model3DGroup.cs
- Cursor.cs
- InternalCompensate.cs
- QueuePathEditor.cs
- ComplexBindingPropertiesAttribute.cs
- M3DUtil.cs
- ImpersonateTokenRef.cs
- SessionState.cs
- EntityDataSourceChangedEventArgs.cs
- RelationshipEnd.cs
- DesignTimeParseData.cs
- HitTestWithPointDrawingContextWalker.cs
- SolidColorBrush.cs
- DataGridViewLinkColumn.cs
- StrongNamePublicKeyBlob.cs
- TdsValueSetter.cs
- SmiMetaDataProperty.cs
- QilLoop.cs
- SubpageParagraph.cs
- TypeDelegator.cs
- MenuBase.cs
- BindingCompleteEventArgs.cs
- CultureInfoConverter.cs