Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DbConnectionStringBuilder.cs
Go to the documentation of this file.
7using System.Text;
9
10namespace System.Data.Common;
11
12[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode", Justification = "The use of GetType preserves ICustomTypeDescriptor members with RequiresUnreferencedCode, but the GetType callsites either occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
15{
17
18 private string _connectionString = string.Empty;
19
21
22 private bool _browsableConnectionString = true;
23
24 private readonly bool _useOdbcRules;
25
26 private static int s_objectTypeCount;
27
29
31
33
46
47 object? IDictionary.this[object keyword]
48 {
49 get
50 {
51 return this[ObjectToString(keyword)];
52 }
53 set
54 {
56 }
57 }
58
59 [Browsable(false)]
60 public virtual object this[string keyword]
61 {
62 get
63 {
64 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.get_Item|API> {0}, keyword='{1}'", ObjectID, keyword);
65 ADP.CheckArgumentNull(keyword, "keyword");
67 {
68 return value;
69 }
71 }
73 set
74 {
75 ADP.CheckArgumentNull(keyword, "keyword");
76 bool flag = false;
77 if (value != null)
78 {
83 }
84 else
85 {
86 flag = Remove(keyword);
87 }
88 _connectionString = null;
89 if (flag)
90 {
92 }
93 }
94 }
95
96 [Browsable(false)]
97 [DesignOnly(true)]
101 {
102 get
103 {
105 }
106 set
107 {
110 }
111 }
112
114 public string ConnectionString
115 {
116 get
117 {
118 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.get_ConnectionString|API> {0}", ObjectID);
119 string text = _connectionString;
120 if (text == null)
121 {
123 foreach (string key in Keys)
124 {
125 if (ShouldSerialize(key) && TryGetValue(key, out object value))
126 {
129 }
130 }
131 text = (_connectionString = stringBuilder.ToString());
132 }
133 return text;
134 }
136 set
137 {
138 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.set_ConnectionString|API> {0}", ObjectID);
141 Clear();
142 try
143 {
145 {
146 if (nameValuePair.Value != null)
147 {
148 this[nameValuePair.Name] = nameValuePair.Value;
149 }
150 else
151 {
152 Remove(nameValuePair.Name);
153 }
154 }
155 _connectionString = null;
156 }
157 catch (ArgumentException)
158 {
161 throw;
162 }
163 }
164 }
165
166 [Browsable(false)]
167 public virtual int Count => CurrentValues.Count;
168
169 [Browsable(false)]
170 public bool IsReadOnly => false;
171
172 [Browsable(false)]
173 public virtual bool IsFixedSize => false;
174
176
177 [Browsable(false)]
178 public virtual ICollection Keys
179 {
180 get
181 {
182 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.Keys|API> {0}", ObjectID);
183 return Dictionary.Keys;
184 }
185 }
186
187 internal int ObjectID => _objectID;
188
190
191 [Browsable(false)]
192 public virtual ICollection Values
193 {
194 get
195 {
196 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.Values|API> {0}", ObjectID);
199 object[] array = new object[collection.Count];
200 for (int i = 0; i < array.Length; i++)
201 {
202 enumerator.MoveNext();
203 array[i] = this[enumerator.Current];
204 }
206 }
207 }
208
210 {
211 }
212
217
218 internal virtual string ConvertValueToString(object value)
219 {
220 if (value != null)
221 {
223 }
224 return null;
225 }
226
227 void IDictionary.Add(object keyword, object value)
228 {
230 }
231
232 public void Add(string keyword, object value)
233 {
234 this[keyword] = value;
235 }
236
241
246
247 public virtual void Clear()
248 {
249 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.Clear|API>");
250 _connectionString = string.Empty;
253 }
254
255 protected internal void ClearPropertyDescriptors()
256 {
258 }
259
261 {
263 }
264
265 public virtual bool ContainsKey(string keyword)
266 {
267 ADP.CheckArgumentNull(keyword, "keyword");
269 }
270
272 {
273 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.ICollection.CopyTo|API> {0}", ObjectID);
275 }
276
278 {
279 ADP.CheckArgumentNull(connectionStringBuilder, "connectionStringBuilder");
280 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.EquivalentTo|API> {0}, connectionStringBuilder={1}", ObjectID, connectionStringBuilder.ObjectID);
281 if (GetType() != connectionStringBuilder.GetType() || CurrentValues.Count != connectionStringBuilder.CurrentValues.Count)
282 {
283 return false;
284 }
285 foreach (KeyValuePair<string, object> currentValue in CurrentValues)
286 {
287 if (!connectionStringBuilder.CurrentValues.TryGetValue(currentValue.Key, out object value) || !currentValue.Value.Equals(value))
288 {
289 return false;
290 }
291 }
292 return true;
293 }
294
296 {
297 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.IEnumerable.GetEnumerator|API> {0}", ObjectID);
298 return Collection.GetEnumerator();
299 }
300
302 {
303 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.IDictionary.GetEnumerator|API> {0}", ObjectID);
304 return Dictionary.GetEnumerator();
305 }
306
307 private string ObjectToString(object keyword)
308 {
309 try
310 {
311 return (string)keyword;
312 }
314 {
315 throw new ArgumentException("not a string", "keyword");
316 }
317 }
318
320 {
322 }
323
324 public virtual bool Remove(string keyword)
325 {
326 DataCommonEventSource.Log.Trace("<comm.DbConnectionStringBuilder.Remove|API> {0}, keyword='{1}'", ObjectID, keyword);
327 ADP.CheckArgumentNull(keyword, "keyword");
329 {
330 _connectionString = null;
332 return true;
333 }
334 return false;
335 }
336
337 public virtual bool ShouldSerialize(string keyword)
338 {
339 ADP.CheckArgumentNull(keyword, "keyword");
341 }
342
343 public override string ToString()
344 {
345 return ConnectionString;
346 }
347
348 public virtual bool TryGetValue(string keyword, [NotNullWhen(true)] out object? value)
349 {
350 ADP.CheckArgumentNull(keyword, "keyword");
352 }
353
355 {
356 Attribute[] array = new Attribute[collection.Count];
357 collection.CopyTo(array, 0);
358 return array;
359 }
360
361 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
362 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
364 {
367 {
368 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbConnectionStringBuilder.GetProperties|INFO> {0}", ObjectID);
369 try
370 {
372 GetProperties(hashtable);
374 hashtable.Values.CopyTo(array, 0);
376 }
377 finally
378 {
379 DataCommonEventSource.Log.ExitScope(scopeId);
380 }
381 }
383 }
384
385 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
386 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
388 {
389 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbConnectionStringBuilder.GetProperties|API> {0}", ObjectID);
390 try
391 {
392 Type type = GetType();
395 {
396 if ("ConnectionString" != property.Name)
397 {
398 string displayName = property.DisplayName;
400 {
404 }
405 }
407 {
408 propertyDescriptors["ConnectionString"] = property;
409 }
410 else
411 {
412 propertyDescriptors.Remove("ConnectionString");
413 }
414 }
415 if (IsFixedSize)
416 {
417 return;
418 }
420 foreach (string key in Keys)
421 {
423 {
424 continue;
425 }
426 object obj = this[key];
427 Type type2;
428 if (obj != null)
429 {
430 type2 = obj.GetType();
431 if (typeof(string) == type2)
432 {
433 bool result2;
434 if (int.TryParse((string)obj, out var _))
435 {
436 type2 = typeof(int);
437 }
438 else if (bool.TryParse((string)obj, out result2))
439 {
440 type2 = typeof(bool);
441 }
442 }
443 }
444 else
445 {
446 type2 = typeof(string);
447 }
448 Attribute[] attributes = null;
449 if (StringComparer.OrdinalIgnoreCase.Equals("Password", key) || StringComparer.OrdinalIgnoreCase.Equals("pwd", key))
450 {
451 attributes = new Attribute[3]
452 {
456 };
457 }
458 else if (attributesFromCollection == null)
459 {
461 {
464 };
465 attributes = attributesFromCollection;
466 }
469 }
470 }
471 finally
472 {
473 DataCommonEventSource.Log.ExitScope(scopeId);
474 }
475 }
476
477 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
478 [RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
480 {
482 if (attributes == null || attributes.Length == 0)
483 {
484 return properties;
485 }
487 int num = 0;
488 foreach (PropertyDescriptor item in properties)
489 {
490 bool flag = true;
491 foreach (Attribute attribute in attributes)
492 {
493 Attribute attribute2 = item.Attributes[attribute.GetType()];
494 if ((attribute2 == null && !attribute.IsDefaultAttribute()) || (attribute2 != null && !attribute2.Match(attribute)))
495 {
496 flag = false;
497 break;
498 }
499 }
500 if (flag)
501 {
502 array[num] = item;
503 num++;
504 }
505 }
507 Array.Copy(array, array2, num);
509 }
510
511 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The component type's class name is preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")]
513 {
514 Type type = GetType();
515 return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
516 }
517
518 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The component type's component name is preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")]
520 {
521 Type type = GetType();
523 }
524
525 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The component type's attributes are preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")]
530
531 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
536
537 [RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
542
543 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
548
549 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
554
555 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
560
561 [RequiresUnreferencedCode("The built-in EventDescriptor implementation uses Reflection which requires unreferenced code.")]
566
567 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The component type's events are preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")]
573
574 [RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
579
581 {
582 return this;
583 }
584}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
virtual ICollection Values
Definition Hashtable.cs:534
void CopyTo(T[] array, int index)
static readonly BrowsableAttribute Yes
static readonly PasswordPropertyTextAttribute Yes
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static EventDescriptorCollection GetEvents([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? object GetEditor(object component, Type editorBaseType)
static ? string GetClassName(object component)
static TypeConverter GetConverter(object component)
static ? EventDescriptor GetDefaultEvent([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? string GetComponentName(object component)
static ? PropertyDescriptor GetDefaultProperty([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static AttributeCollection GetAttributes([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? string ToString(object? value)
Definition Convert.cs:2321
static void CheckArgumentNull([NotNull] object value, string parameterName)
Definition ADP.cs:782
static ArgumentException KeywordNotSupported(string keyword)
Definition ADP.cs:820
static void AppendKeyValuePairBuilder(StringBuilder builder, string keyName, string keyValue, bool useOdbcRules)
static void ValidateKeyValuePair(string keyword, string value)
static void AppendKeyValuePair(StringBuilder builder, string keyword, string? value, bool useOdbcRules)
virtual void GetProperties(Hashtable propertyDescriptors)
static void AppendKeyValuePair(StringBuilder builder, string keyword, string? value)
virtual bool EquivalentTo(DbConnectionStringBuilder connectionStringBuilder)
Attribute[] GetAttributesFromCollection(AttributeCollection collection)
PropertyDescriptorCollection GetProperties(Attribute[] attributes)
virtual bool TryGetValue(string keyword, [NotNullWhen(true)] out object? value)
static readonly DataCommonEventSource Log
static CultureInfo InvariantCulture
static StringComparer OrdinalIgnoreCase
static int Increment(ref int location)
void CopyTo(T[] array, int arrayIndex)
void Add(TKey key, TValue value)
new IEnumerator< T > GetEnumerator()
object? GetEditor(Type editorBaseType)
object? GetPropertyOwner(PropertyDescriptor? pd)
PropertyDescriptorCollection GetProperties()
EventDescriptorCollection GetEvents()