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
- IncomingWebResponseContext.cs
- DateTimeFormatInfo.cs
- NativeMethods.cs
- BamlResourceContent.cs
- ConnectionManagementSection.cs
- XmlEventCache.cs
- SiteMapNodeCollection.cs
- TriggerActionCollection.cs
- MetadataUtilsSmi.cs
- UTF7Encoding.cs
- BitmapEffectDrawing.cs
- DataChangedEventManager.cs
- GridViewSelectEventArgs.cs
- OlePropertyStructs.cs
- TextBoxBase.cs
- CommandID.cs
- SrgsElementList.cs
- RelationshipConverter.cs
- UriSection.cs
- InstanceNotReadyException.cs
- MexHttpsBindingCollectionElement.cs
- SqlDataSourceView.cs
- SerTrace.cs
- SqlResolver.cs
- EventWaitHandle.cs
- SemanticTag.cs
- SoapIncludeAttribute.cs
- QilXmlWriter.cs
- StylusPointProperty.cs
- TemplateApplicationHelper.cs
- WorkflowMessageEventArgs.cs
- UndoManager.cs
- SqlXml.cs
- OpCopier.cs
- UpdateException.cs
- ControlPaint.cs
- Paragraph.cs
- ArithmeticLiteral.cs
- ScriptDescriptor.cs
- XmlNamespaceMapping.cs
- TypedTableGenerator.cs
- ReachSerializationCacheItems.cs
- InputChannel.cs
- OracleConnectionStringBuilder.cs
- TextBoxAutoCompleteSourceConverter.cs
- TextTreeTextNode.cs
- DynamicContractTypeBuilder.cs
- StorageMappingItemLoader.cs
- CodeTypeReferenceCollection.cs
- InputScopeAttribute.cs
- TypeConverterAttribute.cs
- ContentDisposition.cs
- SystemNetworkInterface.cs
- coordinatorscratchpad.cs
- TypeInitializationException.cs
- ControlIdConverter.cs
- ExpressionVisitorHelpers.cs
- DataGridViewButtonCell.cs
- Oid.cs
- ByeOperation11AsyncResult.cs
- COM2PictureConverter.cs
- NamedPipeTransportManager.cs
- MsmqIntegrationSecurityMode.cs
- DefaultObjectMappingItemCollection.cs
- ChannelEndpointElementCollection.cs
- PagerStyle.cs
- SingleTagSectionHandler.cs
- TableItemPatternIdentifiers.cs
- URLIdentityPermission.cs
- COM2DataTypeToManagedDataTypeConverter.cs
- HtmlInputRadioButton.cs
- SmiRecordBuffer.cs
- TcpChannelHelper.cs
- SpeechUI.cs
- WebPartUtil.cs
- XmlStringTable.cs
- precedingsibling.cs
- Bits.cs
- ConfigurationLocation.cs
- RuleCache.cs
- _UriSyntax.cs
- StringFunctions.cs
- FlowDocumentReader.cs
- XmlTextEncoder.cs
- IPHostEntry.cs
- MimeTypeAttribute.cs
- CodeObjectCreateExpression.cs
- ForeignConstraint.cs
- CompiledELinqQueryState.cs
- ColorPalette.cs
- VersionedStreamOwner.cs
- DBAsyncResult.cs
- CodeTypeReferenceCollection.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- AuthenticationConfig.cs
- SystemFonts.cs
- StringKeyFrameCollection.cs
- AssemblyCollection.cs
- SystemException.cs
- ProgressBarBrushConverter.cs