Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / Diagnostics / TraceUtils.cs / 1305376 / 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; using System.Runtime.Versioning; namespace System.Diagnostics { internal static class TraceUtils { [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] 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 (IsOwnedTL(objectType)) throw new ConfigurationErrorsException(SR.GetString(SR.TL_InitializeData_NotSpecified)); // 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 = SecurityUtils.ConstructorInfoInvoke(ctorInfo, 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 = SecurityUtils.ConstructorInfoInvoke(ctorInfo, 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
- StorageScalarPropertyMapping.cs
- StoreItemCollection.Loader.cs
- SyndicationDeserializer.cs
- ListViewItem.cs
- LinearKeyFrames.cs
- MenuEventArgs.cs
- SequenceQuery.cs
- LongValidatorAttribute.cs
- DataGridViewBindingCompleteEventArgs.cs
- TextDpi.cs
- ResponseStream.cs
- InfoCardArgumentException.cs
- _DomainName.cs
- UIElementParagraph.cs
- XmlEventCache.cs
- GridViewUpdateEventArgs.cs
- TraceUtils.cs
- DataGridViewCellEventArgs.cs
- OdbcInfoMessageEvent.cs
- ToolStripPanelCell.cs
- NullNotAllowedCollection.cs
- ConfigurationManagerHelperFactory.cs
- SoapHeaderException.cs
- MenuItemBindingCollection.cs
- ContainerParagraph.cs
- ParameterModifier.cs
- WindowHideOrCloseTracker.cs
- ImageBrush.cs
- ListViewItem.cs
- EditorBrowsableAttribute.cs
- SQLBytes.cs
- OracleTimeSpan.cs
- BindableTemplateBuilder.cs
- CanonicalFontFamilyReference.cs
- NotFiniteNumberException.cs
- VisualStyleRenderer.cs
- SinglePageViewer.cs
- GrammarBuilder.cs
- TargetException.cs
- TextEditorDragDrop.cs
- ServiceModelConfiguration.cs
- shaperfactoryquerycachekey.cs
- ReaderOutput.cs
- TextRangeProviderWrapper.cs
- MachineKeyConverter.cs
- SkipQueryOptionExpression.cs
- OutputCacheSection.cs
- EntityAdapter.cs
- RSAPKCS1SignatureDeformatter.cs
- GroupBox.cs
- WS2007FederationHttpBindingElement.cs
- SamlEvidence.cs
- DataServiceRequestException.cs
- ViewValidator.cs
- SmiGettersStream.cs
- SynchronizingStream.cs
- XmlText.cs
- SafeReversePInvokeHandle.cs
- Zone.cs
- XPathException.cs
- ToolStripContextMenu.cs
- BitmapEffectGeneralTransform.cs
- ContextMarshalException.cs
- ArcSegment.cs
- OdbcDataReader.cs
- ContextProperty.cs
- PointUtil.cs
- BamlWriter.cs
- CustomLineCap.cs
- ExpressionVisitor.cs
- AttributeUsageAttribute.cs
- CaseInsensitiveComparer.cs
- IndexedString.cs
- XmlIncludeAttribute.cs
- Timer.cs
- InvalidateEvent.cs
- COM2FontConverter.cs
- ToolboxDataAttribute.cs
- XmlCustomFormatter.cs
- SecurityState.cs
- Library.cs
- GradientSpreadMethodValidation.cs
- SqlDataSourceQueryEditor.cs
- ReversePositionQuery.cs
- MenuTracker.cs
- ConstraintCollection.cs
- EventDescriptor.cs
- SHA512.cs
- CngProvider.cs
- SendAgentStatusRequest.cs
- WebPartConnectionsConfigureVerb.cs
- KeyValueConfigurationCollection.cs
- CachedPathData.cs
- Choices.cs
- Attributes.cs
- DropTarget.cs
- SecurityRuntime.cs
- WindowShowOrOpenTracker.cs
- EdmSchemaError.cs
- BidOverLoads.cs