internal TraceListener RefreshRuntimeObject(TraceListener listener) {
_runtimeObject = null;
try {
string className = TypeName;
if (String.IsNullOrEmpty(className)) {
// Look it up in SharedListeners and ask the sharedListener to refresh.
Debug.Assert(_allowReferences, "_allowReferences must be true if type name is null");
if (_attributes != null || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || TraceOutputOptions != TraceOptions.None || !String.IsNullOrEmpty(InitData))
throw new ConfigurationErrorsException(SR.GetString(SR.Reference_listener_cant_have_properties, Name));
if (DiagnosticsConfiguration.SharedListeners == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
ListenerElement sharedListener = DiagnosticsConfiguration.SharedListeners[Name];
if (sharedListener == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
else {
_runtimeObject = sharedListener.RefreshRuntimeObject(listener);
return (TraceListener) _runtimeObject;
}
}
else {
// We're the element with the type and initializeData info. First see if those two are the same as they were.
// If not, create a whole new object, otherwise, just update the other properties.
if (Type.GetType(className) != listener.GetType() || InitData != listener.initializeData) {
// type or initdata changed
return GetRuntimeObject();
}
else {
listener.SetAttributes(Attributes);
listener.TraceOutputOptions = TraceOutputOptions;
if (ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere)
listener.Filter = Filter.RefreshRuntimeObject(listener.Filter);
else
listener.Filter = null;
_runtimeObject = listener;
return listener;
}
}
}
catch (ArgumentException e) {
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, Name), e);
}
}