Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CompMod / System / Diagnostics / TraceUtils.cs / 1 / TraceUtils.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System.Configuration;
using System;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Collections;
using System.Collections.Specialized;
namespace System.Diagnostics {
internal static class TraceUtils {
internal static object GetRuntimeObject(string className, Type baseType, string initializeData) {
Object newObject = null;
Type objectType = null;
if (className.Length == 0) {
throw new ConfigurationErrorsException(SR.GetString(SR.EmptyTypeName_NotAllowed));
}
objectType = Type.GetType(className);
if (objectType == null) {
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_find_type, className));
}
if (!baseType.IsAssignableFrom(objectType))
throw new ConfigurationErrorsException(SR.GetString(SR.Incorrect_base_type, className, baseType.FullName));
Exception innerException = null;
try {
if (String.IsNullOrEmpty(initializeData)) {
if (IsOwnedTextWriterTL(objectType))
throw new ConfigurationErrorsException(SR.GetString(SR.TextWriterTL_DefaultConstructor_NotSupported));
// create an object with parameterless constructor
ConstructorInfo ctorInfo = objectType.GetConstructor(new Type[] {});
if (ctorInfo == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
newObject = ctorInfo.Invoke(new object[] {});
}
else {
// create an object with a one-string constructor
// first look for a string constructor
ConstructorInfo ctorInfo = objectType.GetConstructor(new Type[] { typeof(string) });
if (ctorInfo != null) {
// Special case to enable specifying relative path to trace file from config for
// our own TextWriterTraceListener derivatives. We will prepend it with fullpath
// prefix from config file location
if (IsOwnedTextWriterTL(objectType)) {
if ((initializeData[0] != Path.DirectorySeparatorChar) && (initializeData[0] != Path.AltDirectorySeparatorChar) && !Path.IsPathRooted(initializeData)) {
string filePath = DiagnosticsConfiguration.ConfigFilePath;
if (!String.IsNullOrEmpty(filePath)) {
string dirPath = Path.GetDirectoryName(filePath);
if (dirPath != null)
initializeData = Path.Combine(dirPath, initializeData);
}
}
}
newObject = ctorInfo.Invoke(new object[] { initializeData });
}
else {
// now look for another 1 param constructor.
ConstructorInfo[] ctorInfos = objectType.GetConstructors();
if (ctorInfos == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
for (int i=0; i
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System.Configuration;
using System;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Collections;
using System.Collections.Specialized;
namespace System.Diagnostics {
internal static class TraceUtils {
internal static object GetRuntimeObject(string className, Type baseType, string initializeData) {
Object newObject = null;
Type objectType = null;
if (className.Length == 0) {
throw new ConfigurationErrorsException(SR.GetString(SR.EmptyTypeName_NotAllowed));
}
objectType = Type.GetType(className);
if (objectType == null) {
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_find_type, className));
}
if (!baseType.IsAssignableFrom(objectType))
throw new ConfigurationErrorsException(SR.GetString(SR.Incorrect_base_type, className, baseType.FullName));
Exception innerException = null;
try {
if (String.IsNullOrEmpty(initializeData)) {
if (IsOwnedTextWriterTL(objectType))
throw new ConfigurationErrorsException(SR.GetString(SR.TextWriterTL_DefaultConstructor_NotSupported));
// create an object with parameterless constructor
ConstructorInfo ctorInfo = objectType.GetConstructor(new Type[] {});
if (ctorInfo == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
newObject = ctorInfo.Invoke(new object[] {});
}
else {
// create an object with a one-string constructor
// first look for a string constructor
ConstructorInfo ctorInfo = objectType.GetConstructor(new Type[] { typeof(string) });
if (ctorInfo != null) {
// Special case to enable specifying relative path to trace file from config for
// our own TextWriterTraceListener derivatives. We will prepend it with fullpath
// prefix from config file location
if (IsOwnedTextWriterTL(objectType)) {
if ((initializeData[0] != Path.DirectorySeparatorChar) && (initializeData[0] != Path.AltDirectorySeparatorChar) && !Path.IsPathRooted(initializeData)) {
string filePath = DiagnosticsConfiguration.ConfigFilePath;
if (!String.IsNullOrEmpty(filePath)) {
string dirPath = Path.GetDirectoryName(filePath);
if (dirPath != null)
initializeData = Path.Combine(dirPath, initializeData);
}
}
}
newObject = ctorInfo.Invoke(new object[] { initializeData });
}
else {
// now look for another 1 param constructor.
ConstructorInfo[] ctorInfos = objectType.GetConstructors();
if (ctorInfos == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NonPrimarySelectionGlyph.cs
- Serializer.cs
- ArrayElementGridEntry.cs
- HyperLinkColumn.cs
- AssemblyCollection.cs
- InheritablePropertyChangeInfo.cs
- SplitterEvent.cs
- DataBoundControl.cs
- HtmlButton.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- Viewport3DVisual.cs
- SystemException.cs
- AppearanceEditorPart.cs
- Image.cs
- ButtonBase.cs
- NativeActivityMetadata.cs
- ClientScriptManagerWrapper.cs
- ApplicationSecurityManager.cs
- wgx_sdk_version.cs
- MruCache.cs
- remotingproxy.cs
- ProxyWebPartManager.cs
- X509CertificateClaimSet.cs
- _SafeNetHandles.cs
- LocalizationParserHooks.cs
- DictionaryChange.cs
- MarginCollapsingState.cs
- TabPage.cs
- SerializationObjectManager.cs
- ColorConvertedBitmap.cs
- ImageClickEventArgs.cs
- SqlClientWrapperSmiStream.cs
- NavigatorOutput.cs
- ListViewHitTestInfo.cs
- XmlHierarchicalDataSourceView.cs
- MediaCommands.cs
- UniqueConstraint.cs
- XPathDocumentNavigator.cs
- MethodBuilderInstantiation.cs
- Material.cs
- NavigationProgressEventArgs.cs
- DropTarget.cs
- SharedPerformanceCounter.cs
- ObjectComplexPropertyMapping.cs
- SQLRoleProvider.cs
- SourceSwitch.cs
- XmlRawWriter.cs
- XamlToRtfParser.cs
- XpsDigitalSignature.cs
- UidManager.cs
- XmlToDatasetMap.cs
- CodeBinaryOperatorExpression.cs
- BitmapEffectInput.cs
- EventHandlingScope.cs
- TimeoutException.cs
- DataViewSetting.cs
- StylusCaptureWithinProperty.cs
- ArrayConverter.cs
- ListViewGroupItemCollection.cs
- CodeCastExpression.cs
- HwndHost.cs
- SmtpMail.cs
- StringToken.cs
- EntityContainer.cs
- TextContainerHelper.cs
- MemberDescriptor.cs
- DataSourceXmlSerializationAttribute.cs
- XmlObjectSerializerWriteContext.cs
- PointAnimation.cs
- CommandConverter.cs
- PkcsUtils.cs
- RuntimeWrappedException.cs
- ProtectedProviderSettings.cs
- WebPartManager.cs
- InternalControlCollection.cs
- UndoManager.cs
- PageCatalogPart.cs
- OSFeature.cs
- FacetChecker.cs
- OrderByBuilder.cs
- returneventsaver.cs
- ReadOnlyDictionary.cs
- CharacterString.cs
- SourceFileInfo.cs
- ConnectionStringsSection.cs
- PermissionSetEnumerator.cs
- ListParaClient.cs
- ListDictionaryInternal.cs
- CssClassPropertyAttribute.cs
- SecurityException.cs
- DbQueryCommandTree.cs
- ProviderBase.cs
- DbProviderFactoriesConfigurationHandler.cs
- WebBrowser.cs
- TcpProcessProtocolHandler.cs
- SetterBaseCollection.cs
- InkCanvasSelection.cs
- Equal.cs
- _UriTypeConverter.cs
- DiagnosticTrace.cs