Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridViewCheckBoxColumn.cs
- ApplicationHost.cs
- ISFClipboardData.cs
- ActivityMarkupSerializer.cs
- MetadataResolver.cs
- SoapSchemaMember.cs
- DataAdapter.cs
- ArithmeticException.cs
- MappableObjectManager.cs
- MemberHolder.cs
- WorkflowLayouts.cs
- SafeTimerHandle.cs
- DBSchemaRow.cs
- FormViewPagerRow.cs
- GetImportFileNameRequest.cs
- _NegotiateClient.cs
- SqlErrorCollection.cs
- SqlRowUpdatingEvent.cs
- PenContexts.cs
- DriveInfo.cs
- LayoutTableCell.cs
- CmsInterop.cs
- Aggregates.cs
- BamlTreeUpdater.cs
- DatatypeImplementation.cs
- ActivationServices.cs
- QueueSurrogate.cs
- BulletChrome.cs
- InvokeMethodActivity.cs
- AnnotationResourceChangedEventArgs.cs
- PreloadedPackages.cs
- Codec.cs
- DbProviderManifest.cs
- ModifierKeysConverter.cs
- RangeValidator.cs
- CharKeyFrameCollection.cs
- CircleHotSpot.cs
- Compiler.cs
- KoreanLunisolarCalendar.cs
- MonitorWrapper.cs
- NamespaceQuery.cs
- ParamArrayAttribute.cs
- XmlValidatingReader.cs
- ThumbAutomationPeer.cs
- ElementAtQueryOperator.cs
- InvokeSchedule.cs
- EntityCollectionChangedParams.cs
- RelationshipConverter.cs
- FormViewRow.cs
- Delay.cs
- PolicyVersion.cs
- ListViewUpdatedEventArgs.cs
- EmptyControlCollection.cs
- Color.cs
- SmtpNtlmAuthenticationModule.cs
- QuaternionValueSerializer.cs
- HtmlInputSubmit.cs
- GiveFeedbackEvent.cs
- _NestedMultipleAsyncResult.cs
- EventProviderTraceListener.cs
- Rfc4050KeyFormatter.cs
- EntityContainer.cs
- ConversionValidationRule.cs
- TemplateContainer.cs
- _IPv6Address.cs
- DbConnectionPoolGroup.cs
- xamlnodes.cs
- LabelEditEvent.cs
- CommandValueSerializer.cs
- dataobject.cs
- ObjectStateManagerMetadata.cs
- ChangeBlockUndoRecord.cs
- ObjectHandle.cs
- MenuBindingsEditorForm.cs
- ClientSettingsSection.cs
- DelegateBodyWriter.cs
- SequenceNumber.cs
- OleDbError.cs
- ArraySubsetEnumerator.cs
- DiscardableAttribute.cs
- MeshGeometry3D.cs
- WebPartMenuStyle.cs
- GetPageNumberCompletedEventArgs.cs
- InternalEnumValidator.cs
- DisableDpiAwarenessAttribute.cs
- ErrorRuntimeConfig.cs
- ResourceAttributes.cs
- HttpApplicationFactory.cs
- DrawingVisualDrawingContext.cs
- ShutDownListener.cs
- GeometryHitTestParameters.cs
- ImmutableObjectAttribute.cs
- DataGridViewDataConnection.cs
- OutputWindow.cs
- SspiHelper.cs
- storepermission.cs
- PagerSettings.cs
- BinHexDecoder.cs
- CapabilitiesSection.cs
- PhotoPrintingIntent.cs