From 7a6c3782fce131a24f11be2f48410ae1ab5a0572 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 18 Feb 2021 13:33:21 +0100 Subject: [PATCH 1/3] Add nullable annotations to System.DirectoryServices --- .../ref/System.DirectoryServices.cs | 351 +++++++++--------- .../ref/System.DirectoryServices.csproj | 1 + .../src/Interop/AdsValueHelper2.cs | 4 +- .../src/Interop/SafeNativeMethods.cs | 4 +- .../src/Interop/UnsafeNativeMethods.cs | 24 +- .../src/System.DirectoryServices.csproj | 1 + .../ActiveDirectory/ADAMInstance.cs | 56 +-- .../ActiveDirectory/ADAMInstanceCollection.cs | 6 +- .../ActiveDirectory/ADSearcher.cs | 6 +- .../ActiveDirectoryInterSiteTransport.cs | 18 +- .../ActiveDirectoryPartition.cs | 6 +- .../ActiveDirectoryReplicationMetaData.cs | 4 +- .../ActiveDirectory/ActiveDirectorySchema.cs | 36 +- .../ActiveDirectorySchemaClass.cs | 130 +++---- .../ActiveDirectorySchemaClassCollection.cs | 24 +- .../ActiveDirectorySchemaProperty.cs | 98 ++--- ...ActiveDirectorySchemaPropertyCollection.cs | 26 +- .../ActiveDirectory/ActiveDirectorySite.cs | 170 ++++----- .../ActiveDirectorySiteCollection.cs | 52 +-- .../ActiveDirectorySiteLink.cs | 50 +-- .../ActiveDirectorySiteLinkBridge.cs | 24 +- .../ActiveDirectorySiteLinkCollection.cs | 50 +-- .../ActiveDirectory/ActiveDirectorySubnet.cs | 28 +- .../ActiveDirectorySubnetCollection.cs | 40 +- .../ActiveDirectory/ActiveDirectorySyntax.cs | 4 +- .../ActiveDirectory/ApplicationPartition.cs | 98 ++--- .../ApplicationPartitionCollection.cs | 6 +- .../ActiveDirectory/AttributeMetaData.cs | 12 +- .../AttributeMetadataCollection.cs | 6 +- .../ActiveDirectory/ConfigSet.cs | 66 ++-- .../ActiveDirectory/DirectoryContext.cs | 34 +- .../ActiveDirectory/DirectoryEntryManager.cs | 40 +- .../ActiveDirectory/DirectoryServer.cs | 64 ++-- .../DirectoryServerCollection.cs | 44 +-- .../ActiveDirectory/Domain.cs | 98 ++--- .../ActiveDirectory/DomainCollection.cs | 10 +- .../ActiveDirectory/DomainController.cs | 60 +-- .../DomainControllerCollection.cs | 6 +- .../ActiveDirectory/Exception.cs | 70 ++-- .../ActiveDirectory/Forest.cs | 54 +-- .../ActiveDirectory/ForestTrustCollision.cs | 2 +- .../ForestTrustDomainInfoCollection.cs | 2 +- .../ForestTrustDomainInformation.cs | 2 +- .../ForestTrustRelationshipInformation.cs | 30 +- .../ActiveDirectory/GlobalCatalog.cs | 20 +- .../GlobalCatalogCollection.cs | 6 +- .../ActiveDirectory/Locator.cs | 14 +- .../ActiveDirectory/NativeMethods.cs | 80 ++-- .../ActiveDirectory/PropertyManager.cs | 8 +- ...nlyActiveDirectorySchemaClassCollection.cs | 6 +- ...ActiveDirectorySchemaPropertyCollection.cs | 6 +- .../ReadOnlyDirectoryServerCollection.cs | 8 +- .../ActiveDirectory/ReadOnlySiteCollection.cs | 16 +- .../ReadOnlySiteLinkBridgeCollection.cs | 14 +- .../ReadOnlySiteLinkCollection.cs | 15 +- .../ReadOnlyStringCollection.cs | 6 +- .../ActiveDirectory/ReplicationConnection.cs | 96 ++--- .../ReplicationConnectionCollection.cs | 14 +- .../ActiveDirectory/ReplicationCursor.cs | 10 +- .../ReplicationCursorCollection.cs | 2 +- .../ActiveDirectory/ReplicationFailure.cs | 8 +- .../ReplicationFailureCollection.cs | 2 +- .../ActiveDirectory/ReplicationNeighbor.cs | 14 +- .../ReplicationNeighborCollection.cs | 2 +- .../ActiveDirectory/ReplicationOperation.cs | 12 +- .../ReplicationOperationCollection.cs | 4 +- .../ReplicationOperationInformation.cs | 8 +- .../ActiveDirectory/RoleOwnerCollection.cs | 12 +- .../ActiveDirectory/TopLevelNameCollection.cs | 2 +- .../ActiveDirectory/TrustHelper.cs | 86 ++--- .../TrustRelationshipInformation.cs | 12 +- .../TrustRelationshipInformationCollection.cs | 6 +- .../ActiveDirectory/UnsafeNativeMethods.cs | 46 +-- .../ActiveDirectory/Utils.cs | 180 ++++----- .../Design/DirectoryEntryConverter.cs | 14 +- .../DirectoryServices/DirectoryEntries.cs | 8 +- .../DirectoryServices/DirectoryEntry.cs | 79 ++-- .../DirectoryServices/DirectorySearcher.cs | 66 ++-- .../DirectoryServicesCOMException.cs | 8 +- .../DirectoryServicesPermission.cs | 6 +- .../DirectoryServicesPermissionAttribute.cs | 4 +- .../DirectoryServicesPermissionEntry.cs | 4 +- ...ectoryServicesPermissionEntryCollection.cs | 10 +- .../DirectorySynchronization.cs | 8 +- .../DirectoryVirtualListView.cs | 10 +- .../DirectoryVirtualListViewContext.cs | 2 +- .../DirectoryServices/PropertyCollection.cs | 16 +- .../PropertyValueCollection.cs | 42 +-- .../ResultPropertyCollection.cs | 2 +- .../ResultPropertyValueCollection.cs | 12 +- .../DirectoryServices/SchemaNameCollection.cs | 78 ++-- .../System/DirectoryServices/SearchResult.cs | 6 +- .../SearchResultCollection.cs | 30 +- .../System/DirectoryServices/SortOption.cs | 6 +- 94 files changed, 1539 insertions(+), 1504 deletions(-) diff --git a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs index 20820945c2e04..dee8ad0a83a19 100644 --- a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs +++ b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs @@ -137,7 +137,7 @@ internal DirectoryEntries() { } public System.DirectoryServices.SchemaNameCollection SchemaFilter { get { throw null; } } public System.DirectoryServices.DirectoryEntry Add(string name, string schemaClassName) { throw null; } public System.DirectoryServices.DirectoryEntry Find(string name) { throw null; } - public System.DirectoryServices.DirectoryEntry Find(string name, string schemaClassName) { throw null; } + public System.DirectoryServices.DirectoryEntry Find(string name, string? schemaClassName) { throw null; } public System.Collections.IEnumerator GetEnumerator() { throw null; } public void Remove(System.DirectoryServices.DirectoryEntry entry) { } } @@ -145,9 +145,9 @@ public partial class DirectoryEntry : System.ComponentModel.Component { public DirectoryEntry() { } public DirectoryEntry(object adsObject) { } - public DirectoryEntry(string path) { } - public DirectoryEntry(string path, string username, string password) { } - public DirectoryEntry(string path, string username, string password, System.DirectoryServices.AuthenticationTypes authenticationType) { } + public DirectoryEntry(string? path) { } + public DirectoryEntry(string? path, string? username, string? password) { } + public DirectoryEntry(string? path, string? username, string? password, System.DirectoryServices.AuthenticationTypes authenticationType) { } [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.AuthenticationTypes.Secure)] public System.DirectoryServices.AuthenticationTypes AuthenticationType { get { throw null; } set { } } public System.DirectoryServices.DirectoryEntries Children { get { throw null; } } @@ -156,11 +156,12 @@ public DirectoryEntry(string path, string username, string password, System.Dire public string NativeGuid { get { throw null; } } public object NativeObject { get { throw null; } } public System.DirectoryServices.ActiveDirectorySecurity ObjectSecurity { get { throw null; } set { } } - public System.DirectoryServices.DirectoryEntryConfiguration Options { get { throw null; } } + public System.DirectoryServices.DirectoryEntryConfiguration? Options { get { throw null; } } public System.DirectoryServices.DirectoryEntry Parent { get { throw null; } } [System.ComponentModel.DefaultValueAttribute(null)] - public string Password { set { } } + public string? Password { set { } } [System.ComponentModel.DefaultValueAttribute("")] + [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string Path { get { throw null; } set { } } public System.DirectoryServices.PropertyCollection Properties { get { throw null; } } public string SchemaClassName { get { throw null; } } @@ -168,22 +169,22 @@ public string Password { set { } } [System.ComponentModel.DefaultValueAttribute(true)] public bool UsePropertyCache { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public string Username { get { throw null; } set { } } + public string? Username { get { throw null; } set { } } public void Close() { } public void CommitChanges() { } public System.DirectoryServices.DirectoryEntry CopyTo(System.DirectoryServices.DirectoryEntry newParent) { throw null; } - public System.DirectoryServices.DirectoryEntry CopyTo(System.DirectoryServices.DirectoryEntry newParent, string newName) { throw null; } + public System.DirectoryServices.DirectoryEntry CopyTo(System.DirectoryServices.DirectoryEntry newParent, string? newName) { throw null; } public void DeleteTree() { } protected override void Dispose(bool disposing) { } public static bool Exists(string path) { throw null; } - public object Invoke(string methodName, params object[] args) { throw null; } - public object InvokeGet(string propertyName) { throw null; } - public void InvokeSet(string propertyName, params object[] args) { } + public object? Invoke(string methodName, params object?[] args) { throw null; } + public object? InvokeGet(string propertyName) { throw null; } + public void InvokeSet(string propertyName, params object?[] args) { } public void MoveTo(System.DirectoryServices.DirectoryEntry newParent) { } - public void MoveTo(System.DirectoryServices.DirectoryEntry newParent, string newName) { } + public void MoveTo(System.DirectoryServices.DirectoryEntry newParent, string? newName) { } public void RefreshCache() { } public void RefreshCache(string[] propertyNames) { } - public void Rename(string newName) { } + public void Rename(string? newName) { } } public partial class DirectoryEntryConfiguration { @@ -200,16 +201,17 @@ public void SetUserNameQueryQuota(string accountName) { } public partial class DirectorySearcher : System.ComponentModel.Component { public DirectorySearcher() { } - public DirectorySearcher(System.DirectoryServices.DirectoryEntry searchRoot) { } - public DirectorySearcher(System.DirectoryServices.DirectoryEntry searchRoot, string filter) { } - public DirectorySearcher(System.DirectoryServices.DirectoryEntry searchRoot, string filter, string[] propertiesToLoad) { } - public DirectorySearcher(System.DirectoryServices.DirectoryEntry searchRoot, string filter, string[] propertiesToLoad, System.DirectoryServices.SearchScope scope) { } - public DirectorySearcher(string filter) { } - public DirectorySearcher(string filter, string[] propertiesToLoad) { } - public DirectorySearcher(string filter, string[] propertiesToLoad, System.DirectoryServices.SearchScope scope) { } + public DirectorySearcher(System.DirectoryServices.DirectoryEntry? searchRoot) { } + public DirectorySearcher(System.DirectoryServices.DirectoryEntry? searchRoot, string? filter) { } + public DirectorySearcher(System.DirectoryServices.DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad) { } + public DirectorySearcher(System.DirectoryServices.DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad, System.DirectoryServices.SearchScope scope) { } + public DirectorySearcher(string? filter) { } + public DirectorySearcher(string? filter, string[]? propertiesToLoad) { } + public DirectorySearcher(string? filter, string[]? propertiesToLoad, System.DirectoryServices.SearchScope scope) { } [System.ComponentModel.DefaultValueAttribute(false)] public bool Asynchronous { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute("")] + [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string AttributeScopeQuery { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(true)] public bool CacheResults { get { throw null; } set { } } @@ -217,11 +219,11 @@ public DirectorySearcher(string filter, string[] propertiesToLoad, System.Direct [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.DereferenceAlias.Never)] public System.DirectoryServices.DereferenceAlias DerefAlias { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public System.DirectoryServices.DirectorySynchronization DirectorySynchronization { get { throw null; } set { } } + public System.DirectoryServices.DirectorySynchronization? DirectorySynchronization { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.ExtendedDN.None)] public System.DirectoryServices.ExtendedDN ExtendedDN { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute("(objectClass=*)")] - public string Filter { get { throw null; } set { } } + public string? Filter { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(0)] public int PageSize { get { throw null; } set { } } [System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] @@ -231,7 +233,7 @@ public DirectorySearcher(string filter, string[] propertiesToLoad, System.Direct [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.ReferralChasingOption.External)] public System.DirectoryServices.ReferralChasingOption ReferralChasing { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public System.DirectoryServices.DirectoryEntry SearchRoot { get { throw null; } set { } } + public System.DirectoryServices.DirectoryEntry? SearchRoot { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.SearchScope.Subtree)] public System.DirectoryServices.SearchScope SearchScope { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.SecurityMasks.None)] @@ -245,29 +247,29 @@ public DirectorySearcher(string filter, string[] propertiesToLoad, System.Direct [System.ComponentModel.DefaultValueAttribute(false)] public bool Tombstone { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public System.DirectoryServices.DirectoryVirtualListView VirtualListView { get { throw null; } set { } } + public System.DirectoryServices.DirectoryVirtualListView? VirtualListView { get { throw null; } set { } } protected override void Dispose(bool disposing) { } public System.DirectoryServices.SearchResultCollection FindAll() { throw null; } - public System.DirectoryServices.SearchResult FindOne() { throw null; } + public System.DirectoryServices.SearchResult? FindOne() { throw null; } } public partial class DirectoryServicesCOMException : System.Runtime.InteropServices.COMException, System.Runtime.Serialization.ISerializable { public DirectoryServicesCOMException() { } protected DirectoryServicesCOMException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public DirectoryServicesCOMException(string message) { } - public DirectoryServicesCOMException(string message, System.Exception inner) { } + public DirectoryServicesCOMException(string? message) { } + public DirectoryServicesCOMException(string? message, System.Exception? inner) { } public int ExtendedError { get { throw null; } } - public string ExtendedErrorMessage { get { throw null; } } + public string? ExtendedErrorMessage { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } [System.ObsoleteAttribute("Code Access Security is not supported or honored by the runtime.", DiagnosticId = "SYSLIB0003", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public sealed partial class DirectoryServicesPermission : System.Security.Permissions.ResourcePermissionBase { public DirectoryServicesPermission() { } - public DirectoryServicesPermission(System.DirectoryServices.DirectoryServicesPermissionAccess permissionAccess, string path) { } - public DirectoryServicesPermission(System.DirectoryServices.DirectoryServicesPermissionEntry[] permissionAccessEntries) { } + public DirectoryServicesPermission(System.DirectoryServices.DirectoryServicesPermissionAccess permissionAccess, string? path) { } + public DirectoryServicesPermission(System.DirectoryServices.DirectoryServicesPermissionEntry[]? permissionAccessEntries) { } public DirectoryServicesPermission(System.Security.Permissions.PermissionState state) { } - public System.DirectoryServices.DirectoryServicesPermissionEntryCollection PermissionEntries { get { throw null; } } + public System.DirectoryServices.DirectoryServicesPermissionEntryCollection? PermissionEntries { get { throw null; } } } [System.FlagsAttribute] public enum DirectoryServicesPermissionAccess @@ -280,21 +282,21 @@ public enum DirectoryServicesPermissionAccess [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)] public partial class DirectoryServicesPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute { - public DirectoryServicesPermissionAttribute(System.Security.Permissions.SecurityAction action) : base (default(System.Security.Permissions.SecurityAction)) { } - public string Path { get { throw null; } set { } } + public DirectoryServicesPermissionAttribute(System.Security.Permissions.SecurityAction action) : base(default(System.Security.Permissions.SecurityAction)) { } + public string? Path { get { throw null; } set { } } public System.DirectoryServices.DirectoryServicesPermissionAccess PermissionAccess { get { throw null; } set { } } - public override System.Security.IPermission CreatePermission() { throw null; } + public override System.Security.IPermission? CreatePermission() { throw null; } } public partial class DirectoryServicesPermissionEntry { - public DirectoryServicesPermissionEntry(System.DirectoryServices.DirectoryServicesPermissionAccess permissionAccess, string path) { } - public string Path { get { throw null; } } + public DirectoryServicesPermissionEntry(System.DirectoryServices.DirectoryServicesPermissionAccess permissionAccess, string? path) { } + public string? Path { get { throw null; } } public System.DirectoryServices.DirectoryServicesPermissionAccess PermissionAccess { get { throw null; } } } public partial class DirectoryServicesPermissionEntryCollection : System.Collections.CollectionBase { internal DirectoryServicesPermissionEntryCollection() { } - public System.DirectoryServices.DirectoryServicesPermissionEntry this[int index] { get { throw null; } set { } } + public System.DirectoryServices.DirectoryServicesPermissionEntry? this[int index] { get { throw null; } set { } } public int Add(System.DirectoryServices.DirectoryServicesPermissionEntry value) { throw null; } public void AddRange(System.DirectoryServices.DirectoryServicesPermissionEntryCollection value) { } public void AddRange(System.DirectoryServices.DirectoryServicesPermissionEntry[] value) { } @@ -303,24 +305,24 @@ public void CopyTo(System.DirectoryServices.DirectoryServicesPermissionEntry[] a public int IndexOf(System.DirectoryServices.DirectoryServicesPermissionEntry value) { throw null; } public void Insert(int index, System.DirectoryServices.DirectoryServicesPermissionEntry value) { } protected override void OnClear() { } - protected override void OnInsert(int index, object value) { } - protected override void OnRemove(int index, object value) { } - protected override void OnSet(int index, object oldValue, object newValue) { } - public void Remove(System.DirectoryServices.DirectoryServicesPermissionEntry value) { } + protected override void OnInsert(int index, object? value) { } + protected override void OnRemove(int index, object? value) { } + protected override void OnSet(int index, object? oldValue, object? newValue) { } + public void Remove(System.DirectoryServices.DirectoryServicesPermissionEntry? value) { } } public partial class DirectorySynchronization { public DirectorySynchronization() { } - public DirectorySynchronization(byte[] cookie) { } - public DirectorySynchronization(System.DirectoryServices.DirectorySynchronization sync) { } + public DirectorySynchronization(byte[]? cookie) { } + public DirectorySynchronization(System.DirectoryServices.DirectorySynchronization? sync) { } public DirectorySynchronization(System.DirectoryServices.DirectorySynchronizationOptions option) { } - public DirectorySynchronization(System.DirectoryServices.DirectorySynchronizationOptions option, byte[] cookie) { } + public DirectorySynchronization(System.DirectoryServices.DirectorySynchronizationOptions option, byte[]? cookie) { } [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.DirectorySynchronizationOptions.None)] public System.DirectoryServices.DirectorySynchronizationOptions Option { get { throw null; } set { } } public System.DirectoryServices.DirectorySynchronization Copy() { throw null; } public byte[] GetDirectorySynchronizationCookie() { throw null; } public void ResetDirectorySynchronizationCookie() { } - public void ResetDirectorySynchronizationCookie(byte[] cookie) { } + public void ResetDirectorySynchronizationCookie(byte[]? cookie) { } } [System.FlagsAttribute] public enum DirectorySynchronizationOptions : long @@ -336,9 +338,9 @@ public partial class DirectoryVirtualListView public DirectoryVirtualListView() { } public DirectoryVirtualListView(int afterCount) { } public DirectoryVirtualListView(int beforeCount, int afterCount, int offset) { } - public DirectoryVirtualListView(int beforeCount, int afterCount, int offset, System.DirectoryServices.DirectoryVirtualListViewContext context) { } - public DirectoryVirtualListView(int beforeCount, int afterCount, string target) { } - public DirectoryVirtualListView(int beforeCount, int afterCount, string target, System.DirectoryServices.DirectoryVirtualListViewContext context) { } + public DirectoryVirtualListView(int beforeCount, int afterCount, int offset, System.DirectoryServices.DirectoryVirtualListViewContext? context) { } + public DirectoryVirtualListView(int beforeCount, int afterCount, string? target) { } + public DirectoryVirtualListView(int beforeCount, int afterCount, string? target, System.DirectoryServices.DirectoryVirtualListViewContext? context) { } [System.ComponentModel.DefaultValueAttribute(0)] public int AfterCount { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(0)] @@ -346,10 +348,11 @@ public DirectoryVirtualListView(int beforeCount, int afterCount, string target, [System.ComponentModel.DefaultValueAttribute(0)] public int BeforeCount { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public System.DirectoryServices.DirectoryVirtualListViewContext DirectoryVirtualListViewContext { get { throw null; } set { } } + public System.DirectoryServices.DirectoryVirtualListViewContext? DirectoryVirtualListViewContext { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(0)] public int Offset { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute("")] + [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string Target { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(0)] public int TargetPercentage { get { throw null; } set { } } @@ -409,7 +412,7 @@ internal PropertyCollection() { } object System.Collections.ICollection.SyncRoot { get { throw null; } } bool System.Collections.IDictionary.IsFixedSize { get { throw null; } } bool System.Collections.IDictionary.IsReadOnly { get { throw null; } } - object System.Collections.IDictionary.this[object key] { get { throw null; } set { } } + object? System.Collections.IDictionary.this[object key] { get { throw null; } set { } } System.Collections.ICollection System.Collections.IDictionary.Keys { get { throw null; } } public System.Collections.ICollection Values { get { throw null; } } public bool Contains(string propertyName) { throw null; } @@ -431,21 +434,21 @@ public sealed partial class PropertySetAccessRule : System.DirectoryServices.Act public partial class PropertyValueCollection : System.Collections.CollectionBase { internal PropertyValueCollection() { } - public object this[int index] { get { throw null; } set { } } + public object? this[int index] { get { throw null; } set { } } public string PropertyName { get { throw null; } } - public object Value { get { throw null; } set { } } - public int Add(object value) { throw null; } + public object? Value { get { throw null; } set { } } + public int Add(object? value) { throw null; } public void AddRange(System.DirectoryServices.PropertyValueCollection value) { } - public void AddRange(object[] value) { } - public bool Contains(object value) { throw null; } - public void CopyTo(object[] array, int index) { } - public int IndexOf(object value) { throw null; } - public void Insert(int index, object value) { } + public void AddRange(object?[] value) { } + public bool Contains(object? value) { throw null; } + public void CopyTo(object?[] array, int index) { } + public int IndexOf(object? value) { throw null; } + public void Insert(int index, object? value) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } - public void Remove(object value) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + public void Remove(object? value) { } } public enum ReferralChasingOption { @@ -466,38 +469,38 @@ public void CopyTo(System.DirectoryServices.ResultPropertyValueCollection[] arra public partial class ResultPropertyValueCollection : System.Collections.ReadOnlyCollectionBase { internal ResultPropertyValueCollection() { } - public object this[int index] { get { throw null; } } - public bool Contains(object value) { throw null; } - public void CopyTo(object[] values, int index) { } - public int IndexOf(object value) { throw null; } + public object? this[int index] { get { throw null; } } + public bool Contains(object? value) { throw null; } + public void CopyTo(object?[] values, int index) { } + public int IndexOf(object? value) { throw null; } } public partial class SchemaNameCollection : System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList { internal SchemaNameCollection() { } public int Count { get { throw null; } } - public string this[int index] { get { throw null; } set { } } + public string? this[int index] { get { throw null; } set { } } bool System.Collections.ICollection.IsSynchronized { get { throw null; } } object System.Collections.ICollection.SyncRoot { get { throw null; } } bool System.Collections.IList.IsFixedSize { get { throw null; } } bool System.Collections.IList.IsReadOnly { get { throw null; } } - object System.Collections.IList.this[int index] { get { throw null; } set { } } - public int Add(string value) { throw null; } + object? System.Collections.IList.this[int index] { get { throw null; } set { } } + public int Add(string? value) { throw null; } public void AddRange(System.DirectoryServices.SchemaNameCollection value) { } - public void AddRange(string[] value) { } + public void AddRange(string?[] value) { } public void Clear() { } - public bool Contains(string value) { throw null; } - public void CopyTo(string[] stringArray, int index) { } + public bool Contains(string? value) { throw null; } + public void CopyTo(string?[] stringArray, int index) { } public System.Collections.IEnumerator GetEnumerator() { throw null; } - public int IndexOf(string value) { throw null; } - public void Insert(int index, string value) { } - public void Remove(string value) { } + public int IndexOf(string? value) { throw null; } + public void Insert(int index, string? value) { } + public void Remove(string? value) { } public void RemoveAt(int index) { } - void System.Collections.ICollection.CopyTo(System.Array array, int index) { } - int System.Collections.IList.Add(object value) { throw null; } - bool System.Collections.IList.Contains(object value) { throw null; } - int System.Collections.IList.IndexOf(object value) { throw null; } - void System.Collections.IList.Insert(int index, object value) { } - void System.Collections.IList.Remove(object value) { } + void System.Collections.ICollection.CopyTo(System.Array? array, int index) { } + int System.Collections.IList.Add(object? value) { throw null; } + bool System.Collections.IList.Contains(object? value) { throw null; } + int System.Collections.IList.IndexOf(object? value) { throw null; } + void System.Collections.IList.Insert(int index, object? value) { } + void System.Collections.IList.Remove(object? value) { } } public partial class SearchResult { @@ -552,7 +555,8 @@ public SortOption(string propertyName, System.DirectoryServices.SortDirection di [System.ComponentModel.DefaultValueAttribute(System.DirectoryServices.SortDirection.Ascending)] public System.DirectoryServices.SortDirection Direction { get { throw null; } set { } } [System.ComponentModel.DefaultValueAttribute(null)] - public string PropertyName { get { throw null; } set { } } + [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] + public string? PropertyName { get { throw null; } set { } } } } namespace System.DirectoryServices.ActiveDirectory @@ -576,28 +580,28 @@ public partial class ActiveDirectoryObjectExistsException : System.Exception { public ActiveDirectoryObjectExistsException() { } protected ActiveDirectoryObjectExistsException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public ActiveDirectoryObjectExistsException(string message) { } - public ActiveDirectoryObjectExistsException(string message, System.Exception inner) { } + public ActiveDirectoryObjectExistsException(string? message) { } + public ActiveDirectoryObjectExistsException(string? message, System.Exception? inner) { } } public partial class ActiveDirectoryObjectNotFoundException : System.Exception, System.Runtime.Serialization.ISerializable { public ActiveDirectoryObjectNotFoundException() { } protected ActiveDirectoryObjectNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public ActiveDirectoryObjectNotFoundException(string message) { } - public ActiveDirectoryObjectNotFoundException(string message, System.Exception inner) { } - public ActiveDirectoryObjectNotFoundException(string message, System.Type type, string name) { } - public string Name { get { throw null; } } - public System.Type Type { get { throw null; } } + public ActiveDirectoryObjectNotFoundException(string? message) { } + public ActiveDirectoryObjectNotFoundException(string? message, System.Exception? inner) { } + public ActiveDirectoryObjectNotFoundException(string? message, System.Type? type, string? name) { } + public string? Name { get { throw null; } } + public System.Type? Type { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } public partial class ActiveDirectoryOperationException : System.Exception, System.Runtime.Serialization.ISerializable { public ActiveDirectoryOperationException() { } protected ActiveDirectoryOperationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public ActiveDirectoryOperationException(string message) { } - public ActiveDirectoryOperationException(string message, System.Exception inner) { } - public ActiveDirectoryOperationException(string message, System.Exception inner, int errorCode) { } - public ActiveDirectoryOperationException(string message, int errorCode) { } + public ActiveDirectoryOperationException(string? message) { } + public ActiveDirectoryOperationException(string? message, System.Exception? inner) { } + public ActiveDirectoryOperationException(string? message, System.Exception? inner, int errorCode) { } + public ActiveDirectoryOperationException(string? message, int errorCode) { } public int ErrorCode { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } @@ -614,7 +618,7 @@ public partial class ActiveDirectoryReplicationMetadata : System.Collections.Dic { internal ActiveDirectoryReplicationMetadata() { } public System.DirectoryServices.ActiveDirectory.ReadOnlyStringCollection AttributeNames { get { throw null; } } - public System.DirectoryServices.ActiveDirectory.AttributeMetadata this[string name] { get { throw null; } } + public System.DirectoryServices.ActiveDirectory.AttributeMetadata? this[string name] { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AttributeMetadataCollection Values { get { throw null; } } public bool Contains(string attributeName) { throw null; } public void CopyTo(System.DirectoryServices.ActiveDirectory.AttributeMetadata[] array, int index) { } @@ -669,18 +673,18 @@ public partial class ActiveDirectorySchemaClass : System.IDisposable { public ActiveDirectorySchemaClass(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string ldapDisplayName) { } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClassCollection AuxiliaryClasses { get { throw null; } } - public string CommonName { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectorySecurity DefaultObjectSecurityDescriptor { get { throw null; } set { } } - public string Description { get { throw null; } set { } } + public string? CommonName { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectorySecurity? DefaultObjectSecurityDescriptor { get { throw null; } set { } } + public string? Description { get { throw null; } set { } } public bool IsDefunct { get { throw null; } set { } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaPropertyCollection MandatoryProperties { get { throw null; } } public string Name { get { throw null; } } - public string Oid { get { throw null; } set { } } + public string? Oid { get { throw null; } set { } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaPropertyCollection OptionalProperties { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ReadOnlyActiveDirectorySchemaClassCollection PossibleInferiors { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClassCollection PossibleSuperiors { get { throw null; } } public System.Guid SchemaGuid { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass SubClassOf { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass? SubClassOf { get { throw null; } set { } } public System.DirectoryServices.ActiveDirectory.SchemaClassType Type { get { throw null; } set { } } public void Dispose() { } protected virtual void Dispose(bool disposing) { } @@ -703,17 +707,17 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchem public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { } } public partial class ActiveDirectorySchemaProperty : System.IDisposable { public ActiveDirectorySchemaProperty(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string ldapDisplayName) { } - public string CommonName { get { throw null; } set { } } - public string Description { get { throw null; } set { } } + public string? CommonName { get { throw null; } set { } } + public string? Description { get { throw null; } set { } } public bool IsDefunct { get { throw null; } set { } } public bool IsInAnr { get { throw null; } set { } } public bool IsIndexed { get { throw null; } set { } } @@ -722,10 +726,10 @@ public ActiveDirectorySchemaProperty(System.DirectoryServices.ActiveDirectory.Di public bool IsOnTombstonedObject { get { throw null; } set { } } public bool IsSingleValued { get { throw null; } set { } } public bool IsTupleIndexed { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty Link { get { throw null; } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty? Link { get { throw null; } } public int? LinkId { get { throw null; } set { } } public string Name { get { throw null; } } - public string Oid { get { throw null; } set { } } + public string? Oid { get { throw null; } set { } } public int? RangeLower { get { throw null; } set { } } public int? RangeUpper { get { throw null; } set { } } public System.Guid SchemaGuid { get { throw null; } set { } } @@ -750,9 +754,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchem public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { } } @@ -760,13 +764,13 @@ public partial class ActiveDirectoryServerDownException : System.Exception, Syst { public ActiveDirectoryServerDownException() { } protected ActiveDirectoryServerDownException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public ActiveDirectoryServerDownException(string message) { } - public ActiveDirectoryServerDownException(string message, System.Exception inner) { } - public ActiveDirectoryServerDownException(string message, System.Exception inner, int errorCode, string name) { } - public ActiveDirectoryServerDownException(string message, int errorCode, string name) { } + public ActiveDirectoryServerDownException(string? message) { } + public ActiveDirectoryServerDownException(string? message, System.Exception? inner) { } + public ActiveDirectoryServerDownException(string? message, System.Exception? inner, int errorCode, string? name) { } + public ActiveDirectoryServerDownException(string? message, int errorCode, string? name) { } public int ErrorCode { get { throw null; } } public override string Message { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } public partial class ActiveDirectorySite : System.IDisposable @@ -775,9 +779,10 @@ public ActiveDirectorySite(System.DirectoryServices.ActiveDirectory.DirectoryCon public System.DirectoryServices.ActiveDirectory.ReadOnlySiteCollection AdjacentSites { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ReadOnlyDirectoryServerCollection BridgeheadServers { get { throw null; } } public System.DirectoryServices.ActiveDirectory.DomainCollection Domains { get { throw null; } } - public System.DirectoryServices.ActiveDirectory.DirectoryServer InterSiteTopologyGenerator { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule IntraSiteReplicationSchedule { get { throw null; } set { } } - public string Location { get { throw null; } set { } } + [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] + public System.DirectoryServices.ActiveDirectory.DirectoryServer? InterSiteTopologyGenerator { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? IntraSiteReplicationSchedule { get { throw null; } set { } } + public string? Location { get { throw null; } set { } } public string Name { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteOptions Options { get { throw null; } set { } } public System.DirectoryServices.ActiveDirectory.DirectoryServerCollection PreferredRpcBridgeheadServers { get { throw null; } } @@ -806,9 +811,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite[ public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { } } @@ -816,10 +821,10 @@ public partial class ActiveDirectorySiteLink : System.IDisposable { public ActiveDirectorySiteLink(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string siteLinkName) { } public ActiveDirectorySiteLink(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string siteLinkName, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport) { } - public ActiveDirectorySiteLink(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string siteLinkName, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule schedule) { } + public ActiveDirectorySiteLink(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string siteLinkName, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? schedule) { } public int Cost { get { throw null; } set { } } public bool DataCompressionEnabled { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule InterSiteReplicationSchedule { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? InterSiteReplicationSchedule { get { throw null; } set { } } public string Name { get { throw null; } } public bool NotificationEnabled { get { throw null; } set { } } public bool ReciprocalReplicationEnabled { get { throw null; } set { } } @@ -863,9 +868,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteL public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { } } @@ -889,9 +894,9 @@ public partial class ActiveDirectorySubnet : System.IDisposable { public ActiveDirectorySubnet(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string subnetName) { } public ActiveDirectorySubnet(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string subnetName, string siteName) { } - public string Location { get { throw null; } set { } } + public string? Location { get { throw null; } set { } } public string Name { get { throw null; } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySite Site { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySite? Site { get { throw null; } set { } } public void Delete() { } public void Dispose() { } protected virtual void Dispose(bool disposing) { } @@ -913,9 +918,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySubne public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet subnet) { } protected override void OnClear() { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet subnet) { } } @@ -954,16 +959,16 @@ public partial class AdamInstance : System.DirectoryServices.ActiveDirectory.Dir { internal AdamInstance() { } public System.DirectoryServices.ActiveDirectory.ConfigurationSet ConfigurationSet { get { throw null; } } - public string DefaultPartition { get { throw null; } set { } } + public string? DefaultPartition { get { throw null; } set { } } public string HostName { get { throw null; } } public override System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection InboundConnections { get { throw null; } } - public override string IPAddress { get { throw null; } } + public override string? IPAddress { get { throw null; } } public int LdapPort { get { throw null; } } public override System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection OutboundConnections { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AdamRoleCollection Roles { get { throw null; } } public override string SiteName { get { throw null; } } public int SslPort { get { throw null; } } - public override System.DirectoryServices.ActiveDirectory.SyncUpdateCallback SyncFromAllServersCallback { get { throw null; } set { } } + public override System.DirectoryServices.ActiveDirectory.SyncUpdateCallback? SyncFromAllServersCallback { get { throw null; } set { } } public override void CheckReplicationConsistency() { } protected override void Dispose(bool disposing) { } ~AdamInstance() { } @@ -1009,7 +1014,7 @@ public partial class ApplicationPartition : System.DirectoryServices.ActiveDirec public ApplicationPartition(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string distinguishedName) { } public ApplicationPartition(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string distinguishedName, string objectClass) { } public System.DirectoryServices.ActiveDirectory.DirectoryServerCollection DirectoryServers { get { throw null; } } - public string SecurityReferenceDomain { get { throw null; } set { } } + public string? SecurityReferenceDomain { get { throw null; } set { } } public void Delete() { } protected override void Dispose(bool disposing) { } public System.DirectoryServices.ActiveDirectory.ReadOnlyDirectoryServerCollection FindAllDirectoryServers() { throw null; } @@ -1041,7 +1046,7 @@ internal AttributeMetadata() { } public long LocalChangeUsn { get { throw null; } } public string Name { get { throw null; } } public long OriginatingChangeUsn { get { throw null; } } - public string OriginatingServer { get { throw null; } } + public string? OriginatingServer { get { throw null; } } public int Version { get { throw null; } } } public partial class AttributeMetadataCollection : System.Collections.ReadOnlyCollectionBase @@ -1057,7 +1062,7 @@ public partial class ConfigurationSet internal ConfigurationSet() { } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection AdamInstances { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ApplicationPartitionCollection ApplicationPartitions { get { throw null; } } - public string Name { get { throw null; } } + public string? Name { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AdamInstance NamingRoleOwner { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchema Schema { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AdamInstance SchemaRoleOwner { get { throw null; } } @@ -1066,15 +1071,15 @@ public void Dispose() { } protected virtual void Dispose(bool disposing) { } public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance() { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance(string partitionName) { throw null; } - public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance(string partitionName, string siteName) { throw null; } + public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance(string? partitionName, string siteName) { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances() { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string partitionName) { throw null; } - public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string partitionName, string siteName) { throw null; } + public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string? partitionName, string? siteName) { throw null; } public static System.DirectoryServices.ActiveDirectory.ConfigurationSet GetConfigurationSet(System.DirectoryServices.ActiveDirectory.DirectoryContext context) { throw null; } public System.DirectoryServices.DirectoryEntry GetDirectoryEntry() { throw null; } public System.DirectoryServices.ActiveDirectory.ReplicationSecurityLevel GetSecurityLevel() { throw null; } public void SetSecurityLevel(System.DirectoryServices.ActiveDirectory.ReplicationSecurityLevel securityLevel) { } - public override string ToString() { throw null; } + public override string? ToString() { throw null; } } public partial class DirectoryContext { @@ -1083,8 +1088,8 @@ public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContex public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string username, string password) { } public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string name, string username, string password) { } public System.DirectoryServices.ActiveDirectory.DirectoryContextType ContextType { get { throw null; } } - public string Name { get { throw null; } } - public string UserName { get { throw null; } } + public string? Name { get { throw null; } } + public string? UserName { get { throw null; } } } public enum DirectoryContextType { @@ -1098,12 +1103,12 @@ public abstract partial class DirectoryServer : System.IDisposable { protected DirectoryServer() { } public abstract System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection InboundConnections { get; } - public abstract string IPAddress { get; } + public abstract string? IPAddress { get; } public string Name { get { throw null; } } public abstract System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection OutboundConnections { get; } public System.DirectoryServices.ActiveDirectory.ReadOnlyStringCollection Partitions { get { throw null; } } public abstract string SiteName { get; } - public abstract System.DirectoryServices.ActiveDirectory.SyncUpdateCallback SyncFromAllServersCallback { get; set; } + public abstract System.DirectoryServices.ActiveDirectory.SyncUpdateCallback? SyncFromAllServersCallback { get; set; } public abstract void CheckReplicationConsistency(); public void Dispose() { } protected virtual void Dispose(bool disposing) { } @@ -1133,9 +1138,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.DirectoryServer[] ar public void Insert(int index, System.DirectoryServices.ActiveDirectory.DirectoryServer server) { } protected override void OnClear() { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object value) { } - protected override void OnRemoveComplete(int index, object value) { } - protected override void OnSetComplete(int index, object oldValue, object newValue) { } + protected override void OnInsertComplete(int index, object? value) { } + protected override void OnRemoveComplete(int index, object? value) { } + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.DirectoryServer server) { } } @@ -1148,7 +1153,7 @@ internal Domain() { } public int DomainModeLevel { get { throw null; } } public System.DirectoryServices.ActiveDirectory.Forest Forest { get { throw null; } } public System.DirectoryServices.ActiveDirectory.DomainController InfrastructureRoleOwner { get { throw null; } } - public System.DirectoryServices.ActiveDirectory.Domain Parent { get { throw null; } } + public System.DirectoryServices.ActiveDirectory.Domain? Parent { get { throw null; } } public System.DirectoryServices.ActiveDirectory.DomainController PdcRoleOwner { get { throw null; } } public System.DirectoryServices.ActiveDirectory.DomainController RidRoleOwner { get { throw null; } } public void CreateLocalSideOfTrustRelationship(string targetDomainName, System.DirectoryServices.ActiveDirectory.TrustDirection direction, string trustPassword) { } @@ -1207,12 +1212,12 @@ protected DomainController() { } public System.DirectoryServices.ActiveDirectory.Forest Forest { get { throw null; } } public long HighestCommittedUsn { get { throw null; } } public override System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection InboundConnections { get { throw null; } } - public override string IPAddress { get { throw null; } } + public override string? IPAddress { get { throw null; } } public string OSVersion { get { throw null; } } public override System.DirectoryServices.ActiveDirectory.ReplicationConnectionCollection OutboundConnections { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectoryRoleCollection Roles { get { throw null; } } public override string SiteName { get { throw null; } } - public override System.DirectoryServices.ActiveDirectory.SyncUpdateCallback SyncFromAllServersCallback { get { throw null; } set { } } + public override System.DirectoryServices.ActiveDirectory.SyncUpdateCallback? SyncFromAllServersCallback { get { throw null; } set { } } public override void CheckReplicationConsistency() { } protected override void Dispose(bool disposing) { } public virtual System.DirectoryServices.ActiveDirectory.GlobalCatalog EnableGlobalCatalog() { throw null; } @@ -1319,10 +1324,10 @@ public partial class ForestTrustCollisionException : System.DirectoryServices.Ac { public ForestTrustCollisionException() { } protected ForestTrustCollisionException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public ForestTrustCollisionException(string message) { } - public ForestTrustCollisionException(string message, System.Exception inner) { } - public ForestTrustCollisionException(string message, System.Exception inner, System.DirectoryServices.ActiveDirectory.ForestTrustRelationshipCollisionCollection collisions) { } - public System.DirectoryServices.ActiveDirectory.ForestTrustRelationshipCollisionCollection Collisions { get { throw null; } } + public ForestTrustCollisionException(string? message) { } + public ForestTrustCollisionException(string? message, System.Exception? inner) { } + public ForestTrustCollisionException(string? message, System.Exception? inner, System.DirectoryServices.ActiveDirectory.ForestTrustRelationshipCollisionCollection? collisions) { } + public System.DirectoryServices.ActiveDirectory.ForestTrustRelationshipCollisionCollection? Collisions { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } public enum ForestTrustCollisionType @@ -1517,8 +1522,8 @@ public void CopyTo(string[] values, int index) { } public partial class ReplicationConnection : System.IDisposable { public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer) { } - public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule schedule) { } - public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule schedule, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport) { } + public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? schedule) { } + public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? schedule, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport) { } public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryContext context, string name, System.DirectoryServices.ActiveDirectory.DirectoryServer sourceServer, System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType transport) { } public System.DirectoryServices.ActiveDirectory.NotificationStatus ChangeNotificationStatus { get { throw null; } set { } } public bool DataCompressionEnabled { get { throw null; } set { } } @@ -1527,10 +1532,10 @@ public ReplicationConnection(System.DirectoryServices.ActiveDirectory.DirectoryC public bool GeneratedByKcc { get { throw null; } set { } } public string Name { get { throw null; } } public bool ReciprocalReplicationEnabled { get { throw null; } set { } } - public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule ReplicationSchedule { get { throw null; } set { } } + public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule? ReplicationSchedule { get { throw null; } set { } } public bool ReplicationScheduleOwnedByUser { get { throw null; } set { } } public System.DirectoryServices.ActiveDirectory.ReplicationSpan ReplicationSpan { get { throw null; } } - public string SourceServer { get { throw null; } } + public string? SourceServer { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType TransportType { get { throw null; } } public void Delete() { } public void Dispose() { } @@ -1555,7 +1560,7 @@ internal ReplicationCursor() { } public System.DateTime LastSuccessfulSyncTime { get { throw null; } } public string PartitionName { get { throw null; } } public System.Guid SourceInvocationId { get { throw null; } } - public string SourceServer { get { throw null; } } + public string? SourceServer { get { throw null; } } public long UpToDatenessUsn { get { throw null; } } } public partial class ReplicationCursorCollection : System.Collections.ReadOnlyCollectionBase @@ -1573,7 +1578,7 @@ internal ReplicationFailure() { } public System.DateTime FirstFailureTime { get { throw null; } } public int LastErrorCode { get { throw null; } } public string LastErrorMessage { get { throw null; } } - public string SourceServer { get { throw null; } } + public string? SourceServer { get { throw null; } } } public partial class ReplicationFailureCollection : System.Collections.ReadOnlyCollectionBase { @@ -1591,10 +1596,10 @@ internal ReplicationNeighbor() { } public System.DateTime LastSuccessfulSync { get { throw null; } } public string LastSyncMessage { get { throw null; } } public int LastSyncResult { get { throw null; } } - public string PartitionName { get { throw null; } } + public string? PartitionName { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ReplicationNeighbor.ReplicationNeighborOptions ReplicationNeighborOption { get { throw null; } } public System.Guid SourceInvocationId { get { throw null; } } - public string SourceServer { get { throw null; } } + public string? SourceServer { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectoryTransportType TransportType { get { throw null; } } public long UsnAttributeFilter { get { throw null; } } public long UsnLastObjectChangeSynced { get { throw null; } } @@ -1631,9 +1636,9 @@ public partial class ReplicationOperation internal ReplicationOperation() { } public int OperationNumber { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ReplicationOperationType OperationType { get { throw null; } } - public string PartitionName { get { throw null; } } + public string? PartitionName { get { throw null; } } public int Priority { get { throw null; } } - public string SourceServer { get { throw null; } } + public string? SourceServer { get { throw null; } } public System.DateTime TimeEnqueued { get { throw null; } } } public partial class ReplicationOperationCollection : System.Collections.ReadOnlyCollectionBase @@ -1647,9 +1652,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ReplicationOperation public partial class ReplicationOperationInformation { public ReplicationOperationInformation() { } - public System.DirectoryServices.ActiveDirectory.ReplicationOperation CurrentOperation { get { throw null; } } + public System.DirectoryServices.ActiveDirectory.ReplicationOperation? CurrentOperation { get { throw null; } } public System.DateTime OperationStartTime { get { throw null; } } - public System.DirectoryServices.ActiveDirectory.ReplicationOperationCollection PendingOperations { get { throw null; } } + public System.DirectoryServices.ActiveDirectory.ReplicationOperationCollection? PendingOperations { get { throw null; } } } public enum ReplicationOperationType { @@ -1689,8 +1694,8 @@ internal SyncFromAllServersErrorInformation() { } public System.DirectoryServices.ActiveDirectory.SyncFromAllServersErrorCategory ErrorCategory { get { throw null; } } public int ErrorCode { get { throw null; } } public string ErrorMessage { get { throw null; } } - public string SourceServer { get { throw null; } } - public string TargetServer { get { throw null; } } + public string? SourceServer { get { throw null; } } + public string? TargetServer { get { throw null; } } } public enum SyncFromAllServersEvent { @@ -1703,9 +1708,9 @@ public partial class SyncFromAllServersOperationException : System.DirectoryServ { public SyncFromAllServersOperationException() { } protected SyncFromAllServersOperationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public SyncFromAllServersOperationException(string message) { } - public SyncFromAllServersOperationException(string message, System.Exception inner) { } - public SyncFromAllServersOperationException(string message, System.Exception inner, System.DirectoryServices.ActiveDirectory.SyncFromAllServersErrorInformation[] errors) { } + public SyncFromAllServersOperationException(string? message) { } + public SyncFromAllServersOperationException(string? message, System.Exception? inner) { } + public SyncFromAllServersOperationException(string? message, System.Exception? inner, System.DirectoryServices.ActiveDirectory.SyncFromAllServersErrorInformation[]? errors) { } public System.DirectoryServices.ActiveDirectory.SyncFromAllServersErrorInformation[] ErrorInformation { get { throw null; } } public override void GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } } @@ -1720,7 +1725,7 @@ public enum SyncFromAllServersOptions PushChangeOutward = 32, CrossSite = 64, } - public delegate bool SyncUpdateCallback(System.DirectoryServices.ActiveDirectory.SyncFromAllServersEvent eventType, string targetServer, string sourceServer, System.DirectoryServices.ActiveDirectory.SyncFromAllServersOperationException exception); + public delegate bool SyncUpdateCallback(System.DirectoryServices.ActiveDirectory.SyncFromAllServersEvent eventType, string? targetServer, string? sourceServer, System.DirectoryServices.ActiveDirectory.SyncFromAllServersOperationException? exception); public partial class TopLevelName { internal TopLevelName() { } @@ -1759,8 +1764,8 @@ public enum TrustDirection public partial class TrustRelationshipInformation { internal TrustRelationshipInformation() { } - public string SourceName { get { throw null; } } - public string TargetName { get { throw null; } } + public string? SourceName { get { throw null; } } + public string? TargetName { get { throw null; } } public System.DirectoryServices.ActiveDirectory.TrustDirection TrustDirection { get { throw null; } } public System.DirectoryServices.ActiveDirectory.TrustType TrustType { get { throw null; } } } diff --git a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.csproj b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.csproj index a29cfa079c933..c49656ee62280 100644 --- a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.csproj +++ b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.csproj @@ -2,6 +2,7 @@ netstandard2.0 true + enable diff --git a/src/libraries/System.DirectoryServices/src/Interop/AdsValueHelper2.cs b/src/libraries/System.DirectoryServices/src/Interop/AdsValueHelper2.cs index 63abf247b8392..d834eb54409ef 100644 --- a/src/libraries/System.DirectoryServices/src/Interop/AdsValueHelper2.cs +++ b/src/libraries/System.DirectoryServices/src/Interop/AdsValueHelper2.cs @@ -183,7 +183,7 @@ public object GetValue() case AdsType.ADSTYPE_NUMERIC_STRING: case AdsType.ADSTYPE_OBJECT_CLASS: // The value is a String. - return Marshal.PtrToStringUni(adsvalue.pointer.value); + return Marshal.PtrToStringUni(adsvalue.pointer.value)!; case AdsType.ADSTYPE_BOOLEAN: // The value is a bool. @@ -235,7 +235,7 @@ public object GetVlvValue() var vlv = new AdsVLV(); Marshal.PtrToStructure(adsvalue.octetString.value, vlv); - byte[] bytes = null; + byte[]? bytes = null; if (vlv.contextID != (IntPtr)0 && vlv.contextIDlength != 0) { bytes = new byte[vlv.contextIDlength]; diff --git a/src/libraries/System.DirectoryServices/src/Interop/SafeNativeMethods.cs b/src/libraries/System.DirectoryServices/src/Interop/SafeNativeMethods.cs index 726c3676c7667..461be3d67afaf 100644 --- a/src/libraries/System.DirectoryServices/src/Interop/SafeNativeMethods.cs +++ b/src/libraries/System.DirectoryServices/src/Interop/SafeNativeMethods.cs @@ -29,7 +29,7 @@ public const int public static extern unsafe int ADsGetLastError(out int error, char* errorBuffer, int errorBufferLength, char* nameBuffer, int nameBufferLength); [DllImport(ExternDll.Activeds, CharSet = CharSet.Unicode)] - public static extern int ADsSetLastError(int error, string errorString, string provider); + public static extern int ADsSetLastError(int error, string? errorString, string? provider); public class EnumVariant { @@ -93,7 +93,7 @@ private void Advance() if (numRead[0] > 0) { #pragma warning disable 612, 618 - _currentValue = Marshal.GetObjectForNativeVariant(addr); + _currentValue = Marshal.GetObjectForNativeVariant(addr)!; #pragma warning restore 612, 618 } } diff --git a/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs b/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs index 852b38e481eab..d862355eb6760 100644 --- a/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs +++ b/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs @@ -29,9 +29,9 @@ internal struct Variant internal class UnsafeNativeMethods { [DllImport(ExternDll.Activeds, ExactSpelling = true, EntryPoint = "ADsOpenObject", CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - private static extern int IntADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject); + private static extern int IntADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject); - public static int ADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject) + public static int ADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject) { try { @@ -86,17 +86,17 @@ string Schema void SetInfo(); - object Get([In, MarshalAs(UnmanagedType.BStr)] string bstrName); + object? Get([In, MarshalAs(UnmanagedType.BStr)] string bstrName); - void Put([In, MarshalAs(UnmanagedType.BStr)] string bstrName, [In] object vProp); + void Put([In, MarshalAs(UnmanagedType.BStr)] string bstrName, [In] object? vProp); [PreserveSig] - int GetEx([In, MarshalAs(UnmanagedType.BStr)] string bstrName, [Out] out object value); + int GetEx([In, MarshalAs(UnmanagedType.BStr)] string bstrName, [Out] out object? value); void PutEx( [In, MarshalAs(UnmanagedType.U4)] int lnControlCode, [In, MarshalAs(UnmanagedType.BStr)] string bstrName, - [In] object vProp); + [In] object? vProp); void GetInfoEx([In] object vProperties, [In, MarshalAs(UnmanagedType.U4)] int lnReserved); } @@ -116,13 +116,13 @@ object _NewEnum get; } - object Filter { get; set; } + object? Filter { get; set; } object Hints { get; set; } [return: MarshalAs(UnmanagedType.Interface)] object GetObject( - [In, MarshalAs(UnmanagedType.BStr)] string className, + [In, MarshalAs(UnmanagedType.BStr)] string? className, [In, MarshalAs(UnmanagedType.BStr)] string relativeName); [return: MarshalAs(UnmanagedType.Interface)] @@ -137,12 +137,12 @@ void Delete( [return: MarshalAs(UnmanagedType.Interface)] object CopyHere( [In, MarshalAs(UnmanagedType.BStr)] string sourceName, - [In, MarshalAs(UnmanagedType.BStr)] string newName); + [In, MarshalAs(UnmanagedType.BStr)] string? newName); [return: MarshalAs(UnmanagedType.Interface)] object MoveHere( [In, MarshalAs(UnmanagedType.BStr)] string sourceName, - [In, MarshalAs(UnmanagedType.BStr)] string newName); + [In, MarshalAs(UnmanagedType.BStr)] string? newName); } [ComImport, Guid("B2BD0902-8878-11D1-8C21-00C04FD8D503")] @@ -320,8 +320,8 @@ public interface IDirectorySearch void SetSearchPreference([In] IntPtr /*ads_searchpref_info * */pSearchPrefs, int dwNumPrefs); void ExecuteSearch( - [In, MarshalAs(UnmanagedType.LPWStr)] string pszSearchFilter, - [In, MarshalAs(UnmanagedType.LPArray)] string[] pAttributeNames, + [In, MarshalAs(UnmanagedType.LPWStr)] string? pszSearchFilter, + [In, MarshalAs(UnmanagedType.LPArray)] string[]? pAttributeNames, [In] int dwNumberAttributes, [Out] out IntPtr hSearchResult); diff --git a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj index 311e3ab3413ea..085cba0427ca6 100644 --- a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj +++ b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj @@ -4,6 +4,7 @@ $(NetCoreAppCurrent)-windows;netstandard2.0;netcoreapp2.0-windows true true + enable diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstance.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstance.cs index a48059fab5729..a584ab7d00153 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstance.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstance.cs @@ -14,18 +14,18 @@ public class AdamInstance : DirectoryServer private bool _disposed; // for public properties - private string _cachedHostName; + private string? _cachedHostName; private int _cachedLdapPort = -1; private int _cachedSslPort = -1; private bool _defaultPartitionInitialized; private bool _defaultPartitionModified; - private ConfigurationSet _currentConfigSet; - private string _cachedDefaultPartition; - private AdamRoleCollection _cachedRoles; + private ConfigurationSet? _currentConfigSet; + private string? _cachedDefaultPartition; + private AdamRoleCollection? _cachedRoles; private IntPtr _ADAMHandle = (IntPtr)0; private IntPtr _authIdentity = IntPtr.Zero; - private SyncUpdateCallback _userDelegate; + private SyncUpdateCallback? _userDelegate; private readonly SyncReplicaFromAllServersCallback _syncAllFunctionPointer; #region constructors @@ -55,8 +55,8 @@ internal AdamInstance(DirectoryContext context, string adamHostName, DirectoryEn // the replica name should be in the form dnshostname:port this.replicaName = adamHostName; - string portNumber; - Utils.SplitServerNameAndPortNumber(context.Name, out portNumber); + string? portNumber; + Utils.SplitServerNameAndPortNumber(context.Name!, out portNumber); if (portNumber != null) { this.replicaName = this.replicaName + ":" + portNumber; @@ -109,8 +109,8 @@ protected override void Dispose(bool disposing) public static AdamInstance GetAdamInstance(DirectoryContext context) { - DirectoryEntryManager directoryEntryMgr = null; - string dnsHostName = null; + DirectoryEntryManager? directoryEntryMgr = null; + string? dnsHostName = null; // check that the context is not null if (context == null) @@ -144,7 +144,7 @@ public static AdamInstance GetAdamInstance(DirectoryContext context) { throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.AINotFound, context.Name), typeof(AdamInstance), context.Name); } - dnsHostName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName); + dnsHostName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName)!; } catch (COMException e) { @@ -195,7 +195,7 @@ public static AdamInstance FindOne(DirectoryContext context, string partitionNam public static AdamInstanceCollection FindAll(DirectoryContext context, string partitionName) { - AdamInstanceCollection adamInstanceCollection = null; + AdamInstanceCollection? adamInstanceCollection = null; // validate parameters (partitionName validated by the call to ConfigSet) if (context == null) @@ -264,7 +264,7 @@ public void SeizeRoleOwnership(AdamRole role) { // set the "fsmoRoleOwner" attribute on the appropriate role object // to the NTDSAObjectName of this ADAM Instance - string roleObjectDN = null; + string? roleObjectDN = null; CheckIfDisposed(); @@ -286,7 +286,7 @@ public void SeizeRoleOwnership(AdamRole role) } } - DirectoryEntry roleObjectEntry = null; + DirectoryEntry? roleObjectEntry = null; try { roleObjectEntry = DirectoryEntryManager.GetDirectoryEntry(context, roleObjectDN); @@ -518,7 +518,7 @@ public string HostName if (_cachedHostName == null) { DirectoryEntry serverEntry = directoryEntryMgr.GetCachedDirectoryEntry(ServerObjectName); - _cachedHostName = (string)PropertyManager.GetPropertyValue(context, serverEntry, PropertyManager.DnsHostName); + _cachedHostName = (string)PropertyManager.GetPropertyValue(context, serverEntry, PropertyManager.DnsHostName)!; } return _cachedHostName; } @@ -532,7 +532,7 @@ public int LdapPort if (_cachedLdapPort == -1) { DirectoryEntry ntdsaEntry = directoryEntryMgr.GetCachedDirectoryEntry(NtdsaObjectName); - _cachedLdapPort = (int)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSPortLDAP); + _cachedLdapPort = (int)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSPortLDAP)!; } return _cachedLdapPort; } @@ -546,7 +546,7 @@ public int SslPort if (_cachedSslPort == -1) { DirectoryEntry ntdsaEntry = directoryEntryMgr.GetCachedDirectoryEntry(NtdsaObjectName); - _cachedSslPort = (int)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSPortSSL); + _cachedSslPort = (int)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSPortSSL)!; } return _cachedSslPort; } @@ -559,8 +559,8 @@ public AdamRoleCollection Roles get { CheckIfDisposed(); - DirectoryEntry schemaEntry = null; - DirectoryEntry partitionsEntry = null; + DirectoryEntry? schemaEntry = null; + DirectoryEntry? partitionsEntry = null; try { @@ -570,14 +570,14 @@ public AdamRoleCollection Roles ArrayList roleList = new ArrayList(); schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.SchemaNamingContext)); - if (NtdsaObjectName.Equals((string)PropertyManager.GetPropertyValue(context, schemaEntry, PropertyManager.FsmoRoleOwner))) + if (NtdsaObjectName.Equals((string)PropertyManager.GetPropertyValue(context, schemaEntry, PropertyManager.FsmoRoleOwner)!)) { roleList.Add(AdamRole.SchemaRole); } partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); - if (NtdsaObjectName.Equals((string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner))) + if (NtdsaObjectName.Equals((string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)!)) { roleList.Add(AdamRole.NamingRole); } @@ -604,7 +604,7 @@ public AdamRoleCollection Roles } } - public string DefaultPartition + public string? DefaultPartition { get { @@ -622,7 +622,7 @@ public string DefaultPartition } else { - _cachedDefaultPartition = (string)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSDefaultNamingContext); + _cachedDefaultPartition = (string)PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.MsDSDefaultNamingContext)!; } } catch (COMException e) @@ -667,7 +667,7 @@ public string DefaultPartition } } - public override string IPAddress + public override string? IPAddress { get { @@ -695,7 +695,7 @@ public override string SiteName DirectoryEntry siteEntry = DirectoryEntryManager.GetDirectoryEntry(context, SiteObjectName); try { - cachedSiteName = (string)PropertyManager.GetPropertyValue(context, siteEntry, PropertyManager.Cn); + cachedSiteName = (string)PropertyManager.GetPropertyValue(context, siteEntry, PropertyManager.Cn)!; } finally { @@ -742,7 +742,7 @@ internal string ServerObjectName DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { - cachedServerObjectName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ServerName); + cachedServerObjectName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ServerName)!; } catch (COMException e) { @@ -767,7 +767,7 @@ internal string NtdsaObjectName DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { - cachedNtdsaObjectName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName); + cachedNtdsaObjectName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName)!; } catch (COMException e) { @@ -790,14 +790,14 @@ internal Guid NtdsaObjectGuid if (cachedNtdsaObjectGuid == Guid.Empty) { DirectoryEntry ntdsaEntry = directoryEntryMgr.GetCachedDirectoryEntry(NtdsaObjectName); - byte[] guidByteArray = (byte[])PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.ObjectGuid); + byte[] guidByteArray = (byte[])PropertyManager.GetPropertyValue(context, ntdsaEntry, PropertyManager.ObjectGuid)!; cachedNtdsaObjectGuid = new Guid(guidByteArray); } return cachedNtdsaObjectGuid; } } - public override SyncUpdateCallback SyncFromAllServersCallback + public override SyncUpdateCallback? SyncFromAllServersCallback { get { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstanceCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstanceCollection.cs index eec2403464757..df597ac28eaf6 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstanceCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADAMInstanceCollection.cs @@ -17,7 +17,7 @@ internal AdamInstanceCollection(ArrayList values) } } - public AdamInstance this[int index] => (AdamInstance)InnerList[index]; + public AdamInstance this[int index] => (AdamInstance)InnerList[index]!; public bool Contains(AdamInstance adamInstance) { @@ -28,7 +28,7 @@ public bool Contains(AdamInstance adamInstance) for (int i = 0; i < InnerList.Count; i++) { - AdamInstance tmp = (AdamInstance)InnerList[i]; + AdamInstance tmp = (AdamInstance)InnerList[i]!; if (Utils.Compare(tmp.Name, adamInstance.Name) == 0) { return true; @@ -46,7 +46,7 @@ public int IndexOf(AdamInstance adamInstance) for (int i = 0; i < InnerList.Count; i++) { - AdamInstance tmp = (AdamInstance)InnerList[i]; + AdamInstance tmp = (AdamInstance)InnerList[i]!; if (Utils.Compare(tmp.Name, adamInstance.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADSearcher.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADSearcher.cs index 37090c9670007..898d79cc0ee38 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADSearcher.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ADSearcher.cs @@ -26,7 +26,7 @@ public ADSearcher(DirectoryEntry searchRoot, string filter, string[] propertiesT _searcher.PageSize = 512; } - public ADSearcher(DirectoryEntry searchRoot, string filter, string[] propertiesToLoad, SearchScope scope, bool pagedSearch, bool cacheResults) + public ADSearcher(DirectoryEntry searchRoot, string? filter, string[] propertiesToLoad, SearchScope scope, bool pagedSearch, bool cacheResults) { _searcher = new DirectorySearcher(searchRoot, filter, propertiesToLoad, scope); // set proper time out @@ -40,13 +40,13 @@ public ADSearcher(DirectoryEntry searchRoot, string filter, string[] propertiesT _searcher.CacheResults = cacheResults; } - public SearchResult FindOne() => _searcher.FindOne(); + public SearchResult? FindOne() => _searcher.FindOne(); public SearchResultCollection FindAll() => _searcher.FindAll(); public StringCollection PropertiesToLoad => _searcher.PropertiesToLoad; - public string Filter + public string? Filter { get => _searcher.Filter; set => _searcher.Filter = value; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransport.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransport.cs index a7522a47b5a7a..0a6f32845e4a2 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransport.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryInterSiteTransport.cs @@ -55,7 +55,7 @@ public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryCon try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string containerDN = "CN=Inter-Site Transports,CN=Sites," + config; if (transport == ActiveDirectoryTransportType.Rpc) containerDN = "CN=IP," + containerDN; @@ -119,7 +119,7 @@ public bool IgnoreReplicationSchedule try { if (_cachedEntry.Properties.Contains("options")) - option = (int)_cachedEntry.Properties["options"][0]; + option = (int)_cachedEntry.Properties["options"][0]!; } catch (COMException e) { @@ -141,7 +141,7 @@ public bool IgnoreReplicationSchedule try { if (_cachedEntry.Properties.Contains("options")) - option = (int)_cachedEntry.Properties["options"][0]; + option = (int)_cachedEntry.Properties["options"][0]!; // NTDSTRANSPORT_OPT_IGNORE_SCHEDULES ( 1 << 0 ) Schedules disabled if (value) @@ -169,7 +169,7 @@ public bool BridgeAllSiteLinks try { if (_cachedEntry.Properties.Contains("options")) - option = (int)_cachedEntry.Properties["options"][0]; + option = (int)_cachedEntry.Properties["options"][0]!; } catch (COMException e) { @@ -192,7 +192,7 @@ public bool BridgeAllSiteLinks try { if (_cachedEntry.Properties.Contains("options")) - option = (int)_cachedEntry.Properties["options"][0]; + option = (int)_cachedEntry.Properties["options"][0]!; // NTDSTRANSPORT_OPT_BRIDGES_REQUIRED (1 << 1 ) siteLink bridges are required, all site links are not bridged // That is to say, if this bit is set, it means that all site links are not bridged and user needs to create specific bridge @@ -226,7 +226,7 @@ public ReadOnlySiteLinkCollection SiteLinks "(&(objectClass=siteLink)(objectCategory=SiteLink))", new string[] { "cn" }, SearchScope.OneLevel); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -242,7 +242,7 @@ public ReadOnlySiteLinkCollection SiteLinks foreach (SearchResult result in results) { DirectoryEntry connectionEntry = result.GetDirectoryEntry(); - string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn); + string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn)!; ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(_context, cn, _transport, true, connectionEntry); _siteLinkCollection.Add(link); } @@ -274,7 +274,7 @@ public ReadOnlySiteLinkBridgeCollection SiteLinkBridges "(&(objectClass=siteLinkBridge)(objectCategory=SiteLinkBridge))", new string[] { "cn" }, SearchScope.OneLevel); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -290,7 +290,7 @@ public ReadOnlySiteLinkBridgeCollection SiteLinkBridges foreach (SearchResult result in results) { DirectoryEntry connectionEntry = result.GetDirectoryEntry(); - string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn); + string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn)!; ActiveDirectorySiteLinkBridge bridge = new ActiveDirectorySiteLinkBridge(_context, cn, _transport, true); bridge.cachedEntry = connectionEntry; _bridgeCollection.Add(bridge); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryPartition.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryPartition.cs index 816bdf23da26b..e6ebc323006b1 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryPartition.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryPartition.cs @@ -6,9 +6,9 @@ namespace System.DirectoryServices.ActiveDirectory public abstract class ActiveDirectoryPartition : IDisposable { private bool _disposed; - internal string partitionName; - internal DirectoryContext context; - internal DirectoryEntryManager directoryEntryMgr; + internal string partitionName = null!; + internal DirectoryContext context = null!; + internal DirectoryEntryManager directoryEntryMgr = null!; #region constructors protected ActiveDirectoryPartition() diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryReplicationMetaData.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryReplicationMetaData.cs index 06ffdcdb09d03..07316bd14c160 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryReplicationMetaData.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectoryReplicationMetaData.cs @@ -19,14 +19,14 @@ internal ActiveDirectoryReplicationMetadata(DirectoryServer server) _nameTable = Hashtable.Synchronized(tempNameTable); } - public AttributeMetadata this[string name] + public AttributeMetadata? this[string name] { get { string tempName = name.ToLowerInvariant(); if (Contains(tempName)) { - return (AttributeMetadata)InnerHashtable[tempName]; + return (AttributeMetadata)InnerHashtable[tempName]!; } else return null; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchema.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchema.cs index 229c1dc56d1ac..73a386b9732b9 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchema.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchema.cs @@ -27,8 +27,8 @@ public class ActiveDirectorySchema : ActiveDirectoryPartition { private bool _disposed; private DirectoryEntry _schemaEntry; - private DirectoryEntry _abstractSchemaEntry; - private DirectoryServer _cachedSchemaRoleOwner; + private DirectoryEntry? _abstractSchemaEntry; + private DirectoryServer? _cachedSchemaRoleOwner; #region constructors internal ActiveDirectorySchema(DirectoryContext context, string distinguishedName) @@ -64,7 +64,7 @@ protected override void Dispose(bool disposing) if (_schemaEntry != null) { _schemaEntry.Dispose(); - _schemaEntry = null; + _schemaEntry = null!; } // dispose the abstract schema entry if (_abstractSchemaEntry != null) @@ -128,7 +128,7 @@ public static ActiveDirectorySchema GetSchema(DirectoryContext context) context = new DirectoryContext(context); DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); - string schemaNC = null; + string schemaNC; try { DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); @@ -138,7 +138,7 @@ public static ActiveDirectorySchema GetSchema(DirectoryContext context) throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.ServerNotFound, context.Name), typeof(ActiveDirectorySchema), null); } - schemaNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.SchemaNamingContext); + schemaNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.SchemaNamingContext)!; } catch (COMException e) { @@ -183,7 +183,7 @@ public void RefreshSchema() CheckIfDisposed(); // Refresh the schema on the server - DirectoryEntry rootDSE = null; + DirectoryEntry? rootDSE = null; try { rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); @@ -428,13 +428,13 @@ internal static ReadOnlyActiveDirectorySchemaPropertyCollection GetAllProperties propertiesToLoad[2] = PropertyManager.IsDefunct; ADSearcher searcher = new ADSearcher(schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { resCol = searcher.FindAll(); foreach (SearchResult res in resCol) { - string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName); + string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName)!; DirectoryEntry directoryEntry = res.GetDirectoryEntry(); directoryEntry.AuthenticationType = Utils.DefaultAuthType; @@ -445,12 +445,12 @@ internal static ReadOnlyActiveDirectorySchemaPropertyCollection GetAllProperties if ((res.Properties[PropertyManager.IsDefunct] != null) && (res.Properties[PropertyManager.IsDefunct].Count > 0)) { - isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0]; + isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0]!; } if (isDefunct) { - string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn); + string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn)!; propertyList.Add(new ActiveDirectorySchemaProperty(context, commonName, ldapDisplayName, directoryEntry, schemaEntry)); } else @@ -485,13 +485,13 @@ internal static ReadOnlyActiveDirectorySchemaClassCollection GetAllClasses(Direc propertiesToLoad[2] = PropertyManager.IsDefunct; ADSearcher searcher = new ADSearcher(schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { resCol = searcher.FindAll(); foreach (SearchResult res in resCol) { - string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName); + string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName)!; DirectoryEntry directoryEntry = res.GetDirectoryEntry(); directoryEntry.AuthenticationType = Utils.DefaultAuthType; @@ -502,12 +502,12 @@ internal static ReadOnlyActiveDirectorySchemaClassCollection GetAllClasses(Direc if ((res.Properties[PropertyManager.IsDefunct] != null) && (res.Properties[PropertyManager.IsDefunct].Count > 0)) { - isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0]; + isDefunct = (bool)res.Properties[PropertyManager.IsDefunct][0]!; } if (isDefunct) { - string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn); + string commonName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn)!; classList.Add(new ActiveDirectorySchemaClass(context, commonName, ldapDisplayName, directoryEntry, schemaEntry)); } else @@ -541,7 +541,7 @@ private DirectoryServer GetSchemaRoleOwner() if (context.isADAMConfigSet()) { // ADAM - string adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)); + string adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)!); DirectoryContext adamInstContext = Utils.GetNewDirectoryContext(adamInstName, DirectoryContextType.DirectoryServer, context); return new AdamInstance(adamInstContext, adamInstName); } @@ -549,19 +549,19 @@ private DirectoryServer GetSchemaRoleOwner() { // could be AD or adam server - DirectoryServer server = null; + DirectoryServer? server = null; DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); if (Utils.CheckCapability(rootDSE, Capability.ActiveDirectory)) { - string dcName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)); + string dcName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)!); DirectoryContext dcContext = Utils.GetNewDirectoryContext(dcName, DirectoryContextType.DirectoryServer, context); server = new DomainController(dcContext, dcName); } else { // ADAM case again - string adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)); + string adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, _schemaEntry, PropertyManager.FsmoRoleOwner)!); DirectoryContext adamInstContext = Utils.GetNewDirectoryContext(adamInstName, DirectoryContextType.DirectoryServer, context); server = new AdamInstance(adamInstContext, adamInstName); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs index b03c89f67ee1a..a33c8f9a66b24 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs @@ -14,35 +14,35 @@ namespace System.DirectoryServices.ActiveDirectory public class ActiveDirectorySchemaClass : IDisposable { // private variables - private DirectoryEntry _classEntry; - private DirectoryEntry _schemaEntry; - private DirectoryEntry _abstractClassEntry; - private readonly NativeComInterfaces.IAdsClass _iadsClass; + private DirectoryEntry? _classEntry; + private DirectoryEntry? _schemaEntry; + private DirectoryEntry? _abstractClassEntry; + private readonly NativeComInterfaces.IAdsClass? _iadsClass; private readonly DirectoryContext _context; internal bool isBound; private bool _disposed; - private ActiveDirectorySchema _schema; + private ActiveDirectorySchema? _schema; private bool _propertiesFromSchemaContainerInitialized; private bool _isDefunctOnServer; - private Hashtable _propertyValuesFromServer; + private Hashtable? _propertyValuesFromServer; // private variables for all the properties of this class private readonly string _ldapDisplayName; - private string _commonName; - private string _oid; - private string _description; + private string? _commonName; + private string? _oid; + private string? _description; private bool _descriptionInitialized; private bool _isDefunct; - private ActiveDirectorySchemaClassCollection _possibleSuperiors; - private ActiveDirectorySchemaClassCollection _auxiliaryClasses; - private ReadOnlyActiveDirectorySchemaClassCollection _possibleInferiors; - private ActiveDirectorySchemaPropertyCollection _mandatoryProperties; - private ActiveDirectorySchemaPropertyCollection _optionalProperties; - private ActiveDirectorySchemaClass _subClassOf; + private ActiveDirectorySchemaClassCollection? _possibleSuperiors; + private ActiveDirectorySchemaClassCollection? _auxiliaryClasses; + private ReadOnlyActiveDirectorySchemaClassCollection? _possibleInferiors; + private ActiveDirectorySchemaPropertyCollection? _mandatoryProperties; + private ActiveDirectorySchemaPropertyCollection? _optionalProperties; + private ActiveDirectorySchemaClass? _subClassOf; private SchemaClassType _type = SchemaClassType.Structural; private bool _typeInitialized; - private byte[] _schemaGuidBinaryForm; - private string _defaultSDSddlForm; + private byte[]? _schemaGuidBinaryForm; + private string? _defaultSDSddlForm; private bool _defaultSDSddlFormInitialized; #region constructors @@ -92,7 +92,7 @@ public ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayNa } // Internal constructor - internal ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayName, DirectoryEntry classEntry, DirectoryEntry schemaEntry) + internal ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayName, DirectoryEntry? classEntry, DirectoryEntry? schemaEntry) { _context = context; _ldapDisplayName = ldapDisplayName; @@ -148,7 +148,7 @@ internal ActiveDirectorySchemaClass(DirectoryContext context, string commonName, // names _commonName = commonName; - _ldapDisplayName = (string)GetValueFromCache(PropertyManager.LdapDisplayName, true); + _ldapDisplayName = (string)GetValueFromCache(PropertyManager.LdapDisplayName, true)!; // this constructor is only called for defunct classes _isDefunctOnServer = true; @@ -226,7 +226,7 @@ protected virtual void Dispose(bool disposing) #region public methods public static ActiveDirectorySchemaClass FindByName(DirectoryContext context, string ldapDisplayName) { - ActiveDirectorySchemaClass schemaClass = null; + ActiveDirectorySchemaClass? schemaClass = null; if (context == null) { @@ -260,7 +260,7 @@ public static ActiveDirectorySchemaClass FindByName(DirectoryContext context, st context = new DirectoryContext(context); // create a schema class - schemaClass = new ActiveDirectorySchemaClass(context, ldapDisplayName, (DirectoryEntry)null, null); + schemaClass = new ActiveDirectorySchemaClass(context, ldapDisplayName, (DirectoryEntry?)null, null); return schemaClass; } @@ -365,14 +365,14 @@ public void Save() try { // commit the classEntry to server - _classEntry.CommitChanges(); + _classEntry!.CommitChanges(); // Refresh the schema cache on the schema role owner if (_schema == null) { ActiveDirectorySchema schemaObject = ActiveDirectorySchema.GetSchema(_context); bool alreadyUsingSchemaRoleOwnerContext = false; - DirectoryServer schemaRoleOwner = null; + DirectoryServer? schemaRoleOwner = null; try { @@ -466,7 +466,7 @@ public string Name } } - public string CommonName + public string? CommonName { get { @@ -477,7 +477,7 @@ public string CommonName if (_commonName == null) { // get the property from the server - _commonName = (string)GetValueFromCache(PropertyManager.Cn, true); + _commonName = (string)GetValueFromCache(PropertyManager.Cn, true)!; } } return _commonName; @@ -495,7 +495,7 @@ public string CommonName } } - public string Oid + public string? Oid { get { @@ -511,7 +511,7 @@ public string Oid { try { - _oid = _iadsClass.OID; + _oid = _iadsClass!.OID; } catch (COMException e) { @@ -520,7 +520,7 @@ public string Oid } else { - _oid = (string)GetValueFromCache(PropertyManager.GovernsID, true); + _oid = (string)GetValueFromCache(PropertyManager.GovernsID, true)!; } } } @@ -539,7 +539,7 @@ public string Oid } } - public string Description + public string? Description { get { @@ -550,7 +550,7 @@ public string Description if (!_descriptionInitialized) { // get the property from the server - _description = (string)GetValueFromCache(PropertyManager.Description, false); + _description = (string?)GetValueFromCache(PropertyManager.Description, false); _descriptionInitialized = true; } } @@ -611,10 +611,10 @@ public ActiveDirectorySchemaClassCollection PossibleSuperiors // IADsClass.PossibleSuperiors can return either a collection or a string // (if there is only one value) // - object value = null; + object? value = null; try { - value = _iadsClass.PossibleSuperiors; + value = _iadsClass!.PossibleSuperiors; } catch (COMException e) { @@ -637,7 +637,7 @@ public ActiveDirectorySchemaClassCollection PossibleSuperiors else { // single value - possibleSuperiorsList.Add((string)value); + possibleSuperiorsList.Add((string)value!); } _possibleSuperiors = new ActiveDirectorySchemaClassCollection(_context, this, true /* isBound */, PropertyManager.PossibleSuperiors, possibleSuperiorsList, true /* onlyNames */); @@ -710,10 +710,10 @@ public ActiveDirectorySchemaPropertyCollection MandatoryProperties // IADsClass.MandatoryProperties can return either a collection or a string // (if there is only one value) // - object value = null; + object? value = null; try { - value = _iadsClass.MandatoryProperties; + value = _iadsClass!.MandatoryProperties; } catch (COMException e) { @@ -736,7 +736,7 @@ public ActiveDirectorySchemaPropertyCollection MandatoryProperties else { // single value - mandatoryPropertiesList.Add((string)value); + mandatoryPropertiesList.Add((string)value!); } _mandatoryProperties = new ActiveDirectorySchemaPropertyCollection(_context, this, true /* isBound */, PropertyManager.MustContain, mandatoryPropertiesList, true /* onlyNames */); @@ -786,10 +786,10 @@ public ActiveDirectorySchemaPropertyCollection OptionalProperties // IADsClass.OptionalProperties can return either a collection or a string // (if there is only one value) // - object value = null; + object? value = null; try { - value = _iadsClass.OptionalProperties; + value = _iadsClass!.OptionalProperties; } catch (COMException e) { @@ -812,7 +812,7 @@ public ActiveDirectorySchemaPropertyCollection OptionalProperties else { // single value - optionalPropertiesList.Add((string)value); + optionalPropertiesList.Add((string)value!); } _optionalProperties = new ActiveDirectorySchemaPropertyCollection(_context, this, true /* isBound */, PropertyManager.MayContain, optionalPropertiesList, true /* onlyNames */); @@ -871,10 +871,10 @@ public ActiveDirectorySchemaClassCollection AuxiliaryClasses // IADsClass.AuxDerivedFrom can return either a collection or a string // (if there is only one value) // - object value = null; + object? value = null; try { - value = _iadsClass.AuxDerivedFrom; + value = _iadsClass!.AuxDerivedFrom; } catch (COMException e) { @@ -897,7 +897,7 @@ public ActiveDirectorySchemaClassCollection AuxiliaryClasses else { // single value - auxiliaryClassesList.Add((string)value); + auxiliaryClassesList.Add((string)value!); } _auxiliaryClasses = new ActiveDirectorySchemaClassCollection(_context, this, true /* isBound */, PropertyManager.AuxiliaryClass, auxiliaryClassesList, true /* onlyNames */); @@ -926,7 +926,7 @@ public ActiveDirectorySchemaClassCollection AuxiliaryClasses } } - public ActiveDirectorySchemaClass SubClassOf + public ActiveDirectorySchemaClass? SubClassOf { get { @@ -937,7 +937,7 @@ public ActiveDirectorySchemaClass SubClassOf if (_subClassOf == null) { // get the property from the server - _subClassOf = new ActiveDirectorySchemaClass(_context, (string)GetValueFromCache(PropertyManager.SubClassOf, true), (DirectoryEntry)null, _schemaEntry); + _subClassOf = new ActiveDirectorySchemaClass(_context, (string)GetValueFromCache(PropertyManager.SubClassOf, true)!, (DirectoryEntry?)null, _schemaEntry); } } return _subClassOf; @@ -966,7 +966,7 @@ public SchemaClassType Type if (!_typeInitialized) { // get the property from the server - _type = (SchemaClassType)((int)GetValueFromCache(PropertyManager.ObjectClassCategory, true)); + _type = (SchemaClassType)((int)GetValueFromCache(PropertyManager.ObjectClassCategory, true)!); _typeInitialized = true; } } @@ -1002,12 +1002,12 @@ public Guid SchemaGuid if (_schemaGuidBinaryForm == null) { // get the property from the server - _schemaGuidBinaryForm = (byte[])GetValueFromCache(PropertyManager.SchemaIDGuid, true); + _schemaGuidBinaryForm = (byte[]?)GetValueFromCache(PropertyManager.SchemaIDGuid, true); } } // we cache the byte array and create a new guid each time - return new Guid(_schemaGuidBinaryForm); + return new Guid(_schemaGuidBinaryForm!); } set { @@ -1022,20 +1022,20 @@ public Guid SchemaGuid } } - public ActiveDirectorySecurity DefaultObjectSecurityDescriptor + public ActiveDirectorySecurity? DefaultObjectSecurityDescriptor { get { CheckIfDisposed(); - ActiveDirectorySecurity defaultObjectSecurityDescriptor = null; + ActiveDirectorySecurity? defaultObjectSecurityDescriptor = null; if (isBound) { if (!_defaultSDSddlFormInitialized) { // get the property from the server - _defaultSDSddlForm = (string)GetValueFromCache(PropertyManager.DefaultSecurityDescriptor, false); + _defaultSDSddlForm = (string?)GetValueFromCache(PropertyManager.DefaultSecurityDescriptor, false); _defaultSDSddlFormInitialized = true; } } @@ -1080,15 +1080,15 @@ private void CheckIfDisposed() // not an exception should be thrown if a value does not exist. If mustExist is true, this // will throw an exception is value does not exist. // - private object GetValueFromCache(string propertyName, bool mustExist) + private object? GetValueFromCache(string propertyName, bool mustExist) { - object value = null; + object? value = null; // retrieve the properties from the server if necessary InitializePropertiesFromSchemaContainer(); Debug.Assert(_propertyValuesFromServer != null); - ArrayList values = (ArrayList)_propertyValuesFromServer[propertyName.ToLowerInvariant()]; + ArrayList values = (ArrayList)_propertyValuesFromServer[propertyName.ToLowerInvariant()]!; Debug.Assert(values != null); if (values.Count < 1 && mustExist) @@ -1113,7 +1113,7 @@ private ICollection GetValuesFromCache(string propertyName) InitializePropertiesFromSchemaContainer(); Debug.Assert(_propertyValuesFromServer != null); - ArrayList values = (ArrayList)_propertyValuesFromServer[propertyName.ToLowerInvariant()]; + ArrayList values = (ArrayList)_propertyValuesFromServer[propertyName.ToLowerInvariant()]!; Debug.Assert(values != null); return values; @@ -1131,7 +1131,7 @@ private void InitializePropertiesFromSchemaContainer() _schemaEntry = DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext); } - _propertyValuesFromServer = GetPropertiesFromSchemaContainer(_context, _schemaEntry, (_isDefunctOnServer) ? _commonName : _ldapDisplayName, _isDefunctOnServer); + _propertyValuesFromServer = GetPropertiesFromSchemaContainer(_context, _schemaEntry, (_isDefunctOnServer) ? _commonName! : _ldapDisplayName, _isDefunctOnServer); _propertiesFromSchemaContainerInitialized = true; } } @@ -1145,7 +1145,7 @@ private void InitializePropertiesFromSchemaContainer() // internal static Hashtable GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { - Hashtable propertyValuesFromServer = null; + Hashtable? propertyValuesFromServer = null; // // The properties that are loaded from the schemaContainer for non-defunct classes: @@ -1260,13 +1260,13 @@ internal DirectoryEntry GetSchemaClassDirectoryEntry() if (_classEntry == null) { InitializePropertiesFromSchemaContainer(); - _classEntry = DirectoryEntryManager.GetDirectoryEntry(_context, (string)GetValueFromCache(PropertyManager.DistinguishedName, true)); + _classEntry = DirectoryEntryManager.GetDirectoryEntry(_context, (string)GetValueFromCache(PropertyManager.DistinguishedName, true)!); } return _classEntry; } - private void SetProperty(string propertyName, object value) + private void SetProperty(string propertyName, object? value) { // get the distinguished name to construct the directory entry GetSchemaClassDirectoryEntry(); @@ -1299,7 +1299,7 @@ private void SetProperty(string propertyName, object value) private ArrayList GetClasses(ICollection ldapDisplayNames) { ArrayList classes = new ArrayList(); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { @@ -1343,7 +1343,7 @@ private ArrayList GetClasses(ICollection ldapDisplayNames) foreach (SearchResult res in resCol) { - string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName); + string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName)!; DirectoryEntry de = res.GetDirectoryEntry(); de.AuthenticationType = Utils.DefaultAuthType; @@ -1377,7 +1377,7 @@ private ArrayList GetClasses(ICollection ldapDisplayNames) private ArrayList GetProperties(ICollection ldapDisplayNames) { ArrayList properties = new ArrayList(); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { @@ -1421,7 +1421,7 @@ private ArrayList GetProperties(ICollection ldapDisplayNames) foreach (SearchResult res in resCol) { - string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName); + string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName)!; DirectoryEntry de = res.GetDirectoryEntry(); de.AuthenticationType = Utils.DefaultAuthType; @@ -1455,7 +1455,7 @@ private ArrayList GetPropertyValuesRecursively(string[] propertyNames) // get the properties of the super class try { - if (Utils.Compare(SubClassOf.Name, Name) != 0) + if (Utils.Compare(SubClassOf!.Name, Name) != 0) { foreach (string value in SubClassOf.GetPropertyValuesRecursively(propertyNames)) { @@ -1469,7 +1469,7 @@ private ArrayList GetPropertyValuesRecursively(string[] propertyNames) // get the properties of the auxiliary classes foreach (string auxSchemaClassName in GetValuesFromCache(PropertyManager.AuxiliaryClass)) { - ActiveDirectorySchemaClass auxSchemaClass = new ActiveDirectorySchemaClass(_context, auxSchemaClassName, (DirectoryEntry)null, null); + ActiveDirectorySchemaClass auxSchemaClass = new ActiveDirectorySchemaClass(_context, auxSchemaClassName, (DirectoryEntry?)null, null); foreach (string property in auxSchemaClass.GetPropertyValuesRecursively(propertyNames)) { @@ -1481,7 +1481,7 @@ private ArrayList GetPropertyValuesRecursively(string[] propertyNames) } foreach (string auxSchemaClassName in GetValuesFromCache(PropertyManager.SystemAuxiliaryClass)) { - ActiveDirectorySchemaClass auxSchemaClass = new ActiveDirectorySchemaClass(_context, auxSchemaClassName, (DirectoryEntry)null, null); + ActiveDirectorySchemaClass auxSchemaClass = new ActiveDirectorySchemaClass(_context, auxSchemaClassName, (DirectoryEntry?)null, null); foreach (string property in auxSchemaClass.GetPropertyValuesRecursively(propertyNames)) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs index 47cb7878f8ea9..bf72e00ac2efe 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs @@ -8,7 +8,7 @@ namespace System.DirectoryServices.ActiveDirectory { public class ActiveDirectorySchemaClassCollection : CollectionBase { - private DirectoryEntry _classEntry; + private DirectoryEntry? _classEntry; private readonly string _propertyName; private readonly ActiveDirectorySchemaClass _schemaClass; private readonly bool _isBound; @@ -30,7 +30,7 @@ internal ActiveDirectorySchemaClassCollection(DirectoryContext context, { // all properties in writeable class collection are non-defunct // so calling constructor for non-defunct class - InnerList.Add(new ActiveDirectorySchemaClass(context, ldapDisplayName, (DirectoryEntry)null, null)); + InnerList.Add(new ActiveDirectorySchemaClass(context, ldapDisplayName, (DirectoryEntry?)null, null)); } } @@ -53,7 +53,7 @@ internal ActiveDirectorySchemaClassCollection(DirectoryContext context, public ActiveDirectorySchemaClass this[int index] { - get => (ActiveDirectorySchemaClass)List[index]; + get => (ActiveDirectorySchemaClass)List[index]!; set { if (value == null) @@ -178,7 +178,7 @@ public void Remove(ActiveDirectorySchemaClass schemaClass) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]; + ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaClass.Name) == 0) { List.Remove(tmp); @@ -224,7 +224,7 @@ public bool Contains(ActiveDirectorySchemaClass schemaClass) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]; + ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaClass.Name) == 0) { return true; @@ -253,7 +253,7 @@ public int IndexOf(ActiveDirectorySchemaClass schemaClass) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]; + ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaClass.Name) == 0) { return i; @@ -286,7 +286,7 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (_isBound) { @@ -297,7 +297,7 @@ protected override void OnInsertComplete(int index, object value) try { - _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaClass)value).Name); + _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaClass)value!).Name); } catch (COMException e) { @@ -306,7 +306,7 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { if (_isBound) { @@ -319,7 +319,7 @@ protected override void OnRemoveComplete(int index, object value) // these values would not exist in the classEntry // and therefore cannot be removed // we need to throw an exception here - string valueName = ((ActiveDirectorySchemaClass)value).Name; + string valueName = ((ActiveDirectorySchemaClass)value!).Name; try { @@ -339,7 +339,7 @@ protected override void OnRemoveComplete(int index, object value) } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { if (_isBound) { @@ -371,7 +371,7 @@ internal string[] GetMultiValuedProperty() string[] values = new string[InnerList.Count]; for (int i = 0; i < InnerList.Count; i++) { - values[i] = ((ActiveDirectorySchemaClass)InnerList[i]).Name; + values[i] = ((ActiveDirectorySchemaClass)InnerList[i]!).Name; } return values; } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaProperty.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaProperty.cs index bb0cbdd538e0f..181a6161757c9 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaProperty.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaProperty.cs @@ -21,25 +21,25 @@ internal enum SearchFlags : int public class ActiveDirectorySchemaProperty : IDisposable { // private variables - private DirectoryEntry _schemaEntry; - private DirectoryEntry _propertyEntry; - private DirectoryEntry _abstractPropertyEntry; - private readonly NativeComInterfaces.IAdsProperty _iadsProperty; + private DirectoryEntry? _schemaEntry; + private DirectoryEntry? _propertyEntry; + private DirectoryEntry? _abstractPropertyEntry; + private readonly NativeComInterfaces.IAdsProperty? _iadsProperty; private readonly DirectoryContext _context; internal bool isBound; private bool _disposed; - private ActiveDirectorySchema _schema; + private ActiveDirectorySchema? _schema; private bool _propertiesFromSchemaContainerInitialized; private bool _isDefunctOnServer; - private SearchResult _propertyValuesFromServer; + private SearchResult? _propertyValuesFromServer; // private variables for caching properties private readonly string _ldapDisplayName; - private string _commonName; - private string _oid; + private string? _commonName; + private string? _oid; private ActiveDirectorySyntax _syntax = (ActiveDirectorySyntax)(-1); private bool _syntaxInitialized; - private string _description; + private string? _description; private bool _descriptionInitialized; private bool _isSingleValued; private bool _isSingleValuedInitialized; @@ -52,11 +52,11 @@ public class ActiveDirectorySchemaProperty : IDisposable private bool _isDefunct; private SearchFlags _searchFlags = SearchFlags.None; private bool _searchFlagsInitialized; - private ActiveDirectorySchemaProperty _linkedProperty; + private ActiveDirectorySchemaProperty? _linkedProperty; private bool _linkedPropertyInitialized; private Nullable _linkId; private bool _linkIdInitialized; - private byte[] _schemaGuidBinaryForm; + private byte[]? _schemaGuidBinaryForm; // OMObjectClass values for the syntax //0x2B0C0287731C00854A @@ -146,7 +146,7 @@ public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDispla } // internal constructor - internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry) + internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry? propertyEntry, DirectoryEntry? schemaEntry) { _context = context; _ldapDisplayName = ldapDisplayName; @@ -201,7 +201,7 @@ internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonNa // names _commonName = commonName; - _ldapDisplayName = (string)GetValueFromCache(PropertyManager.LdapDisplayName, true); + _ldapDisplayName = (string)GetValueFromCache(PropertyManager.LdapDisplayName, true)!; // this constructor is only called for defunct classes _isDefunctOnServer = true; @@ -280,7 +280,7 @@ protected virtual void Dispose(bool disposing) #region public methods public static ActiveDirectorySchemaProperty FindByName(DirectoryContext context, string ldapDisplayName) { - ActiveDirectorySchemaProperty schemaProperty = null; + ActiveDirectorySchemaProperty? schemaProperty = null; if (context == null) { @@ -315,7 +315,7 @@ public static ActiveDirectorySchemaProperty FindByName(DirectoryContext context, context = new DirectoryContext(context); // create a schema property - schemaProperty = new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry)null, null); + schemaProperty = new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry?)null, null); return schemaProperty; } @@ -407,14 +407,14 @@ public void Save() try { // commit the classEntry to server - _propertyEntry.CommitChanges(); + _propertyEntry!.CommitChanges(); // Refresh the schema cache on the schema role owner if (_schema == null) { ActiveDirectorySchema schemaObject = ActiveDirectorySchema.GetSchema(_context); bool alreadyUsingSchemaRoleOwnerContext = false; - DirectoryServer schemaRoleOwner = null; + DirectoryServer? schemaRoleOwner = null; try { @@ -504,7 +504,7 @@ public string Name } } - public string CommonName + public string? CommonName { get { @@ -515,7 +515,7 @@ public string CommonName if (_commonName == null) { // get the property from the server - _commonName = (string)GetValueFromCache(PropertyManager.Cn, true); + _commonName = (string)GetValueFromCache(PropertyManager.Cn, true)!; } } return _commonName; @@ -536,7 +536,7 @@ public string CommonName } } - public string Oid + public string? Oid { get { @@ -552,7 +552,7 @@ public string Oid { try { - _oid = _iadsProperty.OID; + _oid = _iadsProperty!.OID; } catch (COMException e) { @@ -561,7 +561,7 @@ public string Oid } else { - _oid = (string)GetValueFromCache(PropertyManager.AttributeID, true); + _oid = (string)GetValueFromCache(PropertyManager.AttributeID, true)!; } } } @@ -593,11 +593,11 @@ public ActiveDirectorySyntax Syntax { if (!_syntaxInitialized) { - byte[] omObjectClassBinaryForm = (byte[])GetValueFromCache(PropertyManager.OMObjectClass, false); - OMObjectClass omObjectClass = (omObjectClassBinaryForm != null) ? new OMObjectClass(omObjectClassBinaryForm) : null; + byte[]? omObjectClassBinaryForm = (byte[]?)GetValueFromCache(PropertyManager.OMObjectClass, false); + OMObjectClass? omObjectClass = (omObjectClassBinaryForm != null) ? new OMObjectClass(omObjectClassBinaryForm) : null; - _syntax = MapSyntax((string)GetValueFromCache(PropertyManager.AttributeSyntax, true), - (int)GetValueFromCache(PropertyManager.OMSyntax, true), + _syntax = MapSyntax((string)GetValueFromCache(PropertyManager.AttributeSyntax, true)!, + (int)GetValueFromCache(PropertyManager.OMSyntax, true)!, omObjectClass); _syntaxInitialized = true; } @@ -622,7 +622,7 @@ public ActiveDirectorySyntax Syntax } } - public string Description + public string? Description { get { @@ -633,7 +633,7 @@ public string Description if (!_descriptionInitialized) { // get the property from the server - _description = (string)GetValueFromCache(PropertyManager.Description, false); + _description = (string?)GetValueFromCache(PropertyManager.Description, false); _descriptionInitialized = true; } } @@ -671,7 +671,7 @@ public bool IsSingleValued { try { - _isSingleValued = !_iadsProperty.MultiValued; + _isSingleValued = !_iadsProperty!.MultiValued; } catch (COMException e) { @@ -680,7 +680,7 @@ public bool IsSingleValued } else { - _isSingleValued = (bool)GetValueFromCache(PropertyManager.IsSingleValued, true); + _isSingleValued = (bool)GetValueFromCache(PropertyManager.IsSingleValued, true)!; } _isSingleValuedInitialized = true; } @@ -830,7 +830,7 @@ public bool IsInGlobalCatalog if (!_isInGlobalCatalogInitialized) { // get the property from the server - object value = GetValueFromCache(PropertyManager.IsMemberOfPartialAttributeSet, false); + object? value = GetValueFromCache(PropertyManager.IsMemberOfPartialAttributeSet, false); _isInGlobalCatalog = (value != null) ? (bool)value : false; _isInGlobalCatalogInitialized = true; } @@ -866,7 +866,7 @@ public Nullable RangeLower { // get the property from the server // if the property is not set then we will return null - object value = GetValueFromCache(PropertyManager.RangeLower, false); + object? value = GetValueFromCache(PropertyManager.RangeLower, false); if (value == null) { _rangeLower = null; @@ -919,7 +919,7 @@ public Nullable RangeUpper { // get the property from the server // if the property is not set then we will return null - object value = GetValueFromCache(PropertyManager.RangeUpper, false); + object? value = GetValueFromCache(PropertyManager.RangeUpper, false); if (value == null) { _rangeUpper = null; @@ -981,7 +981,7 @@ public bool IsDefunct } } - public ActiveDirectorySchemaProperty Link + public ActiveDirectorySchemaProperty? Link { get { @@ -991,7 +991,7 @@ public ActiveDirectorySchemaProperty Link { if (!_linkedPropertyInitialized) { - object value = GetValueFromCache(PropertyManager.LinkID, false); + object? value = GetValueFromCache(PropertyManager.LinkID, false); int tempLinkId = (value != null) ? (int)value : -1; if (tempLinkId != -1) @@ -1037,7 +1037,7 @@ public Nullable LinkId { if (!_linkIdInitialized) { - object value = GetValueFromCache(PropertyManager.LinkID, false); + object? value = GetValueFromCache(PropertyManager.LinkID, false); // if the property was not set we will return null if (value == null) { @@ -1090,12 +1090,12 @@ public Guid SchemaGuid if (_schemaGuidBinaryForm == null) { // get the property from the server - _schemaGuidBinaryForm = (byte[])GetValueFromCache(PropertyManager.SchemaIDGuid, true); + _schemaGuidBinaryForm = (byte[])GetValueFromCache(PropertyManager.SchemaIDGuid, true)!; } } // we cache the byte array and create a new guid each time - return new Guid(_schemaGuidBinaryForm); + return new Guid(_schemaGuidBinaryForm!); } set { @@ -1128,16 +1128,16 @@ private void CheckIfDisposed() // not an exception should be thrown if a value does not exist. If mustExist is true, this // will throw an exception is value does not exist. // - private object GetValueFromCache(string propertyName, bool mustExist) + private object? GetValueFromCache(string propertyName, bool mustExist) { - object value = null; + object? value = null; // retrieve the properties from the server if necessary InitializePropertiesFromSchemaContainer(); Debug.Assert(_propertyValuesFromServer != null); - ResultPropertyValueCollection propertyValues = null; + ResultPropertyValueCollection? propertyValues = null; try { propertyValues = _propertyValuesFromServer.Properties[propertyName]; @@ -1173,7 +1173,7 @@ private void InitializePropertiesFromSchemaContainer() _schemaEntry = DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext); } - _propertyValuesFromServer = GetPropertiesFromSchemaContainer(_context, _schemaEntry, (_isDefunctOnServer) ? _commonName : _ldapDisplayName, _isDefunctOnServer); + _propertyValuesFromServer = GetPropertiesFromSchemaContainer(_context, _schemaEntry, (_isDefunctOnServer) ? _commonName! : _ldapDisplayName, _isDefunctOnServer); _propertiesFromSchemaContainerInitialized = true; } } @@ -1187,7 +1187,7 @@ private void InitializePropertiesFromSchemaContainer() // internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext context, DirectoryEntry schemaEntry, string name, bool isDefunctOnServer) { - SearchResult propertyValuesFromServer = null; + SearchResult? propertyValuesFromServer = null; // // The properties that are loaded from the schemaContainer for non-defunct classes: @@ -1244,7 +1244,7 @@ internal static SearchResult GetPropertiesFromSchemaContainer(DirectoryContext c str.Append("=TRUE))"); } - string[] propertiesToLoad = null; + string[]? propertiesToLoad = null; if (!isDefunctOnServer) { propertiesToLoad = new string[12]; @@ -1318,7 +1318,7 @@ internal DirectoryEntry GetSchemaPropertyDirectoryEntry() if (_propertyEntry == null) { InitializePropertiesFromSchemaContainer(); - _propertyEntry = DirectoryEntryManager.GetDirectoryEntry(_context, (string)GetValueFromCache(PropertyManager.DistinguishedName, true)); + _propertyEntry = DirectoryEntryManager.GetDirectoryEntry(_context, (string)GetValueFromCache(PropertyManager.DistinguishedName, true)!); } return _propertyEntry; @@ -1336,7 +1336,7 @@ private void InitializeSearchFlags() { if (!_searchFlagsInitialized) { - object value = GetValueFromCache(PropertyManager.SearchFlags, false); + object? value = GetValueFromCache(PropertyManager.SearchFlags, false); if (value != null) { @@ -1385,7 +1385,7 @@ private void ResetBitInSearchFlags(SearchFlags searchFlagBit) } } - private void SetProperty(string propertyName, object value) + private void SetProperty(string propertyName, object? value) { // get the distinguished name to construct the directory entry GetSchemaPropertyDirectoryEntry(); @@ -1404,7 +1404,7 @@ private void SetProperty(string propertyName, object value) } } - private ActiveDirectorySyntax MapSyntax(string syntaxId, int oMID, OMObjectClass oMObjectClass) + private ActiveDirectorySyntax MapSyntax(string syntaxId, int oMID, OMObjectClass? oMObjectClass) { for (int i = 0; i < s_syntaxes.Length; i++) { @@ -1429,7 +1429,7 @@ private void SetSyntax(ActiveDirectorySyntax syntax) _propertyEntry.Properties[PropertyManager.AttributeSyntax].Value = s_syntaxes[(int)syntax].attributeSyntax; _propertyEntry.Properties[PropertyManager.OMSyntax].Value = s_syntaxes[(int)syntax].oMSyntax; - OMObjectClass oMObjectClass = s_syntaxes[(int)syntax].oMObjectClass; + OMObjectClass? oMObjectClass = s_syntaxes[(int)syntax].oMObjectClass; if (oMObjectClass != null) { _propertyEntry.Properties[PropertyManager.OMObjectClass].Value = oMObjectClass.Data; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs index 30a327356dd4d..c14b53e12eb5f 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs @@ -8,7 +8,7 @@ namespace System.DirectoryServices.ActiveDirectory { public class ActiveDirectorySchemaPropertyCollection : CollectionBase { - private DirectoryEntry _classEntry; + private DirectoryEntry? _classEntry; private readonly string _propertyName; private readonly ActiveDirectorySchemaClass _schemaClass; private readonly bool _isBound; @@ -30,7 +30,7 @@ internal ActiveDirectorySchemaPropertyCollection(DirectoryContext context, { // all properties in writeable property collection are non-defunct // so calling constructor for non-defunct property - this.InnerList.Add(new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry)null, null)); + this.InnerList.Add(new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry?)null, null)); } } @@ -53,7 +53,7 @@ internal ActiveDirectorySchemaPropertyCollection(DirectoryContext context, public ActiveDirectorySchemaProperty this[int index] { - get => (ActiveDirectorySchemaProperty)List[index]; + get => (ActiveDirectorySchemaProperty)List[index]!; set { if (value == null) @@ -178,7 +178,7 @@ public void Remove(ActiveDirectorySchemaProperty schemaProperty) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0) { List.Remove(tmp); @@ -224,7 +224,7 @@ public bool Contains(ActiveDirectorySchemaProperty schemaProperty) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0) { return true; @@ -237,7 +237,7 @@ internal bool Contains(string propertyName) { for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, propertyName) == 0) { @@ -267,7 +267,7 @@ public int IndexOf(ActiveDirectorySchemaProperty schemaProperty) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0) { return i; @@ -299,7 +299,7 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (_isBound) { @@ -310,7 +310,7 @@ protected override void OnInsertComplete(int index, object value) try { - _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaProperty)value).Name); + _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaProperty)value!).Name); } catch (COMException e) { @@ -319,7 +319,7 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { if (_isBound) { @@ -332,7 +332,7 @@ protected override void OnRemoveComplete(int index, object value) // these values would not exist in the classEntry // and therefore cannot be removed // we need to throw an exception here - string valueName = ((ActiveDirectorySchemaProperty)value).Name; + string valueName = ((ActiveDirectorySchemaProperty)value!).Name; try { @@ -351,7 +351,7 @@ protected override void OnRemoveComplete(int index, object value) } } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { if (_isBound) { @@ -379,7 +379,7 @@ internal string[] GetMultiValuedProperty() string[] values = new string[InnerList.Count]; for (int i = 0; i < InnerList.Count; i++) { - values[i] = ((ActiveDirectorySchemaProperty)InnerList[i]).Name; + values[i] = ((ActiveDirectorySchemaProperty)InnerList[i]!).Name; } return values; } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySite.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySite.cs index 489bee4c7b443..48281bb491e39 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySite.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySite.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Diagnostics; using System.Text; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices.ActiveDirectory { @@ -30,9 +31,9 @@ public class ActiveDirectorySite : IDisposable internal readonly DirectoryContext context; private readonly string _name; internal readonly DirectoryEntry cachedEntry; - private DirectoryEntry _ntdsEntry; + private DirectoryEntry? _ntdsEntry; private readonly ActiveDirectorySubnetCollection _subnets; - private DirectoryServer _topologyGenerator; + private DirectoryServer? _topologyGenerator; private readonly ReadOnlySiteCollection _adjacentSites = new ReadOnlySiteCollection(); private bool _disposed; private readonly DomainCollection _domains = new DomainCollection(null); @@ -42,7 +43,7 @@ public class ActiveDirectorySite : IDisposable private ReadOnlyDirectoryServerCollection _bridgeheadServers = new ReadOnlyDirectoryServerCollection(); private readonly DirectoryServerCollection _SMTPBridgeheadServers; private readonly DirectoryServerCollection _RPCBridgeheadServers; - private byte[] _replicationSchedule; + private byte[]? _replicationSchedule; internal bool existing; private bool _subnetRetrieved; @@ -73,7 +74,7 @@ public static ActiveDirectorySite FindByName(DirectoryContext context, string si try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - sitedn = "CN=Sites," + (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + sitedn = "CN=Sites," + (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; de = DirectoryEntryManager.GetDirectoryEntry(context, sitedn); } catch (COMException e) @@ -94,7 +95,7 @@ public static ActiveDirectorySite FindByName(DirectoryContext context, string si SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); - SearchResult srchResult = adSearcher.FindOne(); + SearchResult? srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such site object @@ -134,11 +135,11 @@ public ActiveDirectorySite(DirectoryContext context, string siteName) _name = siteName; // bind to the rootdse to get the configurationnamingcontext - DirectoryEntry de = null; + DirectoryEntry? de = null; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; _siteDN = "CN=Sites," + config; // bind to the site container de = DirectoryEntryManager.GetDirectoryEntry(context, _siteDN); @@ -178,15 +179,15 @@ internal ActiveDirectorySite(DirectoryContext context, string siteName, bool exi this.existing = existing; DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - _siteDN = "CN=Sites," + (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + _siteDN = "CN=Sites," + (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; cachedEntry = DirectoryEntryManager.GetDirectoryEntry(context, "CN=" + siteName + "," + _siteDN); _subnets = new ActiveDirectorySubnetCollection(context, "CN=" + siteName + "," + _siteDN); string transportDN = "CN=IP,CN=Inter-Site Transports," + _siteDN; - _RPCBridgeheadServers = new DirectoryServerCollection(context, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName), transportDN); + _RPCBridgeheadServers = new DirectoryServerCollection(context, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!, transportDN); transportDN = "CN=SMTP,CN=Inter-Site Transports," + _siteDN; - _SMTPBridgeheadServers = new DirectoryServerCollection(context, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName), transportDN); + _SMTPBridgeheadServers = new DirectoryServerCollection(context, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!, transportDN); } public static ActiveDirectorySite GetComputerSite() @@ -209,11 +210,11 @@ public static ActiveDirectorySite GetComputerSite() { try { - string siteName = Marshal.PtrToStringUni(ptr); + string siteName = Marshal.PtrToStringUni(ptr)!; Debug.Assert(siteName != null); // find the forest this machine belongs to - string forestName = Locator.GetDomainControllerInfo(null, null, null, (long)PrivateLocatorFlags.DirectoryServicesRequired).DnsForestName; + string? forestName = Locator.GetDomainControllerInfo(null, null, null, (long)PrivateLocatorFlags.DirectoryServicesRequired).DnsForestName; DirectoryContext currentContext = Utils.GetNewDirectoryContext(forestName, DirectoryContextType.Forest, null); // existing site @@ -346,7 +347,8 @@ public ReadOnlySiteLinkCollection SiteLinks } } - public DirectoryServer InterSiteTopologyGenerator + [DisallowNull] + public DirectoryServer? InterSiteTopologyGenerator { get { @@ -370,13 +372,13 @@ public DirectoryServer InterSiteTopologyGenerator if (ISTGExist) { - string serverDN = (string)PropertyManager.GetPropertyValue(context, NTDSSiteEntry, PropertyManager.InterSiteTopologyGenerator); - string hostname = null; + string serverDN = (string)PropertyManager.GetPropertyValue(context, NTDSSiteEntry, PropertyManager.InterSiteTopologyGenerator)!; + string? hostname = null; DirectoryEntry tmp = DirectoryEntryManager.GetDirectoryEntry(context, serverDN); try { - hostname = (string)PropertyManager.GetPropertyValue(context, tmp.Parent, PropertyManager.DnsHostName); + hostname = (string)PropertyManager.GetPropertyValue(context, tmp.Parent, PropertyManager.DnsHostName)!; } catch (COMException e) { @@ -388,8 +390,8 @@ public DirectoryServer InterSiteTopologyGenerator } if (IsADAM) { - int port = (int)PropertyManager.GetPropertyValue(context, tmp, PropertyManager.MsDSPortLDAP); - string fullHostName = hostname; + int port = (int)PropertyManager.GetPropertyValue(context, tmp, PropertyManager.MsDSPortLDAP)!; + string fullHostName = hostname!; if (port != 389) { fullHostName = hostname + ":" + port; @@ -398,7 +400,7 @@ public DirectoryServer InterSiteTopologyGenerator } else { - _topologyGenerator = new DomainController(Utils.GetNewDirectoryContext(hostname, DirectoryContextType.DirectoryServer, context), hostname); + _topologyGenerator = new DomainController(Utils.GetNewDirectoryContext(hostname, DirectoryContextType.DirectoryServer, context), hostname!); } } } @@ -438,7 +440,7 @@ public ActiveDirectorySiteOptions Options { if (NTDSSiteEntry.Properties.Contains("options")) { - return (ActiveDirectorySiteOptions)NTDSSiteEntry.Properties["options"][0]; + return (ActiveDirectorySiteOptions)NTDSSiteEntry.Properties["options"][0]!; } else return ActiveDirectorySiteOptions.None; @@ -472,7 +474,7 @@ public ActiveDirectorySiteOptions Options } } - public string Location + public string? Location { get { @@ -483,7 +485,7 @@ public string Location { if (cachedEntry.Properties.Contains("location")) { - return (string)cachedEntry.Properties["location"][0]; + return (string)cachedEntry.Properties["location"][0]!; } else return null; @@ -581,14 +583,14 @@ public DirectoryServerCollection PreferredRpcBridgeheadServers } } - public ActiveDirectorySchedule IntraSiteReplicationSchedule + public ActiveDirectorySchedule? IntraSiteReplicationSchedule { get { if (_disposed) throw new ObjectDisposedException(GetType().Name); - ActiveDirectorySchedule schedule = null; + ActiveDirectorySchedule? schedule = null; if (existing) { @@ -597,7 +599,7 @@ public ActiveDirectorySchedule IntraSiteReplicationSchedule { if (NTDSSiteEntry.Properties.Contains("schedule")) { - byte[] tmpSchedule = (byte[])NTDSSiteEntry.Properties["schedule"][0]; + byte[] tmpSchedule = (byte[])NTDSSiteEntry.Properties["schedule"][0]!; Debug.Assert(tmpSchedule != null && tmpSchedule.Length == 188); schedule = new ActiveDirectorySchedule(); schedule.SetUnmanagedSchedule(tmpSchedule); @@ -686,7 +688,7 @@ private DirectoryEntry NTDSSiteEntry { if (_ntdsEntry == null) { - DirectoryEntry tmp = DirectoryEntryManager.GetDirectoryEntry(context, "CN=NTDS Site Settings," + (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)); + DirectoryEntry tmp = DirectoryEntryManager.GetDirectoryEntry(context, "CN=NTDS Site Settings," + (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!); try { tmp.RefreshCache(); @@ -722,7 +724,7 @@ public void Save() { try { - ((DirectoryEntry)e.Value).CommitChanges(); + ((DirectoryEntry)e.Value!).CommitChanges(); } catch (COMException exception) { @@ -737,11 +739,11 @@ public void Save() _subnetRetrieved = false; // need to throw better exception for ADAM since its SMTP transport is not available - foreach (DictionaryEntry e in _SMTPBridgeheadServers.changeList) + foreach (DictionaryEntry e in _SMTPBridgeheadServers.changeList!) { try { - ((DirectoryEntry)e.Value).CommitChanges(); + ((DirectoryEntry)e.Value!).CommitChanges(); } catch (COMException exception) { @@ -758,11 +760,11 @@ public void Save() _SMTPBridgeheadServers.changeList.Clear(); _SMTPBridgeRetrieved = false; - foreach (DictionaryEntry e in _RPCBridgeheadServers.changeList) + foreach (DictionaryEntry e in _RPCBridgeheadServers.changeList!) { try { - ((DirectoryEntry)e.Value).CommitChanges(); + ((DirectoryEntry)e.Value!).CommitChanges(); } catch (COMException exception) { @@ -782,7 +784,7 @@ public void Save() { try { - DirectoryServer server = InterSiteTopologyGenerator; + DirectoryServer server = InterSiteTopologyGenerator!; string ntdsaName = (server is DomainController) ? ((DomainController)server).NtdsaObjectName : ((AdamInstance)server).NtdsaObjectName; NTDSSiteEntry.Properties["interSiteTopologyGenerator"].Value = ntdsaName; } @@ -802,7 +804,7 @@ public void Save() // create nTDSSiteSettings object DirectoryEntry tmpEntry = cachedEntry.Children.Add("CN=NTDS Site Settings", "nTDSSiteSettings"); //set properties on the Site NTDS settings object - DirectoryServer replica = InterSiteTopologyGenerator; + DirectoryServer? replica = InterSiteTopologyGenerator; if (replica != null) { string ntdsaName = (replica is DomainController) ? ((DomainController)replica).NtdsaObjectName : ((AdamInstance)replica).NtdsaObjectName; @@ -889,7 +891,7 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() // get destination bridgehead servers // first go to the servers container under the current site and then do a search to get the all server objects. - string serverContainer = "CN=Servers," + (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName); + string serverContainer = "CN=Servers," + (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!; DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, serverContainer); try @@ -901,7 +903,7 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() SearchScope.Subtree, true, /* need paged search */ true /* need cached result as we need to go back to the first record */); - SearchResultCollection conResults = null; + SearchResultCollection? conResults = null; try { conResults = adSearcher.FindAll(); @@ -916,19 +918,19 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() // find out whether fromServer indicates replicating from a server in another site. foreach (SearchResult r in conResults) { - string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory); + string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory)!; if (Utils.Compare(objectCategoryValue, 0, ocValue.Length, ocValue, 0, ocValue.Length) == 0) { - hostNameTable.Add((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DnsHostName)); + hostNameTable.Add((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName)!, (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DnsHostName)!); } } foreach (SearchResult r in conResults) { - string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory); + string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.ObjectCategory)!; if (Utils.Compare(objectCategoryValue, 0, ocValue.Length, ocValue, 0, ocValue.Length) != 0) { - string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer); + string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer)!; // escaping manipulation string fromSite = Utils.GetPartialDN(fromServer, 3); @@ -937,17 +939,17 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() Debug.Assert(fromSite != null && Utils.Compare(fromSite, 0, 3, "CN=", 0, 3) == 0); fromSite = fromSite.Substring(3); - string serverObjectName = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), 2); + string serverObjectName = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName)!, 2); // don't know whether it is a bridgehead server yet. if (!bridgeHeadTable.Contains(serverObjectName)) { - string hostName = (string)hostNameTable[serverObjectName]; + string hostName = (string)hostNameTable[serverObjectName]!; // add if not yet done if (!nonBridgHeadTable.Contains(serverObjectName)) nonBridgHeadTable.Add(serverObjectName, hostName); // check whether from different site - if (Utils.Compare((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn), fromSite) != 0) + if (Utils.Compare((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn)!, fromSite) != 0) { // the server is a bridgehead server bridgeHeadTable.Add(serverObjectName, hostName); @@ -990,7 +992,7 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() "(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)" + str.ToString() + ")", new string[] { "fromServer", "distinguishedName" }, SearchScope.Subtree); - SearchResultCollection conResults = null; + SearchResultCollection? conResults = null; try { conResults = adSearcher.FindAll(); @@ -1004,12 +1006,12 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() { foreach (SearchResult r in conResults) { - string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer); + string fromServer = (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.FromServer)!; string serverObject = fromServer.Substring(17); if (nonBridgHeadTable.Contains(serverObject)) { - string otherSite = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName), 4); + string otherSite = Utils.GetPartialDN((string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.DistinguishedName)!, 4); // escaping manipulation pathCracker.Set(otherSite, NativeComInterfaces.ADS_SETTYPE_DN); otherSite = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF); @@ -1017,9 +1019,9 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() otherSite = otherSite.Substring(3); // check whether from different sites - if (Utils.Compare(otherSite, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn)) != 0) + if (Utils.Compare(otherSite, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.Cn)!) != 0) { - string val = (string)nonBridgHeadTable[serverObject]; + string val = (string)nonBridgHeadTable[serverObject]!; nonBridgHeadTable.Remove(serverObject); bridgeHeadTable.Add(serverObject, val); } @@ -1033,16 +1035,16 @@ private ReadOnlyDirectoryServerCollection GetBridgeheadServers() } } - DirectoryEntry ADAMEntry = null; + DirectoryEntry? ADAMEntry = null; foreach (DictionaryEntry e in bridgeHeadTable) { - DirectoryServer replica = null; - string host = (string)e.Value; + DirectoryServer? replica = null; + string host = (string)e.Value!; // construct directoryreplica if (IsADAM) { ADAMEntry = DirectoryEntryManager.GetDirectoryEntry(context, "CN=NTDS Settings," + e.Key); - int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP); + int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP)!; string fullhost = host; if (port != 389) { @@ -1130,16 +1132,16 @@ private void GetSubnets() { // performs a search to find out the subnets that belong to this site DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string subnetContainer = "CN=Subnets,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, subnetContainer); ADSearcher adSearcher = new ADSearcher(de, - "(&(objectClass=subnet)(objectCategory=subnet)(siteObject=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))", + "(&(objectClass=subnet)(objectCategory=subnet)(siteObject=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!) + "))", new string[] { "cn", "location" }, SearchScope.OneLevel ); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -1152,10 +1154,10 @@ private void GetSubnets() try { - string subnetName = null; + string? subnetName = null; foreach (SearchResult result in results) { - subnetName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn); + subnetName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn)!; ActiveDirectorySubnet subnet = new ActiveDirectorySubnet(context, subnetName, null, true); // set the cached entry subnet.cachedEntry = result.GetDirectoryEntry(); @@ -1175,14 +1177,14 @@ private void GetSubnets() private void GetAdjacentSites() { DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)de.Properties["configurationNamingContext"][0]; + string config = (string)de.Properties["configurationNamingContext"][0]!; string transportContainer = "CN=Inter-Site Transports,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, transportContainer); ADSearcher adSearcher = new ADSearcher(de, - "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))", + "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!) + "))", new string[] { "cn", "distinguishedName" }, SearchScope.Subtree); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -1195,13 +1197,13 @@ private void GetAdjacentSites() try { - ActiveDirectorySiteLink link = null; + ActiveDirectorySiteLink? link = null; foreach (SearchResult result in results) { - string dn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName); - string linkName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn); - string transportName = (string)Utils.GetDNComponents(dn)[1].Value; + string dn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName)!; + string linkName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn)!; + string transportName = (string)Utils.GetDNComponents(dn)[1].Value!; ActiveDirectoryTransportType transportType; if (string.Equals(transportName, "IP", StringComparison.OrdinalIgnoreCase)) transportType = ActiveDirectoryTransportType.Rpc; @@ -1229,7 +1231,7 @@ private void GetAdjacentSites() } finally { - link.Dispose(); + link!.Dispose(); } } } @@ -1243,14 +1245,14 @@ private void GetAdjacentSites() private void GetLinks() { DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string transportContainer = "CN=Inter-Site Transports,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, transportContainer); ADSearcher adSearcher = new ADSearcher(de, - "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))", + "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!) + "))", new string[] { "cn", "distinguishedName" }, SearchScope.Subtree); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -1267,9 +1269,9 @@ private void GetLinks() { // construct the sitelinks at the same time DirectoryEntry connectionEntry = result.GetDirectoryEntry(); - string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn); - string transport = Utils.GetDNComponents((string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName))[1].Value; - ActiveDirectorySiteLink link = null; + string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn)!; + string transport = Utils.GetDNComponents((string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName)!)[1].Value!; + ActiveDirectorySiteLink? link = null; if (string.Equals(transport, "IP", StringComparison.OrdinalIgnoreCase)) link = new ActiveDirectorySiteLink(context, cn, ActiveDirectoryTransportType.Rpc, true, connectionEntry); else if (string.Equals(transport, "SMTP", StringComparison.OrdinalIgnoreCase)) @@ -1296,7 +1298,7 @@ private void GetDomains() // for ADAM, there is no concept of domain, we just return empty collection which is good enough if (!IsADAM) { - string serverName = cachedEntry.Options.GetCurrentServerName(); + string serverName = cachedEntry.Options!.GetCurrentServerName(); DomainController dc = DomainController.GetDomainController(Utils.GetNewDirectoryContext(serverName, DirectoryContextType.DirectoryServer, context)); IntPtr handle = dc.Handle; @@ -1311,7 +1313,7 @@ private void GetDomains() } UnsafeNativeMethods.DsListDomainsInSiteW dsListDomainsInSiteW = (UnsafeNativeMethods.DsListDomainsInSiteW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsListDomainsInSiteW)); - int result = dsListDomainsInSiteW(handle, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName), ref info); + int result = dsListDomainsInSiteW(handle, (string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)!, ref info); if (result != 0) throw ExceptionHelper.GetExceptionFromErrorCode(result, serverName); @@ -1332,7 +1334,7 @@ private void GetDomains() Marshal.PtrToStructure(tmpPtr, nameResult); if (nameResult.status == DS_NAME_ERROR.DS_NAME_NO_ERROR || nameResult.status == DS_NAME_ERROR.DS_NAME_ERROR_DOMAIN_ONLY) { - string domainName = Marshal.PtrToStringUni(nameResult.pName); + string? domainName = Marshal.PtrToStringUni(nameResult.pName); if (domainName != null && domainName.Length > 0) { string d = Utils.GetDnsNameFromDN(domainName); @@ -1364,7 +1366,7 @@ private void GetServers() "(&(objectClass=server)(objectCategory=server))", new string[] { "dNSHostName" }, SearchScope.Subtree); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { results = adSearcher.FindAll(); @@ -1378,10 +1380,10 @@ private void GetServers() { foreach (SearchResult result in results) { - string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName); + string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName)!; DirectoryEntry de = result.GetDirectoryEntry(); - DirectoryEntry child = null; - DirectoryServer replica = null; + DirectoryEntry? child = null; + DirectoryServer? replica = null; // make sure that the server is not demoted try { @@ -1398,7 +1400,7 @@ private void GetServers() } if (IsADAM) { - int port = (int)PropertyManager.GetPropertyValue(context, child, PropertyManager.MsDSPortLDAP); + int port = (int)PropertyManager.GetPropertyValue(context, child, PropertyManager.MsDSPortLDAP)!; string fullHostName = hostName; if (port != 389) { @@ -1421,7 +1423,7 @@ private void GetServers() private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transport) { string serverContainerDN = "CN=Servers," + PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName); - string transportDN = null; + string? transportDN = null; if (transport == ActiveDirectoryTransportType.Smtp) transportDN = "CN=SMTP,CN=Inter-Site Transports," + _siteDN; else @@ -1432,7 +1434,7 @@ private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transpor "(&(objectClass=server)(objectCategory=Server)(bridgeheadTransportList=" + Utils.GetEscapedFilterValue(transportDN) + "))", new string[] { "dNSHostName", "distinguishedName" }, SearchScope.OneLevel); - SearchResultCollection results = null; + SearchResultCollection? results = null; try { @@ -1445,12 +1447,12 @@ private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transpor try { - DirectoryEntry ADAMEntry = null; + DirectoryEntry? ADAMEntry = null; foreach (SearchResult result in results) { - string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName); + string hostName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DnsHostName)!; DirectoryEntry resultEntry = result.GetDirectoryEntry(); - DirectoryServer replica = null; + DirectoryServer? replica = null; try { @@ -1463,7 +1465,7 @@ private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transpor if (IsADAM) { - int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP); + int port = (int)PropertyManager.GetPropertyValue(context, ADAMEntry, PropertyManager.MsDSPortLDAP)!; string fullHostName = hostName; if (port != 389) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs index 702e3e537bc11..e8723e6a3f15a 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs @@ -8,21 +8,21 @@ namespace System.DirectoryServices.ActiveDirectory { public class ActiveDirectorySiteCollection : CollectionBase { - internal DirectoryEntry de; + internal DirectoryEntry? de; internal bool initialized; - internal DirectoryContext context; + internal DirectoryContext? context; internal ActiveDirectorySiteCollection() { } internal ActiveDirectorySiteCollection(ArrayList sites) { for (int i = 0; i < sites.Count; i++) - Add((ActiveDirectorySite)sites[i]); + Add((ActiveDirectorySite)sites[i]!); } public ActiveDirectorySite this[int index] { - get => (ActiveDirectorySite)InnerList[index]; + get => (ActiveDirectorySite)InnerList[index]!; set { ActiveDirectorySite site = (ActiveDirectorySite)value; @@ -81,12 +81,12 @@ public bool Contains(ActiveDirectorySite site) if (!site.existing) throw new InvalidOperationException(SR.Format(SR.SiteNotCommitted, site.Name)); - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -109,12 +109,12 @@ public int IndexOf(ActiveDirectorySite site) if (!site.existing) throw new InvalidOperationException(SR.Format(SR.SiteNotCommitted, site.Name)); - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -146,12 +146,12 @@ public void Remove(ActiveDirectorySite site) if (!site.existing) throw new InvalidOperationException(SR.Format(SR.SiteNotCommitted, site.Name)); - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -171,7 +171,7 @@ protected override void OnClearComplete() { try { - if (de.Properties.Contains("siteList")) + if (de!.Properties.Contains("siteList")) de.Properties["siteList"].Clear(); } catch (COMException e) @@ -181,15 +181,15 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (initialized) { - ActiveDirectorySite site = (ActiveDirectorySite)value; - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite site = (ActiveDirectorySite)value!; + string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteList"].Add(dn); + de!.Properties["siteList"].Add(dn); } catch (COMException e) { @@ -198,13 +198,13 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { - ActiveDirectorySite site = (ActiveDirectorySite)value; - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite site = (ActiveDirectorySite)value!; + string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteList"].Remove(dn); + de!.Properties["siteList"].Remove(dn); } catch (COMException e) { @@ -212,13 +212,13 @@ protected override void OnRemoveComplete(int index, object value) } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { - ActiveDirectorySite newsite = (ActiveDirectorySite)newValue; - string newdn = (string)PropertyManager.GetPropertyValue(newsite.context, newsite.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySite newsite = (ActiveDirectorySite)newValue!; + string newdn = (string)PropertyManager.GetPropertyValue(newsite.context, newsite.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteList"][index] = newdn; + de!.Properties["siteList"][index] = newdn; } catch (COMException e) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLink.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLink.cs index 71a82836c57d5..09dfc687a963c 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLink.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLink.cs @@ -33,7 +33,7 @@ public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, Ac { } - public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule) + public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule? schedule) { ValidateArgument(context, siteLinkName, transport); @@ -50,9 +50,9 @@ public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, Ac try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; - string parentDN = null; + string parentDN; if (transport == ActiveDirectoryTransportType.Rpc) parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config; else @@ -127,7 +127,7 @@ public static ActiveDirectorySiteLink FindByName(DirectoryContext context, strin try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string containerDN = "CN=Inter-Site Transports,CN=Sites," + config; if (transport == ActiveDirectoryTransportType.Rpc) containerDN = "CN=IP," + containerDN; @@ -154,7 +154,7 @@ public static ActiveDirectorySiteLink FindByName(DirectoryContext context, strin false, /* don't need paged search */ false /* don't need to cache result */ ); - SearchResult srchResult = adSearcher.FindOne(); + SearchResult? srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such sitelink object @@ -251,7 +251,7 @@ public int Cost try { if (cachedEntry.Properties.Contains("cost")) - return (int)cachedEntry.Properties["cost"][0]; + return (int)cachedEntry.Properties["cost"][0]!; } catch (COMException e) { @@ -291,7 +291,7 @@ public TimeSpan ReplicationInterval { if (cachedEntry.Properties.Contains("replInterval")) { - int tmpValue = (int)cachedEntry.Properties["replInterval"][0]; + int tmpValue = (int)cachedEntry.Properties["replInterval"][0]!; return new TimeSpan(0, tmpValue, 0); } } @@ -337,7 +337,7 @@ public bool ReciprocalReplicationEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedEntry.Properties["options"]; @@ -349,7 +349,7 @@ public bool ReciprocalReplicationEnabled if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } //NTDSSITELINK_OPT_TWOWAY_SYNC ( 1 << 1 ) force sync in opposite direction at end of sync @@ -364,7 +364,7 @@ public bool ReciprocalReplicationEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { @@ -372,7 +372,7 @@ public bool ReciprocalReplicationEnabled if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } //NTDSSITELINK_OPT_TWOWAY_SYNC ( 1 << 1 ) force sync in opposite direction at end of sync @@ -401,7 +401,7 @@ public bool NotificationEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedEntry.Properties["options"]; @@ -413,7 +413,7 @@ public bool NotificationEnabled if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } // NTDSSITELINK_OPT_USE_NOTIFY ( 1 << 0 ) Use notification on this link @@ -428,14 +428,14 @@ public bool NotificationEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedEntry.Properties["options"]; if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } // NTDSSITELINK_OPT_USE_NOTIFY ( 1 << 0 ) Use notification on this link @@ -465,7 +465,7 @@ public bool DataCompressionEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { @@ -478,7 +478,7 @@ public bool DataCompressionEnabled if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } //NTDSSITELINK_OPT_DISABLE_COMPRESSION ( 1 << 2 ) @@ -495,14 +495,14 @@ public bool DataCompressionEnabled throw new ObjectDisposedException(GetType().Name); int options = 0; - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedEntry.Properties["options"]; if (propValue.Count != 0) { - options = (int)propValue[0]; + options = (int)propValue[0]!; } //NTDSSITELINK_OPT_DISABLE_COMPRESSION ( 1 << 2 ) @@ -525,19 +525,19 @@ public bool DataCompressionEnabled } } - public ActiveDirectorySchedule InterSiteReplicationSchedule + public ActiveDirectorySchedule? InterSiteReplicationSchedule { get { if (_disposed) throw new ObjectDisposedException(GetType().Name); - ActiveDirectorySchedule schedule = null; + ActiveDirectorySchedule? schedule = null; try { if (cachedEntry.Properties.Contains("schedule")) { - byte[] tmpSchedule = (byte[])cachedEntry.Properties["schedule"][0]; + byte[] tmpSchedule = (byte[])cachedEntry.Properties["schedule"][0]!; Debug.Assert(tmpSchedule != null && tmpSchedule.Length == 188); schedule = new ActiveDirectorySchedule(); schedule.SetUnmanagedSchedule(tmpSchedule); @@ -694,7 +694,7 @@ private static void ValidateArgument(DirectoryContext context, string siteLinkNa private void GetSites() { - NativeComInterfaces.IAdsPathname pathCracker = null; + NativeComInterfaces.IAdsPathname? pathCracker = null; pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname(); ArrayList propertyList = new ArrayList(); // need to turn off the escaping for name @@ -703,7 +703,7 @@ private void GetSites() propertyList.Add(propertyName); Hashtable values = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base); - ArrayList siteLists = (ArrayList)values[propertyName.ToLowerInvariant()]; + ArrayList? siteLists = (ArrayList?)values[propertyName.ToLowerInvariant()]; // somehow no site list if (siteLists == null) @@ -711,7 +711,7 @@ private void GetSites() for (int i = 0; i < siteLists.Count; i++) { - string dn = (string)siteLists[i]; + string dn = (string)siteLists[i]!; // escaping manipulation pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkBridge.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkBridge.cs index 41b64799d9085..672a5aab39aa8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkBridge.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkBridge.cs @@ -17,7 +17,7 @@ public class ActiveDirectorySiteLinkBridge : IDisposable private bool _disposed; private bool _existing; - internal DirectoryEntry cachedEntry; + internal DirectoryEntry? cachedEntry; private readonly ActiveDirectorySiteLinkCollection _links = new ActiveDirectorySiteLinkCollection(); private bool _linksRetrieved; @@ -42,8 +42,8 @@ public ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); - string parentDN = null; + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; + string parentDN; if (transport == ActiveDirectoryTransportType.Rpc) parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config; else @@ -114,7 +114,7 @@ public static ActiveDirectorySiteLinkBridge FindByName(DirectoryContext context, try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string containerDN = "CN=Inter-Site Transports,CN=Sites," + config; if (transport == ActiveDirectoryTransportType.Rpc) containerDN = "CN=IP," + containerDN; @@ -140,7 +140,7 @@ public static ActiveDirectorySiteLinkBridge FindByName(DirectoryContext context, SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); - SearchResult srchResult = adSearcher.FindOne(); + SearchResult? srchResult = adSearcher.FindOne(); if (srchResult == null) { @@ -236,7 +236,7 @@ public void Save() try { - cachedEntry.CommitChanges(); + cachedEntry!.CommitChanges(); } catch (COMException e) { @@ -267,7 +267,7 @@ public void Delete() { try { - cachedEntry.Parent.Children.Remove(cachedEntry); + cachedEntry!.Parent.Children.Remove(cachedEntry); } catch (COMException e) { @@ -295,7 +295,7 @@ public DirectoryEntry GetDirectoryEntry() } else { - return DirectoryEntryManager.GetDirectoryEntryInternal(context, cachedEntry.Path); + return DirectoryEntryManager.GetDirectoryEntryInternal(context, cachedEntry!.Path); } } @@ -351,15 +351,15 @@ private static void ValidateArgument(DirectoryContext context, string bridgeName private void GetLinks() { ArrayList propertyList = new ArrayList(); - NativeComInterfaces.IAdsPathname pathCracker = null; + NativeComInterfaces.IAdsPathname? pathCracker = null; pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname(); // need to turn off the escaping for name pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX; string propertyName = "siteLinkList"; propertyList.Add(propertyName); - Hashtable values = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base); - ArrayList siteLinkLists = (ArrayList)values[propertyName.ToLowerInvariant()]; + Hashtable values = Utils.GetValuesWithRangeRetrieval(cachedEntry!, "(objectClass=*)", propertyList, SearchScope.Base); + ArrayList siteLinkLists = (ArrayList)values[propertyName.ToLowerInvariant()]!; // somehow no site link list if (siteLinkLists == null) @@ -368,7 +368,7 @@ private void GetLinks() // construct the site link object for (int i = 0; i < siteLinkLists.Count; i++) { - string dn = (string)siteLinkLists[i]; + string dn = (string)siteLinkLists[i]!; // escaping manipulation pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN); string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs index 4db6e1ea2230f..e280aa2f738d3 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs @@ -8,15 +8,15 @@ namespace System.DirectoryServices.ActiveDirectory { public class ActiveDirectorySiteLinkCollection : CollectionBase { - internal DirectoryEntry de; + internal DirectoryEntry? de; internal bool initialized; - internal DirectoryContext context; + internal DirectoryContext? context; internal ActiveDirectorySiteLinkCollection() { } public ActiveDirectorySiteLink this[int index] { - get => (ActiveDirectorySiteLink)InnerList[index]; + get => (ActiveDirectorySiteLink)InnerList[index]!; set { ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value; @@ -75,12 +75,12 @@ public bool Contains(ActiveDirectorySiteLink link) if (!link.existing) throw new InvalidOperationException(SR.Format(SR.SiteLinkNotCommitted, link.Name)); - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -103,12 +103,12 @@ public int IndexOf(ActiveDirectorySiteLink link) if (!link.existing) throw new InvalidOperationException(SR.Format(SR.SiteLinkNotCommitted, link.Name)); - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -140,12 +140,12 @@ public void Remove(ActiveDirectorySiteLink link) if (!link.existing) throw new InvalidOperationException(SR.Format(SR.SiteLinkNotCommitted, link.Name)); - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -165,7 +165,7 @@ protected override void OnClearComplete() { try { - if (de.Properties.Contains("siteLinkList")) + if (de!.Properties.Contains("siteLinkList")) de.Properties["siteLinkList"].Clear(); } catch (COMException e) @@ -175,15 +175,15 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (initialized) { - ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value; - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value!; + string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteLinkList"].Add(dn); + de!.Properties["siteLinkList"].Add(dn); } catch (COMException e) { @@ -192,13 +192,13 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { - ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value; - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value!; + string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteLinkList"].Remove(dn); + de!.Properties["siteLinkList"].Remove(dn); } catch (COMException e) { @@ -206,13 +206,13 @@ protected override void OnRemoveComplete(int index, object value) } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { - ActiveDirectorySiteLink newLink = (ActiveDirectorySiteLink)newValue; - string newdn = (string)PropertyManager.GetPropertyValue(newLink.context, newLink.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink newLink = (ActiveDirectorySiteLink)newValue!; + string newdn = (string)PropertyManager.GetPropertyValue(newLink.context, newLink.cachedEntry, PropertyManager.DistinguishedName)!; try { - de.Properties["siteLinkList"][index] = newdn; + de!.Properties["siteLinkList"][index] = newdn; } catch (COMException e) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnet.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnet.cs index 7e7f5df935baf..2309c82cb9123 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnet.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnet.cs @@ -8,13 +8,13 @@ namespace System.DirectoryServices.ActiveDirectory { public class ActiveDirectorySubnet : IDisposable { - private ActiveDirectorySite _site; + private ActiveDirectorySite? _site; private readonly string _name; internal readonly DirectoryContext context; private bool _disposed; internal bool existing; - internal DirectoryEntry cachedEntry; + internal DirectoryEntry cachedEntry = null!; public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName) { @@ -29,7 +29,7 @@ public static ActiveDirectorySubnet FindByName(DirectoryContext context, string try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string subnetdn = "CN=Subnets,CN=Sites," + config; de = DirectoryEntryManager.GetDirectoryEntry(context, subnetdn); } @@ -51,7 +51,7 @@ public static ActiveDirectorySubnet FindByName(DirectoryContext context, string SearchScope.OneLevel, false, /* don't need paged search */ false /* don't need to cache result */); - SearchResult srchResult = adSearcher.FindOne(); + SearchResult? srchResult = adSearcher.FindOne(); if (srchResult == null) { // no such subnet object @@ -60,7 +60,7 @@ public static ActiveDirectorySubnet FindByName(DirectoryContext context, string } else { - string siteName = null; + string? siteName = null; DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry(); // try to get the site that this subnet lives in if (connectionEntry.Properties.Contains("siteObject")) @@ -69,7 +69,7 @@ public static ActiveDirectorySubnet FindByName(DirectoryContext context, string // need to turn off the escaping for name pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX; - string tmp = (string)connectionEntry.Properties["siteObject"][0]; + string tmp = (string)connectionEntry.Properties["siteObject"][0]!; // escaping manipulation pathCracker.Set(tmp, NativeComInterfaces.ADS_SETTYPE_DN); string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF); @@ -78,7 +78,7 @@ public static ActiveDirectorySubnet FindByName(DirectoryContext context, string } // it is an existing subnet object - ActiveDirectorySubnet subnet = null; + ActiveDirectorySubnet? subnet = null; if (siteName == null) subnet = new ActiveDirectorySubnet(context, subnetName, null, true); else @@ -118,12 +118,12 @@ public ActiveDirectorySubnet(DirectoryContext context, string subnetName) _name = subnetName; // bind to the rootdse to get the configurationnamingcontext - DirectoryEntry de = null; + DirectoryEntry? de = null; try { de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext); + string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext)!; string subnetn = "CN=Subnets,CN=Sites," + config; // bind to the subnet container de = DirectoryEntryManager.GetDirectoryEntry(context, subnetn); @@ -167,7 +167,7 @@ public ActiveDirectorySubnet(DirectoryContext context, string subnetName, string } } - internal ActiveDirectorySubnet(DirectoryContext context, string subnetName, string siteName, bool existing) + internal ActiveDirectorySubnet(DirectoryContext context, string subnetName, string? siteName, bool existing) { Debug.Assert(existing == true); @@ -200,7 +200,7 @@ public string Name } } - public ActiveDirectorySite Site + public ActiveDirectorySite? Site { get { @@ -225,7 +225,7 @@ public ActiveDirectorySite Site } } - public string Location + public string? Location { get { @@ -235,7 +235,7 @@ public string Location try { if (cachedEntry.Properties.Contains("location")) - return (string)cachedEntry.Properties["location"][0]; + return (string)cachedEntry.Properties["location"][0]!; else return null; } @@ -295,7 +295,7 @@ public void Save() else { if (Site != null) - cachedEntry.Properties["siteObject"].Add(_site.cachedEntry.Properties["distinguishedName"][0]); + cachedEntry.Properties["siteObject"].Add(_site!.cachedEntry.Properties["distinguishedName"][0]); cachedEntry.CommitChanges(); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs index c2c7217c8c51e..a3432b67fc029 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs @@ -26,7 +26,7 @@ internal ActiveDirectorySubnetCollection(DirectoryContext context, string siteDN public ActiveDirectorySubnet this[int index] { - get => (ActiveDirectorySubnet)InnerList[index]; + get => (ActiveDirectorySubnet)InnerList[index]!; set { ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; @@ -93,12 +93,12 @@ public bool Contains(ActiveDirectorySubnet subnet) if (!subnet.existing) throw new InvalidOperationException(SR.Format(SR.SubnetNotCommitted, subnet.Name)); - string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -121,12 +121,12 @@ public int IndexOf(ActiveDirectorySubnet subnet) if (!subnet.existing) throw new InvalidOperationException(SR.Format(SR.SubnetNotCommitted, subnet.Name)); - string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -158,12 +158,12 @@ public void Remove(ActiveDirectorySubnet subnet) if (!subnet.existing) throw new InvalidOperationException(SR.Format(SR.SubnetNotCommitted, subnet.Name)); - string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); + string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySubnet tmp = (ActiveDirectorySubnet)InnerList[i]!; + string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName)!; if (Utils.Compare(tmpDn, dn) == 0) { @@ -195,23 +195,23 @@ protected override void OnClearComplete() { for (int i = 0; i < _copyList.Count; i++) { - OnRemoveComplete(i, _copyList[i]); + OnRemoveComplete(i, _copyList[i]!); } } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (initialized) { - ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; - string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value!; + string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; try { if (changeList.Contains(dn)) { - ((DirectoryEntry)changeList[dn]).Properties["siteObject"].Value = _siteDN; + ((DirectoryEntry)changeList[dn]!).Properties["siteObject"].Value = _siteDN; } else { @@ -227,16 +227,16 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { - ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; - string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value!; + string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; try { if (changeList.Contains(dn)) { - ((DirectoryEntry)changeList[dn]).Properties["siteObject"].Clear(); + ((DirectoryEntry)changeList[dn]!).Properties["siteObject"].Clear(); } else { @@ -251,7 +251,7 @@ protected override void OnRemoveComplete(int index, object value) } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { OnRemoveComplete(index, oldValue); OnInsertComplete(index, newValue); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySyntax.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySyntax.cs index a393c306c9a6e..6d31c04bb8aba 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySyntax.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySyntax.cs @@ -62,9 +62,9 @@ internal class Syntax { public readonly string attributeSyntax; public readonly int oMSyntax; - public readonly OMObjectClass oMObjectClass; + public readonly OMObjectClass? oMObjectClass; - public Syntax(string attributeSyntax, int oMSyntax, OMObjectClass oMObjectClass) + public Syntax(string attributeSyntax, int oMSyntax, OMObjectClass? oMObjectClass) { this.attributeSyntax = attributeSyntax; this.oMSyntax = oMSyntax; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs index 7243275e5c934..a58745d718986 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices.ActiveDirectory { @@ -26,12 +27,12 @@ public class ApplicationPartition : ActiveDirectoryPartition private bool _disposed; private ApplicationPartitionType _appType = (ApplicationPartitionType)(-1); private bool _committed = true; - private DirectoryEntry _domainDNSEntry; - private DirectoryEntry _crossRefEntry; - private string _dnsName; - private DirectoryServerCollection _cachedDirectoryServers; + private DirectoryEntry? _domainDNSEntry; + private DirectoryEntry? _crossRefEntry; + private string? _dnsName; + private DirectoryServerCollection? _cachedDirectoryServers; private bool _securityRefDomainModified; - private string _securityRefDomain; + private string? _securityRefDomain; #region constructors // Public Constructors @@ -54,7 +55,7 @@ public ApplicationPartition(DirectoryContext context, string distinguishedName, } // Internal Constructors - internal ApplicationPartition(DirectoryContext context, string distinguishedName, string dnsName, ApplicationPartitionType appType, DirectoryEntryManager directoryEntryMgr) + internal ApplicationPartition(DirectoryContext context, string distinguishedName, string? dnsName, ApplicationPartitionType appType, DirectoryEntryManager directoryEntryMgr) : base(context, distinguishedName) { this.directoryEntryMgr = directoryEntryMgr; @@ -88,7 +89,7 @@ protected override void Dispose(bool disposing) if (_domainDNSEntry != null) { _domainDNSEntry.Dispose(); - _domainDNSEntry = null; + _domainDNSEntry = null!; } _disposed = true; @@ -127,9 +128,9 @@ public static ApplicationPartition GetApplicationPartition(DirectoryContext cont context = new DirectoryContext(context); // bind to the application partition head (this will verify credentials) - string distinguishedName = Utils.GetDNFromDnsName(context.Name); + string distinguishedName = Utils.GetDNFromDnsName(context.Name!); DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); - DirectoryEntry appNCHead = null; + DirectoryEntry? appNCHead = null; try { @@ -156,9 +157,9 @@ public static ApplicationPartition GetApplicationPartition(DirectoryContext cont public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName) { - ApplicationPartition partition = null; - DirectoryEntryManager directoryEntryMgr = null; - DirectoryContext appNCContext = null; + ApplicationPartition? partition = null; + DirectoryEntryManager? directoryEntryMgr = null; + DirectoryContext? appNCContext = null; // check that the argument is not null if (context == null) @@ -194,7 +195,7 @@ public static ApplicationPartition FindByName(DirectoryContext context, string d // search in the partitions container of the forest for // crossRef objects that have their nCName set to the specified distinguishedName directoryEntryMgr = new DirectoryEntryManager(context); - DirectoryEntry partitionsEntry = null; + DirectoryEntry? partitionsEntry = null; try { @@ -235,7 +236,7 @@ public static ApplicationPartition FindByName(DirectoryContext context, string d propertiesToLoad[1] = PropertyManager.NCName; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); - SearchResult res = null; + SearchResult? res = null; try { @@ -264,10 +265,10 @@ public static ApplicationPartition FindByName(DirectoryContext context, string d throw new ActiveDirectoryObjectNotFoundException(SR.AppNCNotFound, typeof(ApplicationPartition), distinguishedName); } - string appNCDnsName = null; + string? appNCDnsName = null; try { - appNCDnsName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? (string)res.Properties[PropertyManager.DnsRoot][0] : null; + appNCDnsName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? (string)res.Properties[PropertyManager.DnsRoot][0]! : null; } catch (COMException e) { @@ -341,14 +342,14 @@ public static ApplicationPartition FindByName(DirectoryContext context, string d appNCContext = Utils.GetNewDirectoryContext(adamInstName, DirectoryContextType.DirectoryServer, context); } } - partition = new ApplicationPartition(appNCContext, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName), appNCDnsName, appType, directoryEntryMgr); + partition = new ApplicationPartition(appNCContext, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName)!, appNCDnsName, appType, directoryEntryMgr); return partition; } public DirectoryServer FindDirectoryServer() { - DirectoryServer directoryServer = null; + DirectoryServer? directoryServer = null; CheckIfDisposed(); @@ -371,7 +372,7 @@ public DirectoryServer FindDirectoryServer() public DirectoryServer FindDirectoryServer(string siteName) { - DirectoryServer directoryServer = null; + DirectoryServer? directoryServer = null; CheckIfDisposed(); @@ -400,7 +401,7 @@ public DirectoryServer FindDirectoryServer(string siteName) public DirectoryServer FindDirectoryServer(bool forceRediscovery) { - DirectoryServer directoryServer = null; + DirectoryServer? directoryServer = null; CheckIfDisposed(); @@ -425,7 +426,7 @@ public DirectoryServer FindDirectoryServer(bool forceRediscovery) public DirectoryServer FindDirectoryServer(string siteName, bool forceRediscovery) { - DirectoryServer directoryServer = null; + DirectoryServer? directoryServer = null; CheckIfDisposed(); @@ -585,7 +586,7 @@ public void Save() { try { - _domainDNSEntry.CommitChanges(); + _domainDNSEntry!.CommitChanges(); } catch (COMException e) { @@ -621,7 +622,7 @@ public void Save() try { - _domainDNSEntry.CommitChanges(); + _domainDNSEntry!.CommitChanges(); } catch (COMException e) { @@ -662,7 +663,7 @@ public void Save() // on DC2, the FSMO, and can only be done if the crossRef on DC2 is enabled) // get the ntdsa name of the server on which the partition is created DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); - string primaryServerNtdsaName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName); + string primaryServerNtdsaName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName)!; // get the DN of the crossRef entry that needs to be replicated to the fsmo role if (_appType == ApplicationPartitionType.ADApplicationPartition) @@ -670,7 +671,7 @@ public void Save() // for AD we may not have the crossRef entry yet GetCrossRefEntry(); } - string crossRefDN = (string)PropertyManager.GetPropertyValue(context, _crossRefEntry, PropertyManager.DistinguishedName); + string crossRefDN = (string)PropertyManager.GetPropertyValue(context, _crossRefEntry!, PropertyManager.DistinguishedName)!; // Now set the operational attribute "replicateSingleObject" on the Rootdse of the fsmo role // to : @@ -699,15 +700,15 @@ public void Save() { if (_cachedDirectoryServers != null) { - _crossRefEntry.Properties[PropertyManager.MsDSNCReplicaLocations].AddRange(_cachedDirectoryServers.GetMultiValuedProperty()); + _crossRefEntry!.Properties[PropertyManager.MsDSNCReplicaLocations].AddRange(_cachedDirectoryServers.GetMultiValuedProperty()); } if (_securityRefDomainModified) { - _crossRefEntry.Properties[PropertyManager.MsDSSDReferenceDomain].Value = _securityRefDomain; + _crossRefEntry!.Properties[PropertyManager.MsDSSDReferenceDomain].Value = _securityRefDomain; } try { - _crossRefEntry.CommitChanges(); + _crossRefEntry!.CommitChanges(); } catch (COMException e) { @@ -783,7 +784,7 @@ public DirectoryServerCollection DirectoryServers } } - public string SecurityReferenceDomain + public string? SecurityReferenceDomain { get { @@ -802,7 +803,7 @@ public string SecurityReferenceDomain { if (_crossRefEntry.Properties[PropertyManager.MsDSSDReferenceDomain].Count > 0) { - return (string)_crossRefEntry.Properties[PropertyManager.MsDSSDReferenceDomain].Value; + return (string?)_crossRefEntry.Properties[PropertyManager.MsDSSDReferenceDomain].Value; } else { @@ -860,7 +861,7 @@ public string SecurityReferenceDomain #endregion public properties #region private methods - private void ValidateApplicationPartitionParameters(DirectoryContext context, string distinguishedName, string objectClass, bool objectClassSpecified) + private void ValidateApplicationPartitionParameters(DirectoryContext context, string distinguishedName, string? objectClass, bool objectClassSpecified) { // validate context if (context == null) @@ -931,11 +932,11 @@ private void ValidateApplicationPartitionParameters(DirectoryContext context, st // (since application partition creation will fail if dns name is not specified) // - string serverDnsName = null; + string? serverDnsName = null; try { DirectoryEntry rootDSEEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); - serverDnsName = (string)PropertyManager.GetPropertyValue(this.context, rootDSEEntry, PropertyManager.DnsHostName); + serverDnsName = (string?)PropertyManager.GetPropertyValue(this.context, rootDSEEntry, PropertyManager.DnsHostName); } catch (COMException e) { @@ -946,6 +947,7 @@ private void ValidateApplicationPartitionParameters(DirectoryContext context, st } } + [MemberNotNull(nameof(_domainDNSEntry))] private void CreateApplicationPartition(string distinguishedName, string objectClass) { if (_appType == ApplicationPartitionType.ADApplicationPartition) @@ -957,8 +959,8 @@ private void CreateApplicationPartition(string distinguishedName, string objectC // 3. Set the instanceType and the description for the application partitin object // - DirectoryEntry tempEntry = null; - DirectoryEntry parent = null; + DirectoryEntry? tempEntry = null; + DirectoryEntry? parent = null; try { @@ -1006,8 +1008,8 @@ private void CreateApplicationPartition(string distinguishedName, string objectC { InitializeCrossRef(distinguishedName); - DirectoryEntry tempEntry = null; - DirectoryEntry parent = null; + DirectoryEntry? tempEntry = null; + DirectoryEntry? parent = null; try { @@ -1047,13 +1049,14 @@ private void CreateApplicationPartition(string distinguishedName, string objectC } } + [MemberNotNull(nameof(_crossRefEntry))] private void InitializeCrossRef(string distinguishedName) { if (_crossRefEntry != null) // already initialized return; - DirectoryEntry partitionsEntry = null; + DirectoryEntry? partitionsEntry = null; try { @@ -1063,12 +1066,12 @@ private void InitializeCrossRef(string distinguishedName) string uniqueName = "CN={" + Guid.NewGuid() + "}"; _crossRefEntry = partitionsEntry.Children.Add(uniqueName, "crossRef"); - string dnsHostName = null; + string? dnsHostName = null; if (_appType == ApplicationPartitionType.ADAMApplicationPartition) { // Bind to rootdse and get the server name DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); - string ntdsaName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName); + string ntdsaName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DsServiceName)!; dnsHostName = Utils.GetAdamHostNameAndPortsFromNTDSA(context, ntdsaName); } else @@ -1133,6 +1136,7 @@ private static ApplicationPartitionType GetApplicationPartitionType(DirectoryCon // we always get the crossEntry bound to the FSMO role // this is so that we do not encounter any replication delay related issues + [MemberNotNull(nameof(_crossRefEntry))] internal DirectoryEntry GetCrossRefEntry() { if (_crossRefEntry != null) @@ -1154,17 +1158,17 @@ internal DirectoryEntry GetCrossRefEntry() internal string GetNamingRoleOwner() { - string namingFsmo = null; + string? namingFsmo = null; DirectoryEntry partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); try { if (_appType == ApplicationPartitionType.ADApplicationPartition) { - namingFsmo = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)); + namingFsmo = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)!); } else { - namingFsmo = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)); + namingFsmo = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)!); } } finally @@ -1174,9 +1178,9 @@ internal string GetNamingRoleOwner() return namingFsmo; } - private DirectoryServer FindDirectoryServerInternal(string siteName, bool forceRediscovery) + private DirectoryServer FindDirectoryServerInternal(string? siteName, bool forceRediscovery) { - DirectoryServer directoryServer = null; + DirectoryServer? directoryServer = null; LocatorOptions flag = 0; int errorCode = 0; DomainControllerInfo domainControllerInfo; @@ -1221,7 +1225,7 @@ private DirectoryServer FindDirectoryServerInternal(string siteName, bool forceR return directoryServer; } - private ReadOnlyDirectoryServerCollection FindAllDirectoryServersInternal(string siteName) + private ReadOnlyDirectoryServerCollection FindAllDirectoryServersInternal(string? siteName) { if (siteName != null && siteName.Length == 0) { @@ -1244,7 +1248,7 @@ private ReadOnlyDirectoryServerCollection FindAllDirectoryServersInternal(string return new ReadOnlyDirectoryServerCollection(dcList); } - private ReadOnlyDirectoryServerCollection FindAllDiscoverableDirectoryServersInternal(string siteName) + private ReadOnlyDirectoryServerCollection FindAllDiscoverableDirectoryServersInternal(string? siteName) { if (siteName != null && siteName.Length == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartitionCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartitionCollection.cs index fc685d9310220..9ce65000e7109 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartitionCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartitionCollection.cs @@ -17,7 +17,7 @@ internal ApplicationPartitionCollection(ArrayList values) } } - public ApplicationPartition this[int index] => (ApplicationPartition)InnerList[index]; + public ApplicationPartition this[int index] => (ApplicationPartition)InnerList[index]!; public bool Contains(ApplicationPartition applicationPartition) { @@ -28,7 +28,7 @@ public bool Contains(ApplicationPartition applicationPartition) for (int i = 0; i < InnerList.Count; i++) { - ApplicationPartition tmp = (ApplicationPartition)InnerList[i]; + ApplicationPartition tmp = (ApplicationPartition)InnerList[i]!; if (Utils.Compare(tmp.Name, applicationPartition.Name) == 0) { return true; @@ -46,7 +46,7 @@ public int IndexOf(ApplicationPartition applicationPartition) for (int i = 0; i < InnerList.Count; i++) { - ApplicationPartition tmp = (ApplicationPartition)InnerList[i]; + ApplicationPartition tmp = (ApplicationPartition)InnerList[i]!; if (Utils.Compare(tmp.Name, applicationPartition.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetaData.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetaData.cs index 7ea6de6e22565..12a76be092e91 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetaData.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetaData.cs @@ -9,9 +9,9 @@ namespace System.DirectoryServices.ActiveDirectory { public class AttributeMetadata { - private readonly string _pszLastOriginatingDsaDN; + private readonly string? _pszLastOriginatingDsaDN; - private string _originatingServerName; + private string? _originatingServerName; private readonly DirectoryServer _server; private readonly Hashtable _nameTable; private readonly bool _advanced; @@ -24,7 +24,7 @@ internal AttributeMetadata(IntPtr info, bool advanced, DirectoryServer server, H Marshal.PtrToStructure(info, attrMetaData); Debug.Assert(attrMetaData != null); - Name = Marshal.PtrToStringUni(attrMetaData.pszAttributeName); + Name = Marshal.PtrToStringUni(attrMetaData.pszAttributeName)!; Version = attrMetaData.dwVersion; long ftimeChangeValue = (long)((uint)attrMetaData.ftimeLastOriginatingChange1 + (((long)attrMetaData.ftimeLastOriginatingChange2) << 32)); LastOriginatingChangeTime = DateTime.FromFileTime(ftimeChangeValue); @@ -39,7 +39,7 @@ internal AttributeMetadata(IntPtr info, bool advanced, DirectoryServer server, H Marshal.PtrToStructure(info, attrMetaData); Debug.Assert(attrMetaData != null); - Name = Marshal.PtrToStringUni(attrMetaData.pszAttributeName); + Name = Marshal.PtrToStringUni(attrMetaData.pszAttributeName)!; Version = attrMetaData.dwVersion; long ftimeChangeValue = (long)((uint)attrMetaData.ftimeLastOriginatingChange1 + (((long)attrMetaData.ftimeLastOriginatingChange2) << 32)); LastOriginatingChangeTime = DateTime.FromFileTime(ftimeChangeValue); @@ -64,7 +64,7 @@ internal AttributeMetadata(IntPtr info, bool advanced, DirectoryServer server, H public long LocalChangeUsn { get; } - public string OriginatingServer + public string? OriginatingServer { get { @@ -73,7 +73,7 @@ public string OriginatingServer // check whether we have got it before if (_nameTable.Contains(LastOriginatingInvocationId)) { - _originatingServerName = (string)_nameTable[LastOriginatingInvocationId]; + _originatingServerName = (string)_nameTable[LastOriginatingInvocationId]!; } // do the translation for downlevel platform or kcc is able to do the name translation else if (!_advanced || (_advanced && _pszLastOriginatingDsaDN != null)) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetadataCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetadataCollection.cs index b6f4fc6085e2d..787e71e402f8c 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetadataCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/AttributeMetadataCollection.cs @@ -9,7 +9,7 @@ public class AttributeMetadataCollection : ReadOnlyCollectionBase { internal AttributeMetadataCollection() { } - public AttributeMetadata this[int index] => (AttributeMetadata)InnerList[index]; + public AttributeMetadata this[int index] => (AttributeMetadata)InnerList[index]!; public bool Contains(AttributeMetadata metadata) { @@ -18,7 +18,7 @@ public bool Contains(AttributeMetadata metadata) for (int i = 0; i < InnerList.Count; i++) { - AttributeMetadata tmp = (AttributeMetadata)InnerList[i]; + AttributeMetadata tmp = (AttributeMetadata)InnerList[i]!; string name = tmp.Name; if (Utils.Compare(name, metadata.Name) == 0) @@ -36,7 +36,7 @@ public int IndexOf(AttributeMetadata metadata) for (int i = 0; i < InnerList.Count; i++) { - AttributeMetadata tmp = (AttributeMetadata)InnerList[i]; + AttributeMetadata tmp = (AttributeMetadata)InnerList[i]!; if (Utils.Compare(tmp.Name, metadata.Name) == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs index ef94d0c08fec5..aac9d85611bf7 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs @@ -18,12 +18,12 @@ public class ConfigurationSet // variables corresponding to public properties private readonly string _configSetName; - private ReadOnlySiteCollection _cachedSites; - private AdamInstanceCollection _cachedADAMInstances; - private ApplicationPartitionCollection _cachedApplicationPartitions; - private ActiveDirectorySchema _cachedSchema; - private AdamInstance _cachedSchemaRoleOwner; - private AdamInstance _cachedNamingRoleOwner; + private ReadOnlySiteCollection? _cachedSites; + private AdamInstanceCollection? _cachedADAMInstances; + private ApplicationPartitionCollection? _cachedApplicationPartitions; + private ActiveDirectorySchema? _cachedSchema; + private AdamInstance? _cachedSchemaRoleOwner; + private AdamInstance? _cachedNamingRoleOwner; private ReplicationSecurityLevel _cachedSecurityLevel = (ReplicationSecurityLevel)(-1); // 4 minutes timeout for locating an ADAM instance in the configset @@ -103,8 +103,8 @@ public static ConfigurationSet GetConfigurationSet(DirectoryContext context) // bind to rootdse of an adam instance (if target is already a server, verify that it is an adam instance) // DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); - DirectoryEntry rootDSE = null; - string configSetName = null; + DirectoryEntry? rootDSE = null; + string configSetName; try { @@ -114,7 +114,7 @@ public static ConfigurationSet GetConfigurationSet(DirectoryContext context) throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.AINotFound, context.Name), typeof(ConfigurationSet), null); } - configSetName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ConfigurationNamingContext); + configSetName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ConfigurationNamingContext)!; } catch (COMException e) { @@ -169,7 +169,7 @@ public AdamInstance FindAdamInstance(string partitionName) return FindOneAdamInstance(Name, _context, partitionName, null); } - public AdamInstance FindAdamInstance(string partitionName, string siteName) + public AdamInstance FindAdamInstance(string? partitionName, string siteName) { CheckIfDisposed(); @@ -204,7 +204,7 @@ public AdamInstanceCollection FindAllAdamInstances(string partitionName) return FindAdamInstances(_context, partitionName, null); } - public AdamInstanceCollection FindAllAdamInstances(string partitionName, string siteName) + public AdamInstanceCollection FindAllAdamInstances(string? partitionName, string? siteName) { CheckIfDisposed(); @@ -232,7 +232,7 @@ public ReplicationSecurityLevel GetSecurityLevel() if (_cachedSecurityLevel == (ReplicationSecurityLevel)(-1)) { DirectoryEntry configEntry = _directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.ConfigurationNamingContext); - _cachedSecurityLevel = (ReplicationSecurityLevel)((int)PropertyManager.GetPropertyValue(_context, configEntry, PropertyManager.MsDSReplAuthenticationMode)); + _cachedSecurityLevel = (ReplicationSecurityLevel)((int)PropertyManager.GetPropertyValue(_context, configEntry, PropertyManager.MsDSReplAuthenticationMode)!); } return _cachedSecurityLevel; } @@ -260,13 +260,13 @@ public void SetSecurityLevel(ReplicationSecurityLevel securityLevel) _cachedSecurityLevel = (ReplicationSecurityLevel)(-1); } - public override string ToString() => Name; + public override string? ToString() => Name; #endregion public methods #region public properties - public string Name + public string? Name { get { @@ -381,7 +381,7 @@ private static DirectoryEntry GetSearchRootEntry(Forest forest) // isServer = true; DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(forestContext, WellKnownDN.RootDSE); - string isGCReady = (string)PropertyManager.GetPropertyValue(forestContext, rootDSE, PropertyManager.IsGlobalCatalogReady); + string? isGCReady = (string?)PropertyManager.GetPropertyValue(forestContext, rootDSE, PropertyManager.IsGlobalCatalogReady); isGC = (Utils.Compare(isGCReady, "TRUE") == 0); } @@ -422,7 +422,7 @@ internal static AdamInstance FindAnyAdamInstance(DirectoryContext context) throw new ArgumentException(SR.TargetShouldBeServerORConfigSet, nameof(context)); } - string dnsHostName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName); + string dnsHostName = (string?)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName)!; return new AdamInstance(context, dnsHostName, directoryEntryMgr); } @@ -449,7 +449,7 @@ internal static AdamInstance FindAnyAdamInstance(DirectoryContext context) str.Append("=1.2.840.113556.1.4.1851)("); str.Append(PropertyManager.Keywords); str.Append('='); - str.Append(Utils.GetEscapedFilterValue(context.Name)); // target = config set name + str.Append(Utils.GetEscapedFilterValue(context.Name!)); // target = config set name str.Append("))"); string filter = str.ToString(); @@ -500,12 +500,12 @@ internal static AdamInstance FindAnyAdamInstance(DirectoryContext context) return FindAliveAdamInstance(null, context, adamInstanceNames); } - internal static AdamInstance FindOneAdamInstance(DirectoryContext context, string partitionName, string siteName) + internal static AdamInstance FindOneAdamInstance(DirectoryContext context, string? partitionName, string? siteName) { return FindOneAdamInstance(null, context, partitionName, siteName); } - internal static AdamInstance FindOneAdamInstance(string configSetName, DirectoryContext context, string partitionName, string siteName) + internal static AdamInstance FindOneAdamInstance(string? configSetName, DirectoryContext context, string? partitionName, string? siteName) { // can expect valid context (non-null) if (partitionName != null && partitionName.Length == 0) @@ -528,7 +528,7 @@ internal static AdamInstance FindOneAdamInstance(string configSetName, Directory return FindAliveAdamInstance(configSetName, context, ntdsaNames); } - internal static AdamInstanceCollection FindAdamInstances(DirectoryContext context, string partitionName, string siteName) + internal static AdamInstanceCollection FindAdamInstances(DirectoryContext context, string? partitionName, string? siteName) { // can expect valid context (non-null) if (partitionName != null && partitionName.Length == 0) @@ -558,10 +558,10 @@ internal static AdamInstanceCollection FindAdamInstances(DirectoryContext contex // 1. An ADAM instance responds to an ldap_bind - we return an ADAMInstance object for that adam instance // 2. We exceed the timeout duration - we return an ActiveDirectoryObjectNotFoundException // - internal static AdamInstance FindAliveAdamInstance(string configSetName, DirectoryContext context, ArrayList adamInstanceNames) + internal static AdamInstance FindAliveAdamInstance(string? configSetName, DirectoryContext context, ArrayList adamInstanceNames) { bool foundAliveADAMInstance = false; - AdamInstance adamInstance = null; + AdamInstance? adamInstance = null; // record the start time so that we can determine if the timeout duration has been exceeded or not DateTime startTime = DateTime.UtcNow; @@ -597,7 +597,7 @@ internal static AdamInstance FindAliveAdamInstance(string configSetName, Directo if (foundAliveADAMInstance) { - return adamInstance; + return adamInstance!; } } @@ -608,9 +608,9 @@ internal static AdamInstance FindAliveAdamInstance(string configSetName, Directo /// Returns a DomainController object for the DC that holds the specified FSMO role private AdamInstance GetRoleOwner(AdamRole role) { - DirectoryEntry entry = null; + DirectoryEntry? entry = null; - string adamInstName = null; + string? adamInstName = null; try { switch (role) @@ -633,7 +633,7 @@ private AdamInstance GetRoleOwner(AdamRole role) break; } entry.RefreshCache(); - adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)PropertyManager.GetPropertyValue(_context, entry, PropertyManager.FsmoRoleOwner)); + adamInstName = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)PropertyManager.GetPropertyValue(_context, entry, PropertyManager.FsmoRoleOwner)!); } catch (COMException e) { @@ -668,7 +668,7 @@ private ArrayList GetSites() propertiesToLoad[0] = PropertyManager.Cn; ADSearcher searcher = new ADSearcher(sitesEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { @@ -677,7 +677,7 @@ private ArrayList GetSites() foreach (SearchResult res in resCol) { // an existing site - sites.Add(new ActiveDirectorySite(_context, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn), true)); + sites.Add(new ActiveDirectorySite(_context, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.Cn)!, true)); } } catch (COMException e) @@ -726,27 +726,27 @@ private ArrayList GetApplicationPartitions() propertiesToLoad[1] = PropertyManager.MsDSNCReplicaLocations; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { resCol = searcher.FindAll(); - string schemaNamingContext = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext); - string configurationNamingContext = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext); + string? schemaNamingContext = (string?)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext); + string? configurationNamingContext = (string?)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext); foreach (SearchResult res in resCol) { // add the name of the appNC only if it is not // the Schema or Configuration partition - string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName); + string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName)!; if ((!(nCName.Equals(schemaNamingContext))) && (!(nCName.Equals(configurationNamingContext)))) { ResultPropertyValueCollection replicaLocations = res.Properties[PropertyManager.MsDSNCReplicaLocations]; if (replicaLocations.Count > 0) { - string replicaName = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)replicaLocations[Utils.GetRandomIndex(replicaLocations.Count)]); + string replicaName = Utils.GetAdamDnsHostNameFromNTDSA(_context, (string)replicaLocations[Utils.GetRandomIndex(replicaLocations.Count)]!); DirectoryContext appNCContext = Utils.GetNewDirectoryContext(replicaName, DirectoryContextType.DirectoryServer, _context); appNCs.Add(new ApplicationPartition(appNCContext, nCName, null, ApplicationPartitionType.ADAMApplicationPartition, new DirectoryEntryManager(appNCContext))); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs index b60222552fdab..3fd08dcde513a 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.ComponentModel; using System.IO; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices.ActiveDirectory { @@ -21,10 +22,10 @@ public enum DirectoryContextType public class DirectoryContext { - private string _name; + private string? _name; private DirectoryContextType _contextType; private NetworkCredential _credential; - internal string serverName; + internal string? serverName; internal bool usernameIsNull; internal bool passwordIsNull; private bool _validated; @@ -42,7 +43,8 @@ static DirectoryContext() } // Internal Constructors - internal void InitializeDirectoryContext(DirectoryContextType contextType, string name, string username, string password) + [MemberNotNull(nameof(_credential))] + internal void InitializeDirectoryContext(DirectoryContextType contextType, string? name, string? username, string? password) { _name = name; _contextType = contextType; @@ -57,7 +59,7 @@ internal void InitializeDirectoryContext(DirectoryContextType contextType, strin } } - internal DirectoryContext(DirectoryContextType contextType, string name, DirectoryContext context) + internal DirectoryContext(DirectoryContextType contextType, string? name, DirectoryContext? context) { _name = name; _contextType = contextType; @@ -169,11 +171,11 @@ public DirectoryContext(DirectoryContextType contextType, string name, string us #region public properties - public string Name => _name; + public string? Name => _name; - public string UserName => usernameIsNull ? null : _credential.UserName; + public string? UserName => usernameIsNull ? null : _credential.UserName; - internal string Password + internal string? Password { get => passwordIsNull ? null : _credential.Password; } @@ -191,7 +193,7 @@ internal static bool IsContextValid(DirectoryContext context, DirectoryContextTy if ((contextType == DirectoryContextType.Domain) || ((contextType == DirectoryContextType.Forest) && (context.Name == null))) { - string tmpTarget = context.Name; + string? tmpTarget = context.Name; if (tmpTarget == null) { @@ -341,9 +343,9 @@ internal static bool IsContextValid(DirectoryContext context, DirectoryContextTy // // if the servername contains a port number, then remove that // - string tempServerName = null; - string portNumber; - tempServerName = Utils.SplitServerNameAndPortNumber(context.Name, out portNumber); + string? tempServerName = null; + string? portNumber; + tempServerName = Utils.SplitServerNameAndPortNumber(context.Name!, out portNumber); // // this will validate that the name specified in the context is truely the name of a machine (and not of a domain) @@ -484,7 +486,7 @@ internal bool useServerBind() return ((ContextType == DirectoryContextType.DirectoryServer) || (ContextType == DirectoryContextType.ConfigurationSet)); } - internal string GetServerName() + internal string? GetServerName() { if (serverName == null) { @@ -549,7 +551,7 @@ internal string GetServerName() internal static string GetLoggedOnDomain() { - string domainName = null; + string? domainName = null; NegotiateCallerNameRequest requestBuffer = new NegotiateCallerNameRequest(); int requestBufferLength = (int)Marshal.SizeOf(requestBuffer); @@ -647,7 +649,7 @@ internal static string GetLoggedOnDomain() return domainName; } - internal static string GetDnsDomainName(string domainName) + internal static string? GetDnsDomainName(string? domainName) { DomainControllerInfo domainControllerInfo; int errorCode = 0; @@ -680,6 +682,8 @@ internal static string GetDnsDomainName(string domainName) return domainControllerInfo.DomainName; } + [MemberNotNull(nameof(ADHandle))] + [MemberNotNull(nameof(ADAMHandle))] private static void GetLibraryHandle() { // first get AD handle @@ -696,7 +700,7 @@ private static void GetLibraryHandle() // not get the ADAM handle // got to the windows\adam directory - DirectoryInfo windowsDirectory = Directory.GetParent(systemPath); + DirectoryInfo windowsDirectory = Directory.GetParent(systemPath)!; tempHandle = UnsafeNativeMethods.LoadLibrary(windowsDirectory.FullName + "\\ADAM\\ntdsapi.dll"); if (tempHandle == (IntPtr)0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs index 1491969e088e8..296d91115d325 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs @@ -41,15 +41,15 @@ public bool Equals(DistinguishedName dn) return result; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if ((obj == null) || (!(obj is DistinguishedName))) + if (obj is DistinguishedName other) { - return false; + return Equals(other); } else { - return Equals((DistinguishedName)obj); + return false; } } @@ -58,7 +58,7 @@ public override int GetHashCode() int hashCode = 0; for (int i = 0; i < Components.GetLength(0); i++) { - hashCode = hashCode + Components[i].Name.ToUpperInvariant().GetHashCode() + Components[i].Value.ToUpperInvariant().GetHashCode(); + hashCode = hashCode + Components[i].Name!.ToUpperInvariant().GetHashCode() + Components[i].Value!.ToUpperInvariant().GetHashCode(); } return hashCode; } @@ -84,7 +84,7 @@ public override string ToString() internal class DirectoryEntryManager { private readonly Hashtable _directoryEntries = new Hashtable(); - private string _bindingPrefix; + private string? _bindingPrefix; private readonly DirectoryContext _context; private readonly NativeComInterfaces.IAdsPathname _pathCracker; @@ -121,7 +121,7 @@ internal DirectoryEntry GetCachedDirectoryEntry(string distinguishedName) // add it to the cache _directoryEntries.Add(dn, de); } - return (DirectoryEntry)_directoryEntries[dn]; + return (DirectoryEntry)_directoryEntries[dn]!; } internal void RemoveIfExists(string distinguishedName) @@ -142,7 +142,7 @@ internal void RemoveIfExists(string distinguishedName) if (_directoryEntries.ContainsKey(dn)) { - DirectoryEntry tmp = (DirectoryEntry)_directoryEntries[dn]; + DirectoryEntry? tmp = (DirectoryEntry?)_directoryEntries[dn]; if (tmp != null) { _directoryEntries.Remove(dn); @@ -166,7 +166,7 @@ private DirectoryEntry GetNewDirectoryEntry(string dn) internal string ExpandWellKnownDN(WellKnownDN dn) { - string distinguishedName = null; + string? distinguishedName = null; switch (dn) { @@ -179,25 +179,25 @@ internal string ExpandWellKnownDN(WellKnownDN dn) { DirectoryEntry rootDSE = GetCachedDirectoryEntry("RootDSE"); - distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.RootDomainNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.RootDomainNamingContext)!; break; } case WellKnownDN.DefaultNamingContext: { DirectoryEntry rootDSE = GetCachedDirectoryEntry("RootDSE"); - distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.DefaultNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.DefaultNamingContext)!; break; } case WellKnownDN.SchemaNamingContext: { DirectoryEntry rootDSE = GetCachedDirectoryEntry("RootDSE"); - distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.SchemaNamingContext)!; break; } case WellKnownDN.ConfigurationNamingContext: { DirectoryEntry rootDSE = GetCachedDirectoryEntry("RootDSE"); - distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(_context, rootDSE, PropertyManager.ConfigurationNamingContext)!; break; } case WellKnownDN.PartitionsContainer: @@ -254,9 +254,9 @@ internal static DirectoryEntry GetDirectoryEntryInternal(DirectoryContext contex return Bind(path, context.UserName, context.Password, context.useServerBind()); } - internal static DirectoryEntry Bind(string ldapPath, string username, string password, bool useServerBind) + internal static DirectoryEntry Bind(string ldapPath, string? username, string? password, bool useServerBind) { - DirectoryEntry de = null; + DirectoryEntry? de = null; AuthenticationTypes authType = Utils.DefaultAuthType; // @@ -274,7 +274,7 @@ internal static DirectoryEntry Bind(string ldapPath, string username, string pas internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN dn) { - string distinguishedName = null; + string? distinguishedName = null; switch (dn) { @@ -289,7 +289,7 @@ internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN d try { - distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext)!; } finally { @@ -302,7 +302,7 @@ internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN d DirectoryEntry rootDSE = GetDirectoryEntry(context, "RootDSE"); try { - distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext)!; } finally { @@ -315,7 +315,7 @@ internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN d DirectoryEntry rootDSE = GetDirectoryEntry(context, "RootDSE"); try { - distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.SchemaNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.SchemaNamingContext)!; } finally { @@ -328,7 +328,7 @@ internal static string ExpandWellKnownDN(DirectoryContext context, WellKnownDN d DirectoryEntry rootDSE = GetDirectoryEntry(context, "RootDSE"); try { - distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ConfigurationNamingContext); + distinguishedName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.ConfigurationNamingContext)!; } finally { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs index 933b665a49c53..24bc8ce837251 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServer.cs @@ -11,25 +11,25 @@ namespace System.DirectoryServices.ActiveDirectory public abstract class DirectoryServer : IDisposable { private bool _disposed; - internal DirectoryContext context; - internal string replicaName; - internal DirectoryEntryManager directoryEntryMgr; + internal DirectoryContext context = null!; + internal string replicaName = null!; + internal DirectoryEntryManager directoryEntryMgr = null!; // internal variables for the public properties internal bool siteInfoModified; - internal string cachedSiteName; - internal string cachedSiteObjectName; - internal string cachedServerObjectName; - internal string cachedNtdsaObjectName; + internal string? cachedSiteName; + internal string? cachedSiteObjectName; + internal string? cachedServerObjectName; + internal string? cachedNtdsaObjectName; internal Guid cachedNtdsaObjectGuid = Guid.Empty; - internal ReadOnlyStringCollection cachedPartitions; + internal ReadOnlyStringCollection? cachedPartitions; internal const int DS_REPSYNC_ASYNCHRONOUS_OPERATION = 0x00000001; internal const int DS_REPSYNC_ALL_SOURCES = 0x00000010; internal const int DS_REPSYNCALL_ID_SERVERS_BY_DN = 0x00000004; internal const int DS_REPL_NOTSUPPORTED = 50; - private ReplicationConnectionCollection _inbound; - private ReplicationConnectionCollection _outbound; + private ReplicationConnectionCollection? _inbound; + private ReplicationConnectionCollection? _outbound; #region constructors protected DirectoryServer() @@ -91,7 +91,7 @@ public void MoveToAnotherSite(string siteName) // the dc is really being moved to a different site if (Utils.Compare(SiteName, siteName) != 0) { - DirectoryEntry newParentEntry = null; + DirectoryEntry? newParentEntry = null; try { // Bind to the target site's server container @@ -104,7 +104,7 @@ public void MoveToAnotherSite(string siteName) DirectoryEntry serverEntry = directoryEntryMgr.GetCachedDirectoryEntry(serverName); // force binding (needed otherwise S.DS throw an exception while releasing the COM interface pointer) - _ = (string)PropertyManager.GetPropertyValue(context, serverEntry, PropertyManager.DistinguishedName); + _ = (string?)PropertyManager.GetPropertyValue(context, serverEntry, PropertyManager.DistinguishedName); // move the object to the servers container of the target site serverEntry.MoveTo(newParentEntry); @@ -207,11 +207,11 @@ public ReadOnlyStringCollection Partitions #region public abstract properties - public abstract string IPAddress { get; } + public abstract string? IPAddress { get; } public abstract string SiteName { get; } - public abstract SyncUpdateCallback SyncFromAllServersCallback { get; set; } + public abstract SyncUpdateCallback? SyncFromAllServersCallback { get; set; } public abstract ReplicationConnectionCollection InboundConnections { get; } @@ -224,8 +224,8 @@ public ReadOnlyStringCollection Partitions internal ArrayList GetPartitions() { ArrayList partitionList = new ArrayList(); - DirectoryEntry rootDSE = null; - DirectoryEntry serverNtdsaEntry = null; + DirectoryEntry? rootDSE = null; + DirectoryEntry? serverNtdsaEntry = null; try { @@ -245,7 +245,7 @@ internal ArrayList GetPartitions() ArrayList propertyNames = new ArrayList(); propertyNames.Add(PropertyManager.HasPartialReplicaNCs); - Hashtable values = null; + Hashtable? values = null; try { values = Utils.GetValuesWithRangeRetrieval(serverNtdsaEntry, null, propertyNames, SearchScope.Base); @@ -255,7 +255,7 @@ internal ArrayList GetPartitions() throw ExceptionHelper.GetExceptionFromCOMException(context, e); } - ArrayList readOnlyPartitions = (ArrayList)values[PropertyManager.HasPartialReplicaNCs.ToLowerInvariant()]; + ArrayList readOnlyPartitions = (ArrayList)values[PropertyManager.HasPartialReplicaNCs.ToLowerInvariant()]!; Debug.Assert(readOnlyPartitions != null); foreach (string readOnlyPartition in readOnlyPartitions) @@ -308,7 +308,7 @@ internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libH throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } - internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) + internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string? partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr info = (IntPtr)0; int result = 0; @@ -600,7 +600,7 @@ internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update) // get the error information IntPtr temp = syncAllUpdate.pErrInfo; - SyncFromAllServersOperationException exception = null; + SyncFromAllServersOperationException? exception = null; if (temp != (IntPtr)0) { @@ -613,8 +613,8 @@ internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update) } } - string targetName = null; - string sourceName = null; + string? targetName = null; + string? sourceName = null; temp = syncAllUpdate.pSync; if (temp != (IntPtr)0) @@ -633,7 +633,7 @@ internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update) } } - internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) + internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback? callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; @@ -656,7 +656,7 @@ internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallb // error happens during the synchronization if (errorInfo != (IntPtr)0) { - SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); + SyncFromAllServersOperationException? e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) return; else @@ -693,13 +693,13 @@ private void FreeReplicaInfo(DS_REPL_INFO_TYPE type, IntPtr value, LoadLibrarySa } } - internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string sourceServer, int option, LoadLibrarySafeHandle libHandle) + internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string? sourceServer, int option, LoadLibrarySafeHandle libHandle) { int structSize = Marshal.SizeOf(typeof(Guid)); IntPtr unmanagedGuid = (IntPtr)0; Guid guid = Guid.Empty; - AdamInstance adamServer = null; - DomainController dcServer = null; + AdamInstance? adamServer = null; + DomainController? dcServer = null; unmanagedGuid = Marshal.AllocHGlobal(structSize); try @@ -737,7 +737,7 @@ internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, if (!Partitions.Contains(partition)) throw new ArgumentException(SR.ServerNotAReplica, nameof(partition)); - string serverDownName = null; + string? serverDownName = null; // this is the error returned when the server that we want to sync from is down if (result == ExceptionHelper.RPC_S_SERVER_UNAVAILABLE) serverDownName = sourceServer; @@ -778,14 +778,14 @@ internal ReplicationConnectionCollection GetInboundConnectionsHelper() "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))", new string[] { "cn" }, SearchScope.OneLevel); - SearchResultCollection srchResults = null; + SearchResultCollection? srchResults = null; try { srchResults = adSearcher.FindAll(); foreach (SearchResult r in srchResults) { - ReplicationConnection con = new ReplicationConnection(newContext, r.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.Cn)); + ReplicationConnection con = new ReplicationConnection(newContext, r.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.Cn)!); _inbound.Add(con); } } @@ -820,7 +820,7 @@ internal ReplicationConnectionCollection GetOutboundConnectionsHelper() new string[] { "objectClass", "cn" }, SearchScope.Subtree); - SearchResultCollection results = null; + SearchResultCollection? results = null; DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context); try @@ -830,7 +830,7 @@ internal ReplicationConnectionCollection GetOutboundConnectionsHelper() foreach (SearchResult result in results) { - ReplicationConnection con = new ReplicationConnection(newContext, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]); + ReplicationConnection con = new ReplicationConnection(newContext, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]!); _outbound.Add(con); } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs index 380cf49f2c4e0..2cac72385a237 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs @@ -9,13 +9,13 @@ namespace System.DirectoryServices.ActiveDirectory { public class DirectoryServerCollection : CollectionBase { - internal readonly string siteDN; - internal readonly string transportDN; + internal readonly string? siteDN; + internal readonly string? transportDN; internal readonly DirectoryContext context; internal bool initialized; - internal readonly Hashtable changeList; + internal readonly Hashtable? changeList; private readonly ArrayList _copyList = new ArrayList(); - private readonly DirectoryEntry _crossRefEntry; + private readonly DirectoryEntry? _crossRefEntry; private readonly bool _isADAM; private readonly bool _isForNC; @@ -29,7 +29,7 @@ internal DirectoryServerCollection(DirectoryContext context, string siteDN, stri this.transportDN = transportName; } - internal DirectoryServerCollection(DirectoryContext context, DirectoryEntry crossRefEntry, bool isADAM, ReadOnlyDirectoryServerCollection servers) + internal DirectoryServerCollection(DirectoryContext context, DirectoryEntry? crossRefEntry, bool isADAM, ReadOnlyDirectoryServerCollection servers) { this.context = context; _crossRefEntry = crossRefEntry; @@ -44,7 +44,7 @@ internal DirectoryServerCollection(DirectoryContext context, DirectoryEntry cros public DirectoryServer this[int index] { - get => (DirectoryServer)InnerList[index]; + get => (DirectoryServer)InnerList[index]!; set { DirectoryServer server = (DirectoryServer)value; @@ -129,7 +129,7 @@ public bool Contains(DirectoryServer server) for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer tmp = (DirectoryServer)InnerList[i]; + DirectoryServer tmp = (DirectoryServer)InnerList[i]!; if (Utils.Compare(tmp.Name, server.Name) == 0) { @@ -151,7 +151,7 @@ public int IndexOf(DirectoryServer server) for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer tmp = (DirectoryServer)InnerList[i]; + DirectoryServer tmp = (DirectoryServer)InnerList[i]!; if (Utils.Compare(tmp.Name, server.Name) == 0) { @@ -214,7 +214,7 @@ public void Remove(DirectoryServer server) for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer tmp = (DirectoryServer)InnerList[i]; + DirectoryServer tmp = (DirectoryServer)InnerList[i]!; if (Utils.Compare(tmp.Name, server.Name) == 0) { @@ -263,12 +263,12 @@ protected override void OnClearComplete() { for (int i = 0; i < _copyList.Count; i++) { - OnRemoveComplete(i, _copyList[i]); + OnRemoveComplete(i, _copyList[i]!); } } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (_isForNC) { @@ -276,7 +276,7 @@ protected override void OnInsertComplete(int index, object value) { try { - DirectoryServer server = (DirectoryServer)value; + DirectoryServer server = (DirectoryServer)value!; string ntdsaName = (server is DomainController) ? ((DomainController)server).NtdsaObjectName : ((AdamInstance)server).NtdsaObjectName; _crossRefEntry.Properties[PropertyManager.MsDSNCReplicaLocations].Add(ntdsaName); } @@ -288,15 +288,15 @@ protected override void OnInsertComplete(int index, object value) } else if (initialized) { - DirectoryServer server = (DirectoryServer)value; + DirectoryServer server = (DirectoryServer)value!; string name = server.Name; string serverName = (server is DomainController) ? ((DomainController)server).ServerObjectName : ((AdamInstance)server).ServerObjectName; try { - if (changeList.Contains(name)) + if (changeList!.Contains(name)) { - ((DirectoryEntry)changeList[name]).Properties["bridgeheadTransportList"].Value = this.transportDN; + ((DirectoryEntry)changeList[name]!).Properties["bridgeheadTransportList"].Value = this.transportDN; } else { @@ -313,7 +313,7 @@ protected override void OnInsertComplete(int index, object value) } } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { if (_isForNC) { @@ -321,7 +321,7 @@ protected override void OnRemoveComplete(int index, object value) { if (_crossRefEntry != null) { - string ntdsaName = (value is DomainController) ? ((DomainController)value).NtdsaObjectName : ((AdamInstance)value).NtdsaObjectName; + string ntdsaName = (value is DomainController) ? ((DomainController)value).NtdsaObjectName : ((AdamInstance)value!).NtdsaObjectName; _crossRefEntry.Properties[PropertyManager.MsDSNCReplicaLocations].Remove(ntdsaName); } } @@ -332,15 +332,15 @@ protected override void OnRemoveComplete(int index, object value) } else { - DirectoryServer server = (DirectoryServer)value; + DirectoryServer server = (DirectoryServer)value!; string name = server.Name; string serverName = (server is DomainController) ? ((DomainController)server).ServerObjectName : ((AdamInstance)server).ServerObjectName; try { - if (changeList.Contains(name)) + if (changeList!.Contains(name)) { - ((DirectoryEntry)changeList[name]).Properties["bridgeheadTransportList"].Clear(); + ((DirectoryEntry)changeList[name]!).Properties["bridgeheadTransportList"].Clear(); } else { @@ -357,7 +357,7 @@ protected override void OnRemoveComplete(int index, object value) } } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { OnRemoveComplete(index, oldValue); OnInsertComplete(index, newValue); @@ -394,7 +394,7 @@ internal string[] GetMultiValuedProperty() ArrayList values = new ArrayList(); for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer ds = (DirectoryServer)InnerList[i]; + DirectoryServer ds = (DirectoryServer)InnerList[i]!; string ntdsaName = (ds is DomainController) ? ((DomainController)ds).NtdsaObjectName : ((AdamInstance)ds).NtdsaObjectName; values.Add(ntdsaName); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Domain.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Domain.cs index e3c5178acad3b..54b8e160ed1bb 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Domain.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Domain.cs @@ -7,6 +7,7 @@ using System.ComponentModel; using System.Runtime.InteropServices; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices.ActiveDirectory { @@ -26,19 +27,19 @@ public enum DomainMode : int public class Domain : ActiveDirectoryPartition { /// Private Variables - private string _crossRefDN; - private string _trustParent; + private string? _crossRefDN; + private string? _trustParent; // internal variables corresponding to public properties - private DomainControllerCollection _cachedDomainControllers; - private DomainCollection _cachedChildren; + private DomainControllerCollection? _cachedDomainControllers; + private DomainCollection? _cachedChildren; private DomainMode _currentDomainMode = (DomainMode)(-1); private int _domainModeLevel = -1; - private DomainController _cachedPdcRoleOwner; - private DomainController _cachedRidRoleOwner; - private DomainController _cachedInfrastructureRoleOwner; - private Domain _cachedParent; - private Forest _cachedForest; + private DomainController? _cachedPdcRoleOwner; + private DomainController? _cachedRidRoleOwner; + private DomainController? _cachedInfrastructureRoleOwner; + private Domain? _cachedParent; + private Forest? _cachedForest; // this is needed because null value for parent is valid private bool _isParentInitialized; @@ -97,8 +98,8 @@ public static Domain GetDomain(DirectoryContext context) // bind to the rootDSE of the domain specified in the context // and get the dns name DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context); - DirectoryEntry rootDSE = null; - string defaultDomainNC = null; + DirectoryEntry? rootDSE = null; + string? defaultDomainNC = null; try { rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); @@ -106,7 +107,7 @@ public static Domain GetDomain(DirectoryContext context) { throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.DCNotFound, context.Name), typeof(Domain), null); } - defaultDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext); + defaultDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext)!; } catch (COMException e) { @@ -135,7 +136,7 @@ public static Domain GetDomain(DirectoryContext context) public static Domain GetComputerDomain() { - string computerDomainName = DirectoryContext.GetDnsDomainName(null); + string? computerDomainName = DirectoryContext.GetDnsDomainName(null); if (computerDomainName == null) { throw new ActiveDirectoryObjectNotFoundException(SR.ComputerNotJoinedToDomain, typeof(Domain), null); @@ -166,7 +167,7 @@ public void RaiseDomainFunctionalityLevel(int domainMode) DomainMode existingDomainMode = DomainMode; // set the forest mode on AD - DirectoryEntry domainEntry = null; + DirectoryEntry? domainEntry = null; // CurrentDomain Valid domainMode Action // ----------------- @@ -269,7 +270,7 @@ public void RaiseDomainFunctionality(DomainMode domainMode) existingDomainMode = GetDomainMode(); // set the forest mode on AD - DirectoryEntry domainEntry = null; + DirectoryEntry? domainEntry = null; // CurrentDomain Valid RequestedDomain Action // ----------------- @@ -795,7 +796,7 @@ public void RepairTrustRelationship(Domain targetDomain) // first try to reset the secure channel try { - direction = GetTrustRelationship(targetDomain.Name).TrustDirection; + direction = GetTrustRelationship(targetDomain.Name!).TrustDirection; // verify outbound trust first if ((direction & TrustDirection.Outbound) != 0) @@ -843,8 +844,8 @@ public Forest Forest { // get the name of rootDomainNamingContext DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE); - string rootDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext); - string forestName = Utils.GetDnsNameFromDN(rootDomainNC); + string rootDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext)!; + string? forestName = Utils.GetDnsNameFromDN(rootDomainNC); DirectoryContext forestContext = Utils.GetNewDirectoryContext(forestName, DirectoryContextType.Forest, context); _cachedForest = new Forest(forestContext, forestName); } @@ -904,7 +905,7 @@ public int DomainModeLevel } } - public Domain Parent + public Domain? Parent { get { @@ -965,7 +966,7 @@ public DomainController InfrastructureRoleOwner private int GetDomainModeLevel() { - DirectoryEntry domainEntry = null; + DirectoryEntry? domainEntry = null; DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); int domainFunctionality = 0; @@ -973,7 +974,7 @@ private int GetDomainModeLevel() { if (rootDSE.Properties.Contains(PropertyManager.DomainFunctionality)) { - domainFunctionality = int.Parse((string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DomainFunctionality), NumberFormatInfo.InvariantInfo); + domainFunctionality = int.Parse((string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DomainFunctionality)!, NumberFormatInfo.InvariantInfo); } } catch (COMException e) @@ -1004,7 +1005,7 @@ private DomainMode GetDomainMode() // if domainFunctionality is 5 ==> Windows2012 // if domainFunctionality is 6 ==> Windows2012R2 DomainMode domainMode; - DirectoryEntry domainEntry = null; + DirectoryEntry? domainEntry = null; int domainFunctionality = DomainModeLevel; try @@ -1016,7 +1017,7 @@ private DomainMode GetDomainMode() case 0: { domainEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext)); - int ntMixedDomain = (int)PropertyManager.GetPropertyValue(context, domainEntry, PropertyManager.NTMixedDomain); + int ntMixedDomain = (int)PropertyManager.GetPropertyValue(context, domainEntry, PropertyManager.NTMixedDomain)!; if (ntMixedDomain == 0) { @@ -1072,9 +1073,9 @@ private DomainMode GetDomainMode() /// Returns a DomainController object for the DC that holds the specified FSMO role private DomainController GetRoleOwner(ActiveDirectoryRole role) { - DirectoryEntry entry = null; + DirectoryEntry? entry = null; - string dcName = null; + string? dcName = null; try { switch (role) @@ -1100,7 +1101,7 @@ private DomainController GetRoleOwner(ActiveDirectoryRole role) break; } - dcName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, entry, PropertyManager.FsmoRoleOwner)); + dcName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, entry, PropertyManager.FsmoRoleOwner)!); } catch (COMException e) { @@ -1120,9 +1121,10 @@ private DomainController GetRoleOwner(ActiveDirectoryRole role) return new DomainController(dcContext, dcName); } + [MemberNotNull(nameof(_crossRefDN))] private void LoadCrossRefAttributes() { - DirectoryEntry partitionsEntry = null; + DirectoryEntry? partitionsEntry = null; try { partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); @@ -1146,7 +1148,7 @@ private void LoadCrossRefAttributes() str.Append(")("); str.Append(PropertyManager.DnsRoot); str.Append('='); - str.Append(Utils.GetEscapedFilterValue(partitionName)); + str.Append(Utils.GetEscapedFilterValue(partitionName!)); str.Append("))"); string filter = str.ToString(); @@ -1156,14 +1158,14 @@ private void LoadCrossRefAttributes() propertiesToLoad[1] = PropertyManager.TrustParent; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); - SearchResult res = searcher.FindOne(); + SearchResult res = searcher.FindOne()!; - _crossRefDN = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); + _crossRefDN = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName)!; // "trustParent" attribute may not be set if (res.Properties[PropertyManager.TrustParent].Count > 0) { - _trustParent = (string)res.Properties[PropertyManager.TrustParent][0]; + _trustParent = (string?)res.Properties[PropertyManager.TrustParent][0]; } } catch (COMException e) @@ -1179,7 +1181,7 @@ private void LoadCrossRefAttributes() } } - private Domain GetParent() + private Domain? GetParent() { if (_crossRefDN == null) { @@ -1188,12 +1190,12 @@ private Domain GetParent() if (_trustParent != null) { DirectoryEntry parentCrossRef = DirectoryEntryManager.GetDirectoryEntry(context, _trustParent); - string parentDomainName = null; - DirectoryContext domainContext = null; + string? parentDomainName = null; + DirectoryContext? domainContext = null; try { // create a new directory context for the parent domain - parentDomainName = (string)PropertyManager.GetPropertyValue(context, parentCrossRef, PropertyManager.DnsRoot); + parentDomainName = (string)PropertyManager.GetPropertyValue(context, parentCrossRef, PropertyManager.DnsRoot)!; domainContext = Utils.GetNewDirectoryContext(parentDomainName, DirectoryContextType.Domain, context); } finally @@ -1215,8 +1217,8 @@ private ArrayList GetChildDomains() LoadCrossRefAttributes(); } - DirectoryEntry partitionsEntry = null; - SearchResultCollection resCol = null; + DirectoryEntry? partitionsEntry = null; + SearchResultCollection? resCol = null; try { partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer)); @@ -1253,7 +1255,7 @@ private ArrayList GetChildDomains() foreach (SearchResult res in resCol) { - string childDomainName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot); + string childDomainName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot)!; DirectoryContext childContext = Utils.GetNewDirectoryContext(childDomainName, DirectoryContextType.Domain, context); childDomains.Add(new Domain(childContext, childDomainName)); } @@ -1276,22 +1278,22 @@ private ArrayList GetChildDomains() return childDomains; } - private ArrayList GetTrustsHelper(string targetDomainName) + private ArrayList GetTrustsHelper(string? targetDomainName) { - string serverName = null; + string? serverName = null; IntPtr domains = (IntPtr)0; int count = 0; ArrayList unmanagedTrustList = new ArrayList(); ArrayList tmpTrustList = new ArrayList(); int localDomainIndex = 0; - string localDomainParent = null; + string? localDomainParent = null; int error = 0; bool impersonated = false; // first decide which server to go to if (context.isServer()) { - serverName = context.Name; + serverName = context.Name!; } else { @@ -1339,7 +1341,7 @@ private ArrayList GetTrustsHelper(string targetDomainName) for (int i = 0; i < unmanagedTrustList.Count; i++) { - DS_DOMAIN_TRUSTS unmanagedTrust = (DS_DOMAIN_TRUSTS)unmanagedTrustList[i]; + DS_DOMAIN_TRUSTS unmanagedTrust = (DS_DOMAIN_TRUSTS)unmanagedTrustList[i]!; // make sure this is the trust object that we want if ((unmanagedTrust.Flags & (int)(DS_DOMAINTRUST_FLAG.DS_DOMAIN_PRIMARY | DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_OUTBOUND | DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_INBOUND)) == 0) @@ -1388,7 +1390,7 @@ private ArrayList GetTrustsHelper(string targetDomainName) if ((obj.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_TREE_ROOT) == 0) { // get the parent domain name - DS_DOMAIN_TRUSTS parentTrust = (DS_DOMAIN_TRUSTS)unmanagedTrustList[obj.ParentIndex]; + DS_DOMAIN_TRUSTS parentTrust = (DS_DOMAIN_TRUSTS)unmanagedTrustList[obj.ParentIndex]!; if (parentTrust.DnsDomainName != (IntPtr)0) localDomainParent = Marshal.PtrToStringUni(parentTrust.DnsDomainName); } @@ -1409,7 +1411,7 @@ private ArrayList GetTrustsHelper(string targetDomainName) // now determine the trust type for (int i = 0; i < tmpTrustList.Count; i++) { - TrustObject tmpObject = (TrustObject)tmpTrustList[i]; + TrustObject tmpObject = (TrustObject)tmpTrustList[i]!; // local domain case, trust type has been determined if (i == localDomainIndex) continue; @@ -1427,15 +1429,15 @@ private ArrayList GetTrustsHelper(string targetDomainName) if ((tmpObject.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_IN_FOREST) != 0) { // child domain - if (tmpObject.ParentIndex == ((TrustObject)tmpTrustList[localDomainIndex]).OriginalIndex) + if (tmpObject.ParentIndex == ((TrustObject)tmpTrustList[localDomainIndex]!).OriginalIndex) { tmpObject.TrustType = TrustType.ParentChild; } // tree root else if ((tmpObject.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_TREE_ROOT) != 0 && - (((TrustObject)tmpTrustList[localDomainIndex]).Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_TREE_ROOT) != 0) + (((TrustObject)tmpTrustList[localDomainIndex]!).Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_TREE_ROOT) != 0) { - string tmpForestName = null; + string? tmpForestName = null; string rootDomainNC = directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.RootDomainNamingContext); tmpForestName = Utils.GetDnsNameFromDN(rootDomainNC); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainCollection.cs index f74cd29a2b90e..35cf8ad777dfc 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainCollection.cs @@ -9,18 +9,18 @@ public class DomainCollection : ReadOnlyCollectionBase { internal DomainCollection() { } - internal DomainCollection(ArrayList values) + internal DomainCollection(ArrayList? values) { if (values != null) { for (int i = 0; i < values.Count; i++) { - Add((Domain)values[i]); + Add((Domain)values[i]!); } } } - public Domain this[int index] => (Domain)InnerList[index]; + public Domain this[int index] => (Domain)InnerList[index]!; public bool Contains(Domain domain) { @@ -29,7 +29,7 @@ public bool Contains(Domain domain) for (int i = 0; i < InnerList.Count; i++) { - Domain tmp = (Domain)InnerList[i]; + Domain tmp = (Domain)InnerList[i]!; if (Utils.Compare(tmp.Name, domain.Name) == 0) { return true; @@ -45,7 +45,7 @@ public int IndexOf(Domain domain) for (int i = 0; i < InnerList.Count; i++) { - Domain tmp = (Domain)InnerList[i]; + Domain tmp = (Domain)InnerList[i]!; if (Utils.Compare(tmp.Name, domain.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainController.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainController.cs index 2a1b4f6f71d19..0575534ed6b83 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainController.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainController.cs @@ -34,27 +34,27 @@ public enum SyncFromAllServersErrorCategory ErrorReplicating = 1, ServerUnreachable = 2 } - public delegate bool SyncUpdateCallback(SyncFromAllServersEvent eventType, string targetServer, string sourceServer, SyncFromAllServersOperationException exception); + public delegate bool SyncUpdateCallback(SyncFromAllServersEvent eventType, string? targetServer, string? sourceServer, SyncFromAllServersOperationException? exception); internal delegate bool SyncReplicaFromAllServersCallback(IntPtr data, IntPtr update); public class DomainController : DirectoryServer { private IntPtr _dsHandle = IntPtr.Zero; private IntPtr _authIdentity = IntPtr.Zero; - private readonly string[] _becomeRoleOwnerAttrs; + private readonly string[] _becomeRoleOwnerAttrs = null!; private bool _disposed; // internal variables for the public properties - private string _cachedComputerObjectName; - private string _cachedOSVersion; + private string? _cachedComputerObjectName; + private string? _cachedOSVersion; private double _cachedNumericOSVersion; - private Forest _currentForest; - private Domain _cachedDomain; - private ActiveDirectoryRoleCollection _cachedRoles; + private Forest? _currentForest; + private Domain? _cachedDomain; + private ActiveDirectoryRoleCollection? _cachedRoles; private bool _dcInfoInitialized; - internal SyncUpdateCallback userDelegate; - internal readonly SyncReplicaFromAllServersCallback syncAllFunctionPointer; + internal SyncUpdateCallback? userDelegate; + internal readonly SyncReplicaFromAllServersCallback syncAllFunctionPointer = null!; // this is twice the maximum allowed RIDPool size which is 15k internal const int UpdateRidPoolSeizureValue = 30000; @@ -120,8 +120,8 @@ protected override void Dispose(bool disposing) public static DomainController GetDomainController(DirectoryContext context) { - string dcDnsName = null; - DirectoryEntryManager directoryEntryMgr = null; + string? dcDnsName = null; + DirectoryEntryManager? directoryEntryMgr = null; // check that the context argument is not null if (context == null) @@ -152,7 +152,7 @@ public static DomainController GetDomainController(DirectoryContext context) { throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.DCNotFound, context.Name), typeof(DomainController), context.Name); } - dcDnsName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName); + dcDnsName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName)!; } catch (COMException e) { @@ -294,7 +294,7 @@ public virtual GlobalCatalog EnableGlobalCatalog() int options = 0; if (serverNtdsaEntry.Properties[PropertyManager.Options].Value != null) { - options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value; + options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value!; } serverNtdsaEntry.Properties[PropertyManager.Options].Value = options | 1; serverNtdsaEntry.CommitChanges(); @@ -320,7 +320,7 @@ public virtual bool IsGlobalCatalog() int options = 0; if (serverNtdsaEntry.Properties[PropertyManager.Options].Value != null) { - options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value; + options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value!; } if ((options & (1)) == 1) { @@ -366,7 +366,7 @@ public void SeizeRoleOwnership(ActiveDirectoryRole role) { // set the "fsmoRoleOwner" attribute on the appropriate role object // to the NTDSAObjectName of this DC - string roleObjectDN = null; + string? roleObjectDN = null; CheckIfDisposed(); @@ -401,7 +401,7 @@ public void SeizeRoleOwnership(ActiveDirectoryRole role) throw new InvalidEnumArgumentException(nameof(role), (int)role, typeof(ActiveDirectoryRole)); } - DirectoryEntry roleObjectEntry = null; + DirectoryEntry? roleObjectEntry = null; try { roleObjectEntry = DirectoryEntryManager.GetDirectoryEntry(context, roleObjectDN); @@ -410,7 +410,7 @@ public void SeizeRoleOwnership(ActiveDirectoryRole role) // Increment the RIDAvailablePool by 30k. if (role == ActiveDirectoryRole.RidRole) { - System.DirectoryServices.Interop.UnsafeNativeMethods.IADsLargeInteger ridPool = (System.DirectoryServices.Interop.UnsafeNativeMethods.IADsLargeInteger)roleObjectEntry.Properties[PropertyManager.RIDAvailablePool].Value; + System.DirectoryServices.Interop.UnsafeNativeMethods.IADsLargeInteger ridPool = (System.DirectoryServices.Interop.UnsafeNativeMethods.IADsLargeInteger)roleObjectEntry.Properties[PropertyManager.RIDAvailablePool].Value!; // check the overflow of the low part if (ridPool.LowPart + UpdateRidPoolSeizureValue < ridPool.LowPart) @@ -630,11 +630,11 @@ public DateTime CurrentTime CheckIfDisposed(); DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string serverUTCTime = null; + string? serverUTCTime = null; try { - serverUTCTime = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.CurrentTime); + serverUTCTime = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.CurrentTime)!; } finally { @@ -651,11 +651,11 @@ public long HighestCommittedUsn CheckIfDisposed(); DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string serverHighestCommittedUsn = null; + string? serverHighestCommittedUsn = null; try { - serverHighestCommittedUsn = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.HighestCommittedUSN); + serverHighestCommittedUsn = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.HighestCommittedUSN)!; } finally { @@ -675,7 +675,7 @@ public string OSVersion // get the operating system version attribute DirectoryEntry computerEntry = directoryEntryMgr.GetCachedDirectoryEntry(ComputerObjectName); // is in the form Windows Server 2003 - _cachedOSVersion = (string)PropertyManager.GetPropertyValue(context, computerEntry, PropertyManager.OperatingSystem); + _cachedOSVersion = (string)PropertyManager.GetPropertyValue(context, computerEntry, PropertyManager.OperatingSystem)!; } return _cachedOSVersion; } @@ -692,7 +692,7 @@ internal double NumericOSVersion DirectoryEntry computerEntry = directoryEntryMgr.GetCachedDirectoryEntry(ComputerObjectName); // is in the form Windows Server 2003 - string osVersion = (string)PropertyManager.GetPropertyValue(context, computerEntry, PropertyManager.OperatingSystemVersion); + string osVersion = (string)PropertyManager.GetPropertyValue(context, computerEntry, PropertyManager.OperatingSystemVersion)!; // this could be in the form 5.2 (3790), so we need to take out the (3790) int index = osVersion.IndexOf('('); @@ -727,7 +727,7 @@ public Domain Domain CheckIfDisposed(); if (_cachedDomain == null) { - string domainName = null; + string? domainName = null; try { string defaultNCName = directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.DefaultNamingContext); @@ -747,7 +747,7 @@ public Domain Domain } } - public override string IPAddress + public override string? IPAddress { get { @@ -868,7 +868,7 @@ internal Guid NtdsaObjectGuid } } - public override SyncUpdateCallback SyncFromAllServersCallback + public override SyncUpdateCallback? SyncFromAllServersCallback { get { @@ -913,7 +913,7 @@ internal static void ValidateCredential(DomainController dc, DirectoryContext co de.Bind(true); } - internal static DomainController FindOneWithCredentialValidation(DirectoryContext context, string siteName, LocatorOptions flag) + internal static DomainController FindOneWithCredentialValidation(DirectoryContext context, string? siteName, LocatorOptions flag) { DomainController dc; bool retry = false; @@ -989,7 +989,7 @@ internal static DomainController FindOneWithCredentialValidation(DirectoryContex return dc; } - internal static DomainController FindOneInternal(DirectoryContext context, string domainName, string siteName, LocatorOptions flag) + internal static DomainController FindOneInternal(DirectoryContext context, string? domainName, string? siteName, LocatorOptions flag) { DomainControllerInfo domainControllerInfo; int errorCode = 0; @@ -1037,7 +1037,7 @@ internal static DomainController FindOneInternal(DirectoryContext context, strin return new DomainController(dcContext, domainControllerName); } - internal static DomainControllerCollection FindAllInternal(DirectoryContext context, string domainName, bool isDnsDomainName, string siteName) + internal static DomainControllerCollection FindAllInternal(DirectoryContext context, string? domainName, bool isDnsDomainName, string? siteName) { ArrayList dcList = new ArrayList(); @@ -1272,7 +1272,7 @@ private ArrayList GetRoles() // check if the role owner is this dc if (dsNameResultItem.status == NativeMethods.DsNameNoError) { - if (dsNameResultItem.name.Equals(NtdsaObjectName)) + if (dsNameResultItem.name!.Equals(NtdsaObjectName)) { // add this role to the array // the index of the item in the result signifies diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainControllerCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainControllerCollection.cs index 85884103c9838..cb6958b689d7d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainControllerCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DomainControllerCollection.cs @@ -17,7 +17,7 @@ internal DomainControllerCollection(ArrayList values) } } - public DomainController this[int index] => (DomainController)InnerList[index]; + public DomainController this[int index] => (DomainController)InnerList[index]!; public bool Contains(DomainController domainController) { @@ -26,7 +26,7 @@ public bool Contains(DomainController domainController) for (int i = 0; i < InnerList.Count; i++) { - DomainController tmp = (DomainController)InnerList[i]; + DomainController tmp = (DomainController)InnerList[i]!; if (Utils.Compare(tmp.Name, domainController.Name) == 0) { return true; @@ -42,7 +42,7 @@ public int IndexOf(DomainController domainController) for (int i = 0; i < InnerList.Count; i++) { - DomainController tmp = (DomainController)InnerList[i]; + DomainController tmp = (DomainController)InnerList[i]!; if (Utils.Compare(tmp.Name, domainController.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Exception.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Exception.cs index fe323f90d2a51..fd37da0e8bf3d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Exception.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Exception.cs @@ -11,7 +11,7 @@ namespace System.DirectoryServices.ActiveDirectory { public class SyncFromAllServersErrorInformation { - internal SyncFromAllServersErrorInformation(SyncFromAllServersErrorCategory category, int errorCode, string errorMessage, string sourceServer, string targetServer) + internal SyncFromAllServersErrorInformation(SyncFromAllServersErrorCategory category, int errorCode, string errorMessage, string? sourceServer, string? targetServer) { ErrorCategory = category; ErrorCode = errorCode; @@ -26,24 +26,24 @@ internal SyncFromAllServersErrorInformation(SyncFromAllServersErrorCategory cate public string ErrorMessage { get; } - public string TargetServer { get; } + public string? TargetServer { get; } - public string SourceServer { get; } + public string? SourceServer { get; } } [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ActiveDirectoryObjectNotFoundException : Exception, ISerializable { - public ActiveDirectoryObjectNotFoundException(string message, Type type, string name) : base(message) + public ActiveDirectoryObjectNotFoundException(string? message, Type? type, string? name) : base(message) { Type = type; Name = name; } - public ActiveDirectoryObjectNotFoundException(string message, Exception inner) : base(message, inner) { } + public ActiveDirectoryObjectNotFoundException(string? message, Exception? inner) : base(message, inner) { } - public ActiveDirectoryObjectNotFoundException(string message) : base(message) { } + public ActiveDirectoryObjectNotFoundException(string? message) : base(message) { } public ActiveDirectoryObjectNotFoundException() : base() { } @@ -51,9 +51,9 @@ protected ActiveDirectoryObjectNotFoundException(SerializationInfo info, Streami { } - public Type Type { get; } + public Type? Type { get; } - public string Name { get; } + public string? Name { get; } public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { @@ -79,19 +79,19 @@ public override string Message [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ActiveDirectoryOperationException : Exception, ISerializable { - public ActiveDirectoryOperationException(string message, Exception inner, int errorCode) : base(message, inner) + public ActiveDirectoryOperationException(string? message, Exception? inner, int errorCode) : base(message, inner) { ErrorCode = errorCode; } - public ActiveDirectoryOperationException(string message, int errorCode) : base(message) + public ActiveDirectoryOperationException(string? message, int errorCode) : base(message) { ErrorCode = errorCode; } - public ActiveDirectoryOperationException(string message, Exception inner) : base(message, inner) { } + public ActiveDirectoryOperationException(string? message, Exception? inner) : base(message, inner) { } - public ActiveDirectoryOperationException(string message) : base(message) { } + public ActiveDirectoryOperationException(string? message) : base(message) { } public ActiveDirectoryOperationException() : base(SR.DSUnknownFailure) { } @@ -111,21 +111,21 @@ public override void GetObjectData(SerializationInfo serializationInfo, Streamin [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ActiveDirectoryServerDownException : Exception, ISerializable { - public ActiveDirectoryServerDownException(string message, Exception inner, int errorCode, string name) : base(message, inner) + public ActiveDirectoryServerDownException(string? message, Exception? inner, int errorCode, string? name) : base(message, inner) { ErrorCode = errorCode; Name = name; } - public ActiveDirectoryServerDownException(string message, int errorCode, string name) : base(message) + public ActiveDirectoryServerDownException(string? message, int errorCode, string? name) : base(message) { ErrorCode = errorCode; Name = name; } - public ActiveDirectoryServerDownException(string message, Exception inner) : base(message, inner) { } + public ActiveDirectoryServerDownException(string? message, Exception? inner) : base(message, inner) { } - public ActiveDirectoryServerDownException(string message) : base(message) { } + public ActiveDirectoryServerDownException(string? message) : base(message) { } public ActiveDirectoryServerDownException() : base() { } @@ -135,7 +135,7 @@ protected ActiveDirectoryServerDownException(SerializationInfo info, StreamingCo public int ErrorCode { get; } - public string Name { get; } + public string? Name { get; } public override string Message { @@ -160,9 +160,9 @@ public override void GetObjectData(SerializationInfo serializationInfo, Streamin [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ActiveDirectoryObjectExistsException : Exception { - public ActiveDirectoryObjectExistsException(string message, Exception inner) : base(message, inner) { } + public ActiveDirectoryObjectExistsException(string? message, Exception? inner) : base(message, inner) { } - public ActiveDirectoryObjectExistsException(string message) : base(message) { } + public ActiveDirectoryObjectExistsException(string? message) : base(message) { } public ActiveDirectoryObjectExistsException() : base() { } @@ -175,16 +175,16 @@ protected ActiveDirectoryObjectExistsException(SerializationInfo info, Streaming [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class SyncFromAllServersOperationException : ActiveDirectoryOperationException, ISerializable { - private readonly SyncFromAllServersErrorInformation[] _errors; + private readonly SyncFromAllServersErrorInformation[]? _errors; - public SyncFromAllServersOperationException(string message, Exception inner, SyncFromAllServersErrorInformation[] errors) : base(message, inner) + public SyncFromAllServersOperationException(string? message, Exception? inner, SyncFromAllServersErrorInformation[]? errors) : base(message, inner) { _errors = errors; } - public SyncFromAllServersOperationException(string message, Exception inner) : base(message, inner) { } + public SyncFromAllServersOperationException(string? message, Exception? inner) : base(message, inner) { } - public SyncFromAllServersOperationException(string message) : base(message) { } + public SyncFromAllServersOperationException(string? message) : base(message) { } public SyncFromAllServersOperationException() : base(SR.DSSyncAllFailure) { } @@ -217,14 +217,14 @@ public override void GetObjectData(SerializationInfo serializationInfo, Streamin [System.Runtime.CompilerServices.TypeForwardedFrom("System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ForestTrustCollisionException : ActiveDirectoryOperationException, ISerializable { - public ForestTrustCollisionException(string message, Exception inner, ForestTrustRelationshipCollisionCollection collisions) : base(message, inner) + public ForestTrustCollisionException(string? message, Exception? inner, ForestTrustRelationshipCollisionCollection? collisions) : base(message, inner) { Collisions = collisions; } - public ForestTrustCollisionException(string message, Exception inner) : base(message, inner) { } + public ForestTrustCollisionException(string? message, Exception? inner) : base(message, inner) { } - public ForestTrustCollisionException(string message) : base(message) { } + public ForestTrustCollisionException(string? message) : base(message) { } public ForestTrustCollisionException() : base(SR.ForestTrustCollision) { } @@ -232,7 +232,7 @@ protected ForestTrustCollisionException(SerializationInfo info, StreamingContext { } - public ForestTrustRelationshipCollisionCollection Collisions { get; } = new ForestTrustRelationshipCollisionCollection(); + public ForestTrustRelationshipCollisionCollection? Collisions { get; } = new ForestTrustRelationshipCollisionCollection(); public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { @@ -267,7 +267,7 @@ internal static Exception GetExceptionFromCOMException(COMException e) return GetExceptionFromCOMException(null, e); } - internal static Exception GetExceptionFromCOMException(DirectoryContext context, COMException e) + internal static Exception GetExceptionFromCOMException(DirectoryContext? context, COMException e) { Exception exception; int errorCode = e.ErrorCode; @@ -349,7 +349,7 @@ internal static Exception GetExceptionFromErrorCode(int errorCode) return GetExceptionFromErrorCode(errorCode, null); } - internal static Exception GetExceptionFromErrorCode(int errorCode, string targetName) + internal static Exception GetExceptionFromErrorCode(int errorCode, string? targetName) { string errorMsg = GetErrorMessage(errorCode, false); @@ -382,7 +382,7 @@ internal static string GetErrorMessage(int errorCode, bool hresult) return new Win32Exception((int)temp).Message; } - internal static SyncFromAllServersOperationException CreateSyncAllException(IntPtr errorInfo, bool singleError) + internal static SyncFromAllServersOperationException? CreateSyncAllException(IntPtr errorInfo, bool singleError) { if (errorInfo == (IntPtr)0) return new SyncFromAllServersOperationException(); @@ -393,8 +393,8 @@ internal static SyncFromAllServersOperationException CreateSyncAllException(IntP DS_REPSYNCALL_ERRINFO error = new DS_REPSYNCALL_ERRINFO(); Marshal.PtrToStructure(errorInfo, error); string message = GetErrorMessage(error.dwWin32Err, false); - string source = Marshal.PtrToStringUni(error.pszSrcId); - string target = Marshal.PtrToStringUni(error.pszSvrId); + string? source = Marshal.PtrToStringUni(error.pszSrcId); + string? target = Marshal.PtrToStringUni(error.pszSvrId); if (error.dwWin32Err == ERROR_CANCELLED) { @@ -421,8 +421,8 @@ internal static SyncFromAllServersOperationException CreateSyncAllException(IntP if (error.dwWin32Err != ERROR_CANCELLED) { string message = GetErrorMessage(error.dwWin32Err, false); - string source = Marshal.PtrToStringUni(error.pszSrcId); - string target = Marshal.PtrToStringUni(error.pszSvrId); + string? source = Marshal.PtrToStringUni(error.pszSrcId); + string? target = Marshal.PtrToStringUni(error.pszSvrId); SyncFromAllServersErrorInformation managedError = new SyncFromAllServersErrorInformation(error.error, error.dwWin32Err, message, source, target); errorList.Add(managedError); @@ -438,7 +438,7 @@ internal static SyncFromAllServersOperationException CreateSyncAllException(IntP SyncFromAllServersErrorInformation[] info = new SyncFromAllServersErrorInformation[errorList.Count]; for (int j = 0; j < errorList.Count; j++) { - SyncFromAllServersErrorInformation tmp = (SyncFromAllServersErrorInformation)errorList[j]; + SyncFromAllServersErrorInformation tmp = (SyncFromAllServersErrorInformation)errorList[j]!; info[j] = new SyncFromAllServersErrorInformation(tmp.ErrorCategory, tmp.ErrorCode, tmp.ErrorMessage, tmp.SourceServer, tmp.TargetServer); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Forest.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Forest.cs index b108641eb6611..bee105b811159 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Forest.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Forest.cs @@ -31,15 +31,15 @@ public class Forest : IDisposable // Internal variables corresponding to public properties private readonly string _forestDnsName; - private ReadOnlySiteCollection _cachedSites; - private DomainCollection _cachedDomains; - private GlobalCatalogCollection _cachedGlobalCatalogs; - private ApplicationPartitionCollection _cachedApplicationPartitions; + private ReadOnlySiteCollection? _cachedSites; + private DomainCollection? _cachedDomains; + private GlobalCatalogCollection? _cachedGlobalCatalogs; + private ApplicationPartitionCollection? _cachedApplicationPartitions; private int _forestModeLevel = -1; - private Domain _cachedRootDomain; - private ActiveDirectorySchema _cachedSchema; - private DomainController _cachedSchemaRoleOwner; - private DomainController _cachedNamingRoleOwner; + private Domain? _cachedRootDomain; + private ActiveDirectorySchema? _cachedSchema; + private DomainController? _cachedSchemaRoleOwner; + private DomainController? _cachedNamingRoleOwner; #region constructors internal Forest(DirectoryContext context, string forestDnsName, DirectoryEntryManager directoryEntryMgr) @@ -83,9 +83,9 @@ protected void Dispose(bool disposing) public static Forest GetForest(DirectoryContext context) { - DirectoryEntryManager directoryEntryMgr = null; - DirectoryEntry rootDSE = null; - string rootDomainNC = null; + DirectoryEntryManager? directoryEntryMgr = null; + DirectoryEntry? rootDSE = null; + string? rootDomainNC = null; // check that the argument is not null if (context == null) @@ -133,7 +133,7 @@ public static Forest GetForest(DirectoryContext context) { throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.DCNotFound, context.Name), typeof(Forest), null); } - rootDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext); + rootDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext)!; } catch (COMException e) { @@ -805,7 +805,7 @@ private int GetForestModeLevel() } else { - forestModeValue = int.Parse((string)rootDSE.Properties[PropertyManager.ForestFunctionality].Value, NumberFormatInfo.InvariantInfo); + forestModeValue = int.Parse((string)rootDSE.Properties[PropertyManager.ForestFunctionality].Value!, NumberFormatInfo.InvariantInfo); } } catch (COMException e) @@ -824,8 +824,8 @@ private int GetForestModeLevel() // private DomainController GetRoleOwner(ActiveDirectoryRole role) { - DirectoryEntry entry = null; - string dcName = null; + DirectoryEntry? entry = null; + string? dcName = null; try { @@ -849,7 +849,7 @@ private DomainController GetRoleOwner(ActiveDirectoryRole role) break; } - dcName = Utils.GetDnsHostNameFromNTDSA(_context, (string)PropertyManager.GetPropertyValue(_context, entry, PropertyManager.FsmoRoleOwner)); + dcName = Utils.GetDnsHostNameFromNTDSA(_context, (string)PropertyManager.GetPropertyValue(_context, entry, PropertyManager.FsmoRoleOwner)!); } catch (COMException e) { @@ -907,7 +907,7 @@ private ArrayList GetSites() Marshal.PtrToStructure(currentItem, dsNameResultItem); if (dsNameResultItem.status == NativeMethods.DsNameNoError) { - string siteName = Utils.GetDNComponents(dsNameResultItem.name)[0].Value; + string siteName = Utils.GetDNComponents(dsNameResultItem.name!)[0].Value!; // an existing site sites.Add(new ActiveDirectorySite(_context, siteName, true)); } @@ -986,7 +986,7 @@ private ArrayList GetApplicationPartitions() propertiesToLoad[1] = PropertyManager.NCName; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { resCol = searcher.FindAll(); @@ -998,15 +998,15 @@ private ArrayList GetApplicationPartitions() { // add the name of the appNC only if it is not // the Schema or Configuration partition - string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName); + string nCName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName)!; if ((!(nCName.Equals(schemaNamingContext))) && (!(nCName.Equals(configurationNamingContext)))) { // create a new context to be passed on to the appNC object // (pass the dns name of the appliction partition as the target) - string dnsName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot); + string dnsName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot)!; DirectoryContext appNCContext = Utils.GetNewDirectoryContext(dnsName, DirectoryContextType.ApplicationPartition, _context); - appNCs.Add(new ApplicationPartition(appNCContext, nCName, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot), ApplicationPartitionType.ADApplicationPartition, new DirectoryEntryManager(appNCContext))); + appNCs.Add(new ApplicationPartition(appNCContext, nCName, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot)!, ApplicationPartitionType.ADApplicationPartition, new DirectoryEntryManager(appNCContext))); } } } @@ -1055,14 +1055,14 @@ private ArrayList GetDomains() propertiesToLoad[0] = PropertyManager.DnsRoot; ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; try { resCol = searcher.FindAll(); foreach (SearchResult res in resCol) { - string domainName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot); + string domainName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsRoot)!; DirectoryContext domainContext = Utils.GetNewDirectoryContext(domainName, DirectoryContextType.Domain, _context); domains.Add(new Domain(domainContext, domainName)); } @@ -1105,9 +1105,9 @@ private void CheckIfDisposed() } } - private TrustRelationshipInformationCollection GetTrustsHelper(string targetForestName) + private TrustRelationshipInformationCollection GetTrustsHelper(string? targetForestName) { - string serverName = null; + string? serverName = null; IntPtr domains = (IntPtr)0; int count = 0; TrustRelationshipInformationCollection collection = new TrustRelationshipInformationCollection(); @@ -1155,8 +1155,8 @@ private TrustRelationshipInformationCollection GetTrustsHelper(string targetFore if (targetForestName != null) { bool sameTarget = false; - string tmpDNSName = null; - string tmpNetBIOSName = null; + string? tmpDNSName = null; + string? tmpNetBIOSName = null; if (unmanagedTrust.DnsDomainName != (IntPtr)0) tmpDNSName = Marshal.PtrToStringUni(unmanagedTrust.DnsDomainName); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustCollision.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustCollision.cs index e1ac191c7f32f..6e6f98ac3af60 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustCollision.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustCollision.cs @@ -30,7 +30,7 @@ internal ForestTrustRelationshipCollisionCollection() { } public ForestTrustRelationshipCollision this[int index] { - get => (ForestTrustRelationshipCollision)InnerList[index]; + get => (ForestTrustRelationshipCollision)InnerList[index]!; } public bool Contains(ForestTrustRelationshipCollision collision) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInfoCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInfoCollection.cs index f75f66038aaa6..062f14dd41991 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInfoCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInfoCollection.cs @@ -11,7 +11,7 @@ internal ForestTrustDomainInfoCollection() { } public ForestTrustDomainInformation this[int index] { - get => (ForestTrustDomainInformation)InnerList[index]; + get => (ForestTrustDomainInformation)InnerList[index]!; } public bool Contains(ForestTrustDomainInformation information) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInformation.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInformation.cs index f8f69ab9039a8..1b418b8252f14 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInformation.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustDomainInformation.cs @@ -34,7 +34,7 @@ internal ForestTrustDomainInformation(int flag, LSA_FOREST_TRUST_DOMAIN_INFO dom try { - DomainSid = Marshal.PtrToStringUni(ptr); + DomainSid = Marshal.PtrToStringUni(ptr)!; } finally { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustRelationshipInformation.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustRelationshipInformation.cs index 9607bf5d609fc..ae2ccd4144752 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustRelationshipInformation.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ForestTrustRelationshipInformation.cs @@ -19,8 +19,8 @@ public class ForestTrustRelationshipInformation : TrustRelationshipInformation internal ForestTrustRelationshipInformation(DirectoryContext context, string source, DS_DOMAIN_TRUSTS unmanagedTrust, TrustType type) { - string tmpDNSName = null; - string tmpNetBIOSName = null; + string? tmpDNSName = null; + string? tmpNetBIOSName = null; // security context this.context = context; @@ -82,14 +82,14 @@ public void Save() int currentCount = 0; IntPtr tmpPtr = (IntPtr)0; IntPtr forestInfo = (IntPtr)0; - PolicySafeHandle handle = null; + PolicySafeHandle? handle = null; LSA_UNICODE_STRING trustedDomainName; IntPtr collisionInfo = (IntPtr)0; ArrayList ptrList = new ArrayList(); ArrayList sidList = new ArrayList(); bool impersonated = false; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; IntPtr fileTime = (IntPtr)0; // first get the count of all the records @@ -155,9 +155,9 @@ public void Save() LSA_FOREST_TRUST_RECORD record = new LSA_FOREST_TRUST_RECORD(); record.Flags = 0; record.ForestTrustType = LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelNameEx; - if (_excludedNameTime.Contains(_excludedNames[i])) + if (_excludedNameTime.Contains(_excludedNames[i]!)) { - record.Time = (LARGE_INTEGER)_excludedNameTime[i]; + record.Time = (LARGE_INTEGER)_excludedNameTime[i]!; } else { @@ -232,8 +232,8 @@ public void Save() // now begin to construct excluded top leve name record LSA_FOREST_TRUST_RECORD record = new LSA_FOREST_TRUST_RECORD(); record.Flags = 0; - record.Time = (LARGE_INTEGER)_binaryDataTime[i]; - record.Data.Length = ((byte[])_binaryData[i]).Length; + record.Time = (LARGE_INTEGER)_binaryDataTime[i]!; + record.Data.Length = ((byte[])_binaryData[i]!).Length; if (record.Data.Length == 0) { record.Data.Buffer = (IntPtr)0; @@ -242,7 +242,7 @@ public void Save() { record.Data.Buffer = Marshal.AllocHGlobal(record.Data.Length); ptrList.Add(record.Data.Buffer); - Marshal.Copy((byte[])_binaryData[i], 0, record.Data.Buffer, record.Data.Length); + Marshal.Copy((byte[])_binaryData[i]!, 0, record.Data.Buffer, record.Data.Length); } tmpPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LSA_FOREST_TRUST_RECORD))); ptrList.Add(tmpPtr); @@ -306,12 +306,12 @@ public void Save() // release the memory for (int i = 0; i < ptrList.Count; i++) { - Marshal.FreeHGlobal((IntPtr)ptrList[i]); + Marshal.FreeHGlobal((IntPtr)ptrList[i]!); } for (int i = 0; i < sidList.Count; i++) { - UnsafeNativeMethods.LocalFree((IntPtr)sidList[i]); + UnsafeNativeMethods.LocalFree((IntPtr)sidList[i]!); } if (records != (IntPtr)0) @@ -340,11 +340,11 @@ public void Save() private void GetForestTrustInfoHelper() { IntPtr forestTrustInfo = (IntPtr)0; - PolicySafeHandle handle = null; - LSA_UNICODE_STRING tmpName = null; + PolicySafeHandle? handle = null; + LSA_UNICODE_STRING? tmpName = null; bool impersonated = false; IntPtr targetPtr = (IntPtr)0; - string serverName = null; + string? serverName = null; TopLevelNameCollection tmpTLNs = new TopLevelNameCollection(); StringCollection tmpExcludedTLNs = new StringCollection(); @@ -416,7 +416,7 @@ private void GetForestTrustInfoHelper() } else if (record.ForestTrustType == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustDomainInfo) { - ForestTrustDomainInformation dom = new ForestTrustDomainInformation(record.Flags, record.DomainInfo, record.Time); + ForestTrustDomainInformation dom = new ForestTrustDomainInformation(record.Flags, record.DomainInfo!, record.Time); tmpDomainInformation.Add(dom); } else if (record.ForestTrustType == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustRecordTypeLast) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalog.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalog.cs index 8a2d291a0d387..a9428286fc526 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalog.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalog.cs @@ -10,7 +10,7 @@ namespace System.DirectoryServices.ActiveDirectory public class GlobalCatalog : DomainController { // private variables - private ActiveDirectorySchema _schema; + private ActiveDirectorySchema? _schema; private bool _disabled; #region constructors @@ -27,9 +27,9 @@ internal GlobalCatalog(DirectoryContext context, string globalCatalogName, Direc public static GlobalCatalog GetGlobalCatalog(DirectoryContext context) { - string gcDnsName = null; + string? gcDnsName = null; bool isGlobalCatalog = false; - DirectoryEntryManager directoryEntryMgr = null; + DirectoryEntryManager? directoryEntryMgr = null; // check that the context argument is not null if (context == null) @@ -62,8 +62,8 @@ public static GlobalCatalog GetGlobalCatalog(DirectoryContext context) throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.GCNotFound, context.Name), typeof(GlobalCatalog), context.Name); } - gcDnsName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName); - isGlobalCatalog = (bool)bool.Parse((string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.IsGlobalCatalogReady)); + gcDnsName = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DnsHostName)!; + isGlobalCatalog = (bool)bool.Parse((string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.IsGlobalCatalogReady)!); if (!isGlobalCatalog) { throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.GCNotFound, context.Name), typeof(GlobalCatalog), context.Name); @@ -218,7 +218,7 @@ public DomainController DisableGlobalCatalog() { if (serverNtdsaEntry.Properties[PropertyManager.Options].Value != null) { - options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value; + options = (int)serverNtdsaEntry.Properties[PropertyManager.Options].Value!; } serverNtdsaEntry.Properties[PropertyManager.Options].Value = options & (~1); @@ -253,7 +253,7 @@ public ReadOnlyActiveDirectorySchemaPropertyCollection FindAllProperties() // create an ActiveDirectorySchema object if (_schema == null) { - string schemaNC = null; + string? schemaNC = null; try { schemaNC = directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.SchemaNamingContext); @@ -290,7 +290,7 @@ private void CheckIfDisabled() } } - internal static new GlobalCatalog FindOneWithCredentialValidation(DirectoryContext context, string siteName, LocatorOptions flag) + internal static new GlobalCatalog FindOneWithCredentialValidation(DirectoryContext context, string? siteName, LocatorOptions flag) { GlobalCatalog gc; bool retry = false; @@ -366,7 +366,7 @@ private void CheckIfDisabled() return gc; } - internal static new GlobalCatalog FindOneInternal(DirectoryContext context, string forestName, string siteName, LocatorOptions flag) + internal static new GlobalCatalog FindOneInternal(DirectoryContext context, string? forestName, string? siteName, LocatorOptions flag) { DomainControllerInfo domainControllerInfo; int errorCode = 0; @@ -430,7 +430,7 @@ private void CheckIfDisabled() return new GlobalCatalog(gcContext, globalCatalogName); } - internal static GlobalCatalogCollection FindAllInternal(DirectoryContext context, string siteName) + internal static GlobalCatalogCollection FindAllInternal(DirectoryContext context, string? siteName) { ArrayList gcList = new ArrayList(); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalogCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalogCollection.cs index 1f82854c42dc9..16f9d34bbe28b 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalogCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/GlobalCatalogCollection.cs @@ -17,7 +17,7 @@ internal GlobalCatalogCollection(ArrayList values) } } - public GlobalCatalog this[int index] => (GlobalCatalog)InnerList[index]; + public GlobalCatalog this[int index] => (GlobalCatalog)InnerList[index]!; public bool Contains(GlobalCatalog globalCatalog) { @@ -26,7 +26,7 @@ public bool Contains(GlobalCatalog globalCatalog) for (int i = 0; i < InnerList.Count; i++) { - GlobalCatalog tmp = (GlobalCatalog)InnerList[i]; + GlobalCatalog tmp = (GlobalCatalog)InnerList[i]!; if (Utils.Compare(tmp.Name, globalCatalog.Name) == 0) { return true; @@ -42,7 +42,7 @@ public int IndexOf(GlobalCatalog globalCatalog) for (int i = 0; i < InnerList.Count; i++) { - GlobalCatalog tmp = (GlobalCatalog)InnerList[i]; + GlobalCatalog tmp = (GlobalCatalog)InnerList[i]!; if (Utils.Compare(tmp.Name, globalCatalog.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Locator.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Locator.cs index 07d17ee6b36b3..76c5e4376f972 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Locator.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Locator.cs @@ -12,7 +12,7 @@ internal sealed class Locator // To disable public/protected constructors for this class private Locator() { } - internal static DomainControllerInfo GetDomainControllerInfo(string computerName, string domainName, string siteName, long flags) + internal static DomainControllerInfo GetDomainControllerInfo(string? computerName, string? domainName, string? siteName, long flags) { int errorCode = 0; DomainControllerInfo domainControllerInfo; @@ -27,7 +27,7 @@ internal static DomainControllerInfo GetDomainControllerInfo(string computerName return domainControllerInfo; } - internal static int DsGetDcNameWrapper(string computerName, string domainName, string siteName, long flags, out DomainControllerInfo domainControllerInfo) + internal static int DsGetDcNameWrapper(string? computerName, string? domainName, string? siteName, long flags, out DomainControllerInfo domainControllerInfo) { IntPtr pDomainControllerInfo = IntPtr.Zero; int result = 0; @@ -69,9 +69,9 @@ internal static int DsGetDcNameWrapper(string computerName, string domainName, s return result; } - internal static ArrayList EnumerateDomainControllers(DirectoryContext context, string domainName, string siteName, long dcFlags) + internal static ArrayList EnumerateDomainControllers(DirectoryContext context, string? domainName, string? siteName, long dcFlags) { - Hashtable allDCs = null; + Hashtable? allDCs = null; ArrayList dcs = new ArrayList(); // @@ -126,7 +126,7 @@ internal static ArrayList EnumerateDomainControllers(DirectoryContext context, s return dcs; } - private static Hashtable DnsGetDcWrapper(string domainName, string siteName, long dcFlags) + private static Hashtable DnsGetDcWrapper(string? domainName, string? siteName, long dcFlags) { Hashtable domainControllers = new Hashtable(); @@ -136,7 +136,7 @@ private static Hashtable DnsGetDcWrapper(string domainName, string siteName, lon int sockAddressCount = 0; IntPtr sockAddressCountPtr = new IntPtr(sockAddressCount); IntPtr sockAddressList = IntPtr.Zero; - string dcDnsHostName = null; + string? dcDnsHostName = null; int result = 0; result = NativeMethods.DsGetDcOpen(domainName, (int)optionFlags, siteName, IntPtr.Zero, null, (int)dcFlags, out retGetDcContext); @@ -157,7 +157,7 @@ private static Hashtable DnsGetDcWrapper(string domainName, string siteName, lon { try { - dcDnsHostName = Marshal.PtrToStringUni(dcDnsHostNamePtr); + dcDnsHostName = Marshal.PtrToStringUni(dcDnsHostNamePtr)!; string key = dcDnsHostName.ToLowerInvariant(); if (!domainControllers.Contains(key)) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/NativeMethods.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/NativeMethods.cs index 8027a68b39d01..d1d75787248f8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/NativeMethods.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/NativeMethods.cs @@ -21,15 +21,15 @@ namespace System.DirectoryServices.ActiveDirectory [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal sealed class DomainControllerInfo { - public string DomainControllerName; - public string DomainControllerAddress; + public string DomainControllerName = null!; + public string? DomainControllerAddress; public int DomainControllerAddressType; public Guid DomainGuid; - public string DomainName; - public string DnsForestName; + public string? DomainName; + public string? DnsForestName; public int Flags; - public string DcSiteName; - public string ClientSiteName; + public string? DcSiteName; + public string? ClientSiteName; } /*typedef struct { @@ -51,13 +51,13 @@ internal sealed class DomainControllerInfo [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal sealed class DsDomainControllerInfo2 { - public string netBiosName; - public string dnsHostName; - public string siteName; - public string siteObjectName; - public string computerObjectName; - public string serverObjectName; - public string ntdsaObjectName; + public string? netBiosName; + public string? dnsHostName; + public string? siteName; + public string? siteObjectName; + public string? computerObjectName; + public string? serverObjectName; + public string? ntdsaObjectName; public bool isPdc; public bool dsEnabled; public bool isGC; @@ -87,13 +87,13 @@ internal sealed class DsDomainControllerInfo2 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal sealed class DsDomainControllerInfo3 { - public string netBiosName; - public string dnsHostName; - public string siteName; - public string siteObjectName; - public string computerObjectName; - public string serverObjectName; - public string ntdsaObjectName; + public string? netBiosName; + public string? dnsHostName; + public string? siteName; + public string? siteObjectName; + public string? computerObjectName; + public string? serverObjectName; + public string? ntdsaObjectName; public bool isPdc; public bool dsEnabled; public bool isGC; @@ -124,8 +124,8 @@ internal sealed class DsNameResult internal sealed class DsNameResultItem { public int status; - public string domain; - public string name; + public string? domain; + public string? name; } /*typedef struct _DnsRecord { @@ -181,20 +181,20 @@ struct _DnsRecord * pNext; internal sealed class DnsRecord { public IntPtr next; - public string name; + public string? name; public short type; public short dataLength; public int flags; public int ttl; public int reserved; - public DnsSrvData data; + public DnsSrvData data = null!; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal sealed class PartialDnsRecord { public IntPtr next; - public string name; + public string? name; public short type; public short dataLength; public int flags; @@ -213,7 +213,7 @@ internal sealed class PartialDnsRecord [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal sealed class DnsSrvData { - public string targetName; + public string targetName = null!; public short priority; public short weight; public short port; @@ -248,7 +248,7 @@ public OSVersionInfoEx() public int buildNumber; public int platformId; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] - public string csdVersion = null; + public string? csdVersion = null; public short servicePackMajor; public short servicePackMinor; public short suiteMask; @@ -275,7 +275,7 @@ internal sealed class LUID internal sealed class NegotiateCallerNameRequest { public int messageType; - public LUID logonId; + public LUID? logonId; } /*typedef struct _NEGOTIATE_CALLER_NAME_RESPONSE { @@ -286,7 +286,7 @@ internal sealed class NegotiateCallerNameRequest internal sealed class NegotiateCallerNameResponse { public int messageType; - public string callerName; + public string? callerName; } internal sealed class NativeMethods @@ -322,10 +322,10 @@ private NativeMethods() { } );*/ [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNameW", CharSet = CharSet.Unicode)] internal static extern int DsGetDcName( - [In] string computerName, - [In] string domainName, + [In] string? computerName, + [In] string? domainName, [In] IntPtr domainGuid, - [In] string siteName, + [In] string? siteName, [In] int flags, [Out] out IntPtr domainControllerInfo); @@ -340,11 +340,11 @@ PHANDLE RetGetDcContext );*/ [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcOpenW", CharSet = CharSet.Unicode)] internal static extern int DsGetDcOpen( - [In] string dnsName, + [In] string? dnsName, [In] int optionFlags, - [In] string siteName, + [In] string? siteName, [In] IntPtr domainGuid, - [In] string dnsForestName, + [In] string? dnsForestName, [In] int dcFlags, [Out] out IntPtr retGetDcContext); @@ -383,9 +383,9 @@ internal static extern int NetApiBufferFree( );*/ internal delegate int DsMakePasswordCredentials( - [MarshalAs(UnmanagedType.LPWStr)] string user, - [MarshalAs(UnmanagedType.LPWStr)] string domain, - [MarshalAs(UnmanagedType.LPWStr)] string password, + [MarshalAs(UnmanagedType.LPWStr)] string? user, + [MarshalAs(UnmanagedType.LPWStr)] string? domain, + [MarshalAs(UnmanagedType.LPWStr)] string? password, [Out] out IntPtr authIdentity); /*VOID DsFreePasswordCredentials( @@ -401,8 +401,8 @@ internal delegate void DsFreePasswordCredentials( HANDLE* phDS );*/ internal delegate int DsBindWithCred( - [MarshalAs(UnmanagedType.LPWStr)] string domainController, - [MarshalAs(UnmanagedType.LPWStr)] string dnsDomainName, + [MarshalAs(UnmanagedType.LPWStr)] string? domainController, + [MarshalAs(UnmanagedType.LPWStr)] string? dnsDomainName, [In] IntPtr authIdentity, [Out] out IntPtr handle); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs index d0ed5fbad39c8..9a4b9ef1129fb 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs @@ -124,12 +124,12 @@ internal class PropertyManager #pragma warning restore 0414 public static string MsDSHasInstantiatedNCs = "msDS-HasInstantiatedNCs"; - public static object GetPropertyValue(DirectoryEntry directoryEntry, string propertyName) + public static object? GetPropertyValue(DirectoryEntry directoryEntry, string propertyName) { return GetPropertyValue(null, directoryEntry, propertyName); } - public static object GetPropertyValue(DirectoryContext context, DirectoryEntry directoryEntry, string propertyName) + public static object? GetPropertyValue(DirectoryContext? context, DirectoryEntry directoryEntry, string propertyName) { Debug.Assert(directoryEntry != null, "PropertyManager::GetPropertyValue - directoryEntry is null"); @@ -157,13 +157,13 @@ public static object GetPropertyValue(DirectoryContext context, DirectoryEntry d return directoryEntry.Properties[propertyName].Value; } - public static object GetSearchResultPropertyValue(SearchResult res, string propertyName) + public static object? GetSearchResultPropertyValue(SearchResult res, string propertyName) { Debug.Assert(res != null, "PropertyManager::GetSearchResultPropertyValue - res is null"); Debug.Assert(propertyName != null, "PropertyManager::GetSearchResultPropertyValue - propertyName is null"); - ResultPropertyValueCollection propertyValues = null; + ResultPropertyValueCollection? propertyValues = null; try { propertyValues = res.Properties[propertyName]; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaClassCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaClassCollection.cs index bb181511f65eb..38cebbfe6642e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaClassCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaClassCollection.cs @@ -19,7 +19,7 @@ internal ReadOnlyActiveDirectorySchemaClassCollection(ICollection values) public ActiveDirectorySchemaClass this[int index] { - get => (ActiveDirectorySchemaClass)InnerList[index]; + get => (ActiveDirectorySchemaClass)InnerList[index]!; } public bool Contains(ActiveDirectorySchemaClass schemaClass) @@ -29,7 +29,7 @@ public bool Contains(ActiveDirectorySchemaClass schemaClass) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]; + ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaClass.Name) == 0) { return true; @@ -45,7 +45,7 @@ public int IndexOf(ActiveDirectorySchemaClass schemaClass) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]; + ActiveDirectorySchemaClass tmp = (ActiveDirectorySchemaClass)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaClass.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaPropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaPropertyCollection.cs index cdffa0bdab5fb..07c6e424d2242 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaPropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyActiveDirectorySchemaPropertyCollection.cs @@ -19,7 +19,7 @@ internal ReadOnlyActiveDirectorySchemaPropertyCollection(ArrayList values) public ActiveDirectorySchemaProperty this[int index] { - get => (ActiveDirectorySchemaProperty)InnerList[index]; + get => (ActiveDirectorySchemaProperty)InnerList[index]!; } public bool Contains(ActiveDirectorySchemaProperty schemaProperty) @@ -28,7 +28,7 @@ public bool Contains(ActiveDirectorySchemaProperty schemaProperty) throw new ArgumentNullException(nameof(schemaProperty)); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0) { return true; @@ -44,7 +44,7 @@ public int IndexOf(ActiveDirectorySchemaProperty schemaProperty) for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]; + ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i]!; if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyDirectoryServerCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyDirectoryServerCollection.cs index 54723e37d666c..58c894940ede6 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyDirectoryServerCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyDirectoryServerCollection.cs @@ -15,12 +15,12 @@ internal ReadOnlyDirectoryServerCollection(ArrayList values) { for (int i = 0; i < values.Count; i++) { - Add((DirectoryServer)values[i]); + Add((DirectoryServer)values[i]!); } } } - public DirectoryServer this[int index] => (DirectoryServer)InnerList[index]; + public DirectoryServer this[int index] => (DirectoryServer)InnerList[index]!; public bool Contains(DirectoryServer directoryServer) { @@ -29,7 +29,7 @@ public bool Contains(DirectoryServer directoryServer) for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer tmp = (DirectoryServer)InnerList[i]; + DirectoryServer tmp = (DirectoryServer)InnerList[i]!; if (Utils.Compare(tmp.Name, directoryServer.Name) == 0) { return true; @@ -45,7 +45,7 @@ public int IndexOf(DirectoryServer directoryServer) for (int i = 0; i < InnerList.Count; i++) { - DirectoryServer tmp = (DirectoryServer)InnerList[i]; + DirectoryServer tmp = (DirectoryServer)InnerList[i]!; if (Utils.Compare(tmp.Name, directoryServer.Name) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteCollection.cs index 09abb4f3023fe..4c87183f74335 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteCollection.cs @@ -13,24 +13,24 @@ internal ReadOnlySiteCollection(ArrayList sites) { for (int i = 0; i < sites.Count; i++) { - Add((ActiveDirectorySite)sites[i]); + Add((ActiveDirectorySite)sites[i]!); } } - public ActiveDirectorySite this[int index] => (ActiveDirectorySite)InnerList[index]; + public ActiveDirectorySite this[int index] => (ActiveDirectorySite)InnerList[index]!; public bool Contains(ActiveDirectorySite site) { if (site == null) throw new ArgumentNullException(nameof(site)); - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; + ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]!; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { @@ -45,13 +45,13 @@ public int IndexOf(ActiveDirectorySite site) if (site == null) throw new ArgumentNullException(nameof(site)); - string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]; + ActiveDirectorySite tmp = (ActiveDirectorySite)InnerList[i]!; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkBridgeCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkBridgeCollection.cs index 8b8938bc3e79d..fdafe4fba99ff 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkBridgeCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkBridgeCollection.cs @@ -11,7 +11,7 @@ internal ReadOnlySiteLinkBridgeCollection() { } public ActiveDirectorySiteLinkBridge this[int index] { - get => (ActiveDirectorySiteLinkBridge)InnerList[index]; + get => (ActiveDirectorySiteLinkBridge)InnerList[index]!; } public bool Contains(ActiveDirectorySiteLinkBridge bridge) @@ -19,12 +19,12 @@ public bool Contains(ActiveDirectorySiteLinkBridge bridge) if (bridge == null) throw new ArgumentNullException(nameof(bridge)); - string dn = (string)PropertyManager.GetPropertyValue(bridge.context, bridge.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(bridge.context, bridge.cachedEntry!, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLinkBridge tmp = (ActiveDirectorySiteLinkBridge)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLinkBridge tmp = (ActiveDirectorySiteLinkBridge)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry!, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { @@ -39,12 +39,12 @@ public int IndexOf(ActiveDirectorySiteLinkBridge bridge) if (bridge == null) throw new ArgumentNullException(nameof(bridge)); - string dn = (string)PropertyManager.GetPropertyValue(bridge.context, bridge.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(bridge.context, bridge.cachedEntry!, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLinkBridge tmp = (ActiveDirectorySiteLinkBridge)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLinkBridge tmp = (ActiveDirectorySiteLinkBridge)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry!, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs index a0fad5e1f4c4e..89e804443f1a3 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - using System.Collections; namespace System.DirectoryServices.ActiveDirectory @@ -11,7 +10,7 @@ internal ReadOnlySiteLinkCollection() { } public ActiveDirectorySiteLink this[int index] { - get => (ActiveDirectorySiteLink)InnerList[index]; + get => (ActiveDirectorySiteLink)InnerList[index]!; } public bool Contains(ActiveDirectorySiteLink link) @@ -19,12 +18,12 @@ public bool Contains(ActiveDirectorySiteLink link) if (link == null) throw new ArgumentNullException(nameof(link)); - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { @@ -39,12 +38,12 @@ public int IndexOf(ActiveDirectorySiteLink link) if (link == null) throw new ArgumentNullException(nameof(link)); - string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); + ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyStringCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyStringCollection.cs index 14be9c1e0686c..9918903119a20 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyStringCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlyStringCollection.cs @@ -22,7 +22,7 @@ public string this[int index] { get { - object returnValue = InnerList[index]; + object returnValue = InnerList[index]!; if (returnValue is Exception) throw (Exception)returnValue; @@ -40,7 +40,7 @@ public bool Contains(string value) for (int i = 0; i < InnerList.Count; i++) { - string tmp = (string)InnerList[i]; + string tmp = (string)InnerList[i]!; if (Utils.Compare(tmp, value) == 0) { return true; @@ -58,7 +58,7 @@ public int IndexOf(string value) for (int i = 0; i < InnerList.Count; i++) { - string tmp = (string)InnerList[i]; + string tmp = (string)InnerList[i]!; if (Utils.Compare(tmp, value) == 0) { return i; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnection.cs index 68e87014e5722..0cfadb8fd177e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnection.cs @@ -30,8 +30,8 @@ public class ReplicationConnection : IDisposable private int _options; private readonly string _connectionName; - private string _sourceServerName; - private string _destinationServerName; + private string? _sourceServerName; + private string? _destinationServerName; private readonly ActiveDirectoryTransportType _transport = ActiveDirectoryTransportType.Rpc; private const string ADAMGuid = "1.2.840.113556.1.4.1851"; @@ -47,7 +47,7 @@ public static ReplicationConnection FindByName(DirectoryContext context, string DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { - string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName); + string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName)!; string connectionContainer = "CN=NTDS Settings," + serverDN; de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer); // doing the search to find the connection object based on its name @@ -57,7 +57,7 @@ public static ReplicationConnection FindByName(DirectoryContext context, string SearchScope.OneLevel, false, /* no paged search */ false /* don't cache results */); - SearchResult srchResult = null; + SearchResult? srchResult = null; try { srchResult = adSearcher.FindOne(); @@ -106,7 +106,7 @@ public ReplicationConnection(DirectoryContext context, string name, DirectorySer { } - public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule) : this(context, name, sourceServer, schedule, ActiveDirectoryTransportType.Rpc) + public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule? schedule) : this(context, name, sourceServer, schedule, ActiveDirectoryTransportType.Rpc) { } @@ -114,7 +114,7 @@ public ReplicationConnection(DirectoryContext context, string name, DirectorySer { } - public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport) + public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule? schedule, ActiveDirectoryTransportType transport) { ValidateArgument(context, name); @@ -136,7 +136,7 @@ public ReplicationConnection(DirectoryContext context, string name, DirectorySer DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); try { - string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName); + string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName)!; string connectionContainer = "CN=NTDS Settings," + serverDN; de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer); @@ -150,7 +150,7 @@ public ReplicationConnection(DirectoryContext context, string name, DirectorySer // sourceserver property DirectoryContext sourceServerContext = sourceServer.Context; de = DirectoryEntryManager.GetDirectoryEntry(sourceServerContext, WellKnownDN.RootDSE); - string serverName = (string)PropertyManager.GetPropertyValue(sourceServerContext, de, PropertyManager.ServerName); + string serverName = (string)PropertyManager.GetPropertyValue(sourceServerContext, de, PropertyManager.ServerName)!; serverName = "CN=NTDS Settings," + serverName; cachedDirectoryEntry.Properties["fromServer"].Add(serverName); @@ -233,7 +233,7 @@ public string Name } } - public string SourceServer + public string? SourceServer { get { @@ -243,12 +243,12 @@ public string SourceServer // get the source server if (_sourceServerName == null) { - string sourceServerDN = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.FromServer); + string sourceServerDN = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.FromServer)!; DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, sourceServerDN); if (IsADAM) { - int portnumber = (int)PropertyManager.GetPropertyValue(context, de, PropertyManager.MsDSPortLDAP); - string tmpServerName = (string)PropertyManager.GetPropertyValue(context, de.Parent, PropertyManager.DnsHostName); + int portnumber = (int)PropertyManager.GetPropertyValue(context, de, PropertyManager.MsDSPortLDAP)!; + string? tmpServerName = (string?)PropertyManager.GetPropertyValue(context, de.Parent, PropertyManager.DnsHostName); if (portnumber != 389) { _sourceServerName = tmpServerName + ":" + portnumber; @@ -256,7 +256,7 @@ public string SourceServer } else { - _sourceServerName = (string)PropertyManager.GetPropertyValue(context, de.Parent, PropertyManager.DnsHostName); + _sourceServerName = (string?)PropertyManager.GetPropertyValue(context, de.Parent, PropertyManager.DnsHostName); } } return _sourceServerName; @@ -272,8 +272,8 @@ public string DestinationServer if (_destinationServerName == null) { - DirectoryEntry NTDSObject = null; - DirectoryEntry serverObject = null; + DirectoryEntry? NTDSObject = null; + DirectoryEntry? serverObject = null; try { NTDSObject = cachedDirectoryEntry.Parent; @@ -284,10 +284,10 @@ public string DestinationServer throw ExceptionHelper.GetExceptionFromCOMException(context, e); } - string hostName = (string)PropertyManager.GetPropertyValue(context, serverObject, PropertyManager.DnsHostName); + string hostName = (string)PropertyManager.GetPropertyValue(context, serverObject, PropertyManager.DnsHostName)!; if (IsADAM) { - int portnumber = (int)PropertyManager.GetPropertyValue(context, NTDSObject, PropertyManager.MsDSPortLDAP); + int portnumber = (int)PropertyManager.GetPropertyValue(context, NTDSObject, PropertyManager.MsDSPortLDAP)!; if (portnumber != 389) { _destinationServerName = hostName + ":" + portnumber; @@ -313,7 +313,7 @@ public bool Enabled try { if (cachedDirectoryEntry.Properties.Contains("enabledConnection")) - return (bool)cachedDirectoryEntry.Properties["enabledConnection"][0]; + return (bool)cachedDirectoryEntry.Properties["enabledConnection"][0]!; else return false; } @@ -349,7 +349,7 @@ public ActiveDirectoryTransportType TransportType // the member variable value directly if (existingConnection) { - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedDirectoryEntry.Properties["transportType"]; @@ -366,7 +366,7 @@ public ActiveDirectoryTransportType TransportType } else { - return Utils.GetTransportTypeFromDN((string)propValue[0]); + return Utils.GetTransportTypeFromDN((string)propValue[0]!); } } else @@ -381,7 +381,7 @@ public bool GeneratedByKcc if (_disposed) throw new ObjectDisposedException(GetType().Name); - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { @@ -398,7 +398,7 @@ public bool GeneratedByKcc } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_IS_GENERATED ( 1 << 0 ) object generated by DS, not admin @@ -421,7 +421,7 @@ public bool GeneratedByKcc } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_IS_GENERATED ( 1 << 0 ) object generated by DS, not admin @@ -451,7 +451,7 @@ public bool ReciprocalReplicationEnabled if (_disposed) throw new ObjectDisposedException(GetType().Name); - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedDirectoryEntry.Properties["options"]; @@ -468,7 +468,7 @@ public bool ReciprocalReplicationEnabled } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_TWOWAY_SYNC ( 1 << 1 ) force sync in opposite direction at end of sync @@ -491,7 +491,7 @@ public bool ReciprocalReplicationEnabled } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_TWOWAY_SYNC ( 1 << 1 ) force sync in opposite direction at end of sync @@ -521,7 +521,7 @@ public NotificationStatus ChangeNotificationStatus if (_disposed) throw new ObjectDisposedException(GetType().Name); - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedDirectoryEntry.Properties["options"]; @@ -538,7 +538,7 @@ public NotificationStatus ChangeNotificationStatus } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } int overrideNotify = _options & 0x4; @@ -567,7 +567,7 @@ public NotificationStatus ChangeNotificationStatus } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } if (value == NotificationStatus.IntraSiteOnly) @@ -603,7 +603,7 @@ public bool DataCompressionEnabled if (_disposed) throw new ObjectDisposedException(GetType().Name); - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedDirectoryEntry.Properties["options"]; @@ -620,7 +620,7 @@ public bool DataCompressionEnabled } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } //NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION (1 << 4) @@ -645,7 +645,7 @@ public bool DataCompressionEnabled } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } //NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION (1 << 4) @@ -677,7 +677,7 @@ public bool ReplicationScheduleOwnedByUser if (_disposed) throw new ObjectDisposedException(GetType().Name); - PropertyValueCollection propValue = null; + PropertyValueCollection? propValue = null; try { propValue = cachedDirectoryEntry.Properties["options"]; @@ -694,7 +694,7 @@ public bool ReplicationScheduleOwnedByUser } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_USER_OWNED_SCHEDULE (1 << 5) @@ -717,7 +717,7 @@ public bool ReplicationScheduleOwnedByUser } else { - _options = (int)propValue[0]; + _options = (int)propValue[0]!; } // NTDSCONN_OPT_USER_OWNED_SCHEDULE (1 << 5) @@ -748,12 +748,12 @@ public ReplicationSpan ReplicationSpan throw new ObjectDisposedException(GetType().Name); // find out whether the site and the destination is in the same site - string destinationPath = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.FromServer); - string destinationSite = Utils.GetDNComponents(destinationPath)[3].Value; + string destinationPath = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.FromServer)!; + string? destinationSite = Utils.GetDNComponents(destinationPath)[3].Value; DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName); - string serverSite = Utils.GetDNComponents(serverDN)[2].Value; + string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName)!; + string? serverSite = Utils.GetDNComponents(serverDN)[2].Value; if (Utils.Compare(destinationSite, serverSite) == 0) { @@ -766,14 +766,14 @@ public ReplicationSpan ReplicationSpan } } - public ActiveDirectorySchedule ReplicationSchedule + public ActiveDirectorySchedule? ReplicationSchedule { get { if (_disposed) throw new ObjectDisposedException(GetType().Name); - ActiveDirectorySchedule schedule = null; + ActiveDirectorySchedule? schedule = null; bool scheduleExists = false; try { @@ -786,7 +786,7 @@ public ActiveDirectorySchedule ReplicationSchedule if (scheduleExists) { - byte[] tmpSchedule = (byte[])cachedDirectoryEntry.Properties["schedule"][0]; + byte[] tmpSchedule = (byte[])cachedDirectoryEntry.Properties["schedule"][0]!; Debug.Assert(tmpSchedule != null && tmpSchedule.Length == 188); schedule = new ActiveDirectorySchedule(); schedule.SetUnmanagedSchedule(tmpSchedule); @@ -924,8 +924,8 @@ private static void ValidateArgument(DirectoryContext context, string name) private void ValidateTargetAndSourceServer(DirectoryContext context, DirectoryServer sourceServer) { bool targetIsDC = false; - DirectoryEntry targetDE = null; - DirectoryEntry sourceDE = null; + DirectoryEntry? targetDE = null; + DirectoryEntry? sourceDE = null; // first find out target is a dc or ADAM instance targetDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); @@ -957,8 +957,8 @@ private void ValidateTargetAndSourceServer(DirectoryContext context, DirectorySe // now if they are both dc, we need to check whether they come from the same forest if (targetIsDC) { - string targetRoot = (string)PropertyManager.GetPropertyValue(context, targetDE, PropertyManager.RootDomainNamingContext); - string sourceRoot = (string)PropertyManager.GetPropertyValue(sourceServer.Context, sourceDE, PropertyManager.RootDomainNamingContext); + string? targetRoot = (string?)PropertyManager.GetPropertyValue(context, targetDE, PropertyManager.RootDomainNamingContext); + string? sourceRoot = (string?)PropertyManager.GetPropertyValue(sourceServer.Context, sourceDE, PropertyManager.RootDomainNamingContext); if (Utils.Compare(targetRoot, sourceRoot) != 0) { throw new ArgumentException(SR.ConnectionSourcServerSameForest, nameof(sourceServer)); @@ -966,8 +966,8 @@ private void ValidateTargetAndSourceServer(DirectoryContext context, DirectorySe } else { - string targetRoot = (string)PropertyManager.GetPropertyValue(context, targetDE, PropertyManager.ConfigurationNamingContext); - string sourceRoot = (string)PropertyManager.GetPropertyValue(sourceServer.Context, sourceDE, PropertyManager.ConfigurationNamingContext); + string? targetRoot = (string?)PropertyManager.GetPropertyValue(context, targetDE, PropertyManager.ConfigurationNamingContext); + string? sourceRoot = (string?)PropertyManager.GetPropertyValue(sourceServer.Context, sourceDE, PropertyManager.ConfigurationNamingContext); if (Utils.Compare(targetRoot, sourceRoot) != 0) { throw new ArgumentException(SR.ConnectionSourcServerSameConfigSet, nameof(sourceServer)); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnectionCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnectionCollection.cs index d8b238595b260..6133b1b8f1963 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnectionCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationConnectionCollection.cs @@ -9,7 +9,7 @@ public class ReplicationConnectionCollection : ReadOnlyCollectionBase { internal ReplicationConnectionCollection() { } - public ReplicationConnection this[int index] => (ReplicationConnection)InnerList[index]; + public ReplicationConnection this[int index] => (ReplicationConnection)InnerList[index]!; public bool Contains(ReplicationConnection connection) { @@ -19,12 +19,12 @@ public bool Contains(ReplicationConnection connection) if (!connection.existingConnection) throw new InvalidOperationException(SR.Format(SR.ConnectionNotCommitted, connection.Name)); - string dn = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ReplicationConnection tmp = (ReplicationConnection)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); + ReplicationConnection tmp = (ReplicationConnection)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { @@ -42,12 +42,12 @@ public int IndexOf(ReplicationConnection connection) if (!connection.existingConnection) throw new InvalidOperationException(SR.Format(SR.ConnectionNotCommitted, connection.Name)); - string dn = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); + string? dn = (string?)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName); for (int i = 0; i < InnerList.Count; i++) { - ReplicationConnection tmp = (ReplicationConnection)InnerList[i]; - string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); + ReplicationConnection tmp = (ReplicationConnection)InnerList[i]!; + string? tmpDn = (string?)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName); if (Utils.Compare(tmpDn, dn) == 0) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursor.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursor.cs index ef6a8b81d1aa8..040e05b805ab4 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursor.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursor.cs @@ -7,12 +7,12 @@ namespace System.DirectoryServices.ActiveDirectory { public class ReplicationCursor { - private readonly string _serverDN; + private readonly string? _serverDN; private readonly DateTime _syncTime; private readonly bool _advanced; - private string _sourceServer; + private string? _sourceServer; - private readonly DirectoryServer _server; + private readonly DirectoryServer _server = null!; private ReplicationCursor() { } @@ -42,13 +42,13 @@ internal ReplicationCursor(DirectoryServer server, string partition, Guid guid, _server = server; } - public string PartitionName { get; } + public string PartitionName { get; } = null!; public Guid SourceInvocationId { get; } public long UpToDatenessUsn { get; } - public string SourceServer + public string? SourceServer { get { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursorCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursorCollection.cs index 318e309f69a76..52e2946a207db 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursorCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationCursorCollection.cs @@ -15,7 +15,7 @@ internal ReplicationCursorCollection(DirectoryServer server) _server = server; } - public ReplicationCursor this[int index] => (ReplicationCursor)InnerList[index]; + public ReplicationCursor this[int index] => (ReplicationCursor)InnerList[index]!; public bool Contains(ReplicationCursor cursor) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailure.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailure.cs index 359bac6cd7716..3f70d9d8598e4 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailure.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailure.cs @@ -8,11 +8,11 @@ namespace System.DirectoryServices.ActiveDirectory { public class ReplicationFailure { - private readonly string _sourceDsaDN; + private readonly string? _sourceDsaDN; internal int lastResult; private readonly DirectoryServer _server; - private string _sourceServer; + private string? _sourceServer; private readonly Hashtable _nameTable; internal ReplicationFailure(IntPtr addr, DirectoryServer server, Hashtable table) @@ -30,7 +30,7 @@ internal ReplicationFailure(IntPtr addr, DirectoryServer server, Hashtable table _nameTable = table; } - public string SourceServer + public string? SourceServer { get { @@ -39,7 +39,7 @@ public string SourceServer // check whether we have got it before if (_nameTable.Contains(SourceServerGuid)) { - _sourceServer = (string)_nameTable[SourceServerGuid]; + _sourceServer = (string)_nameTable[SourceServerGuid]!; } else if (_sourceDsaDN != null) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailureCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailureCollection.cs index 71e30f8778532..561349658a729 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailureCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationFailureCollection.cs @@ -18,7 +18,7 @@ internal ReplicationFailureCollection(DirectoryServer server) _nameTable = Hashtable.Synchronized(tempNameTable); } - public ReplicationFailure this[int index] => (ReplicationFailure)InnerList[index]; + public ReplicationFailure this[int index] => (ReplicationFailure)InnerList[index]!; public bool Contains(ReplicationFailure failure) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighbor.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighbor.cs index 651d104f62fa5..ce644bbb90895 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighbor.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighbor.cs @@ -34,10 +34,10 @@ public enum ReplicationNeighborOptions : long PartialAttributeSet = 0x40000000 } - private readonly string _sourceServerDN; + private readonly string? _sourceServerDN; private readonly DirectoryServer _server; - private string _sourceServer; + private string? _sourceServer; private readonly Hashtable _nameTable; internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table) @@ -48,11 +48,11 @@ internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable tabl PartitionName = Marshal.PtrToStringUni(neighbor.pszNamingContext); _sourceServerDN = Marshal.PtrToStringUni(neighbor.pszSourceDsaDN); - string transportDN = Marshal.PtrToStringUni(neighbor.pszAsyncIntersiteTransportDN); + string? transportDN = Marshal.PtrToStringUni(neighbor.pszAsyncIntersiteTransportDN); if (transportDN != null) { string rdn = Utils.GetRdnFromDN(transportDN); - string transport = (Utils.GetDNComponents(rdn))[0].Value; + string? transport = (Utils.GetDNComponents(rdn))[0].Value; if (string.Equals(transport, "SMTP", StringComparison.OrdinalIgnoreCase)) TransportType = ActiveDirectoryTransportType.Smtp; @@ -73,9 +73,9 @@ internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable tabl _nameTable = table; } - public string PartitionName { get; } + public string? PartitionName { get; } - public string SourceServer + public string? SourceServer { get { @@ -84,7 +84,7 @@ public string SourceServer // check whether we have got it before if (_nameTable.Contains(SourceInvocationId)) { - _sourceServer = (string)_nameTable[SourceInvocationId]; + _sourceServer = (string?)_nameTable[SourceInvocationId]; } else if (_sourceServerDN != null) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighborCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighborCollection.cs index abc6cd6128a58..34f7203e9f520 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighborCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationNeighborCollection.cs @@ -18,7 +18,7 @@ internal ReplicationNeighborCollection(DirectoryServer server) _nameTable = Hashtable.Synchronized(tempNameTable); } - public ReplicationNeighbor this[int index] => (ReplicationNeighbor)InnerList[index]; + public ReplicationNeighbor this[int index] => (ReplicationNeighbor)InnerList[index]!; public bool Contains(ReplicationNeighbor neighbor) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperation.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperation.cs index 0649dda9bd5f9..09b8f2e23417e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperation.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperation.cs @@ -8,10 +8,10 @@ namespace System.DirectoryServices.ActiveDirectory { public class ReplicationOperation { - private readonly string _dsaDN; + private readonly string? _dsaDN; private readonly DirectoryServer _server; - private string _sourceServer; + private string? _sourceServer; private readonly Hashtable _nameTable; internal ReplicationOperation(IntPtr addr, DirectoryServer server, Hashtable table) @@ -52,9 +52,9 @@ internal ReplicationOperation(IntPtr addr, DirectoryServer server, Hashtable tab public ReplicationOperationType OperationType { get; } - public string PartitionName { get; } + public string? PartitionName { get; } - public string SourceServer + public string? SourceServer { get { @@ -63,11 +63,11 @@ public string SourceServer // check whether we have got it before if (_nameTable.Contains(SourceServerGuid)) { - _sourceServer = (string)_nameTable[SourceServerGuid]; + _sourceServer = (string)_nameTable[SourceServerGuid]!; } else if (_dsaDN != null) { - _sourceServer = Utils.GetServerNameFromInvocationID(_dsaDN, SourceServerGuid, _server); + _sourceServer = Utils.GetServerNameFromInvocationID(_dsaDN, SourceServerGuid, _server)!; // add it to the hashtable _nameTable.Add(SourceServerGuid, _sourceServer); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationCollection.cs index 0f5f2f30f3bbd..297691533afb6 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationCollection.cs @@ -18,7 +18,7 @@ internal ReplicationOperationCollection(DirectoryServer server) _nameTable = Hashtable.Synchronized(tempNameTable); } - public ReplicationOperation this[int index] => (ReplicationOperation)InnerList[index]; + public ReplicationOperation this[int index] => (ReplicationOperation)InnerList[index]!; public bool Contains(ReplicationOperation operation) { @@ -61,7 +61,7 @@ internal void AddHelper(DS_REPL_PENDING_OPS operations, IntPtr info) internal ReplicationOperation GetFirstOperation() { - ReplicationOperation op = (ReplicationOperation)InnerList[0]; + ReplicationOperation op = (ReplicationOperation)InnerList[0]!; InnerList.RemoveAt(0); return op; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationInformation.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationInformation.cs index 26a5a49578cd6..e051d8c1ed7ae 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationInformation.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReplicationOperationInformation.cs @@ -6,8 +6,8 @@ namespace System.DirectoryServices.ActiveDirectory public class ReplicationOperationInformation { internal DateTime startTime; - internal ReplicationOperation currentOp; - internal ReplicationOperationCollection collection; + internal ReplicationOperation? currentOp; + internal ReplicationOperationCollection? collection; public ReplicationOperationInformation() { @@ -15,8 +15,8 @@ public ReplicationOperationInformation() public DateTime OperationStartTime => startTime; - public ReplicationOperation CurrentOperation => currentOp; + public ReplicationOperation? CurrentOperation => currentOp; - public ReplicationOperationCollection PendingOperations => collection; + public ReplicationOperationCollection? PendingOperations => collection; } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/RoleOwnerCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/RoleOwnerCollection.cs index 5a06075b61883..b4798aaa67894 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/RoleOwnerCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/RoleOwnerCollection.cs @@ -18,7 +18,7 @@ internal ActiveDirectoryRoleCollection(ArrayList values) } } - public ActiveDirectoryRole this[int index] => (ActiveDirectoryRole)InnerList[index]; + public ActiveDirectoryRole this[int index] => (ActiveDirectoryRole)InnerList[index]!; public bool Contains(ActiveDirectoryRole role) { @@ -29,7 +29,7 @@ public bool Contains(ActiveDirectoryRole role) for (int i = 0; i < InnerList.Count; i++) { - int tmp = (int)InnerList[i]; + int tmp = (int)InnerList[i]!; if (tmp == (int)role) { return true; @@ -47,7 +47,7 @@ public int IndexOf(ActiveDirectoryRole role) for (int i = 0; i < InnerList.Count; i++) { - int tmp = (int)InnerList[i]; + int tmp = (int)InnerList[i]!; if (tmp == (int)role) { @@ -76,7 +76,7 @@ internal AdamRoleCollection(ArrayList values) } } - public AdamRole this[int index] => (AdamRole)InnerList[index]; + public AdamRole this[int index] => (AdamRole)InnerList[index]!; public bool Contains(AdamRole role) { @@ -87,7 +87,7 @@ public bool Contains(AdamRole role) for (int i = 0; i < InnerList.Count; i++) { - int tmp = (int)InnerList[i]; + int tmp = (int)InnerList[i]!; if (tmp == (int)role) { return true; @@ -105,7 +105,7 @@ public int IndexOf(AdamRole role) for (int i = 0; i < InnerList.Count; i++) { - int tmp = (int)InnerList[i]; + int tmp = (int)InnerList[i]!; if (tmp == (int)role) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TopLevelNameCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TopLevelNameCollection.cs index 2bcf11b5cbec2..0b9ce43ae6348 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TopLevelNameCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TopLevelNameCollection.cs @@ -9,7 +9,7 @@ public class TopLevelNameCollection : ReadOnlyCollectionBase { internal TopLevelNameCollection() { } - public TopLevelName this[int index] => (TopLevelName)InnerList[index]; + public TopLevelName this[int index] => (TopLevelName)InnerList[index]!; public bool Contains(TopLevelName name) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustHelper.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustHelper.cs index 94d69f31afa7b..e4d5813316847 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustHelper.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustHelper.cs @@ -57,14 +57,14 @@ internal class TrustHelper private TrustHelper() { } - internal static bool GetTrustedDomainInfoStatus(DirectoryContext context, string sourceName, string targetName, TRUST_ATTRIBUTE attribute, bool isForest) + internal static bool GetTrustedDomainInfoStatus(DirectoryContext context, string? sourceName, string targetName, TRUST_ATTRIBUTE attribute, bool isForest) { - PolicySafeHandle handle = null; + PolicySafeHandle? handle = null; IntPtr buffer = (IntPtr)0; - LSA_UNICODE_STRING trustedDomainName = null; + LSA_UNICODE_STRING? trustedDomainName = null; bool impersonated = false; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; // get policy server name serverName = Utils.GetPolicyServerName(context, isForest, false, sourceName); @@ -154,15 +154,15 @@ internal static bool GetTrustedDomainInfoStatus(DirectoryContext context, string catch { throw; } } - internal static void SetTrustedDomainInfoStatus(DirectoryContext context, string sourceName, string targetName, TRUST_ATTRIBUTE attribute, bool status, bool isForest) + internal static void SetTrustedDomainInfoStatus(DirectoryContext context, string? sourceName, string targetName, TRUST_ATTRIBUTE attribute, bool status, bool isForest) { - PolicySafeHandle handle = null; + PolicySafeHandle? handle = null; IntPtr buffer = (IntPtr)0; IntPtr newInfo = (IntPtr)0; - LSA_UNICODE_STRING trustedDomainName = null; + LSA_UNICODE_STRING? trustedDomainName = null; bool impersonated = false; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; serverName = Utils.GetPolicyServerName(context, isForest, false, sourceName); @@ -284,14 +284,14 @@ internal static void SetTrustedDomainInfoStatus(DirectoryContext context, string catch { throw; } } - internal static void DeleteTrust(DirectoryContext sourceContext, string sourceName, string targetName, bool isForest) + internal static void DeleteTrust(DirectoryContext sourceContext, string? sourceName, string? targetName, bool isForest) { - PolicySafeHandle policyHandle = null; - LSA_UNICODE_STRING trustedDomainName = null; + PolicySafeHandle? policyHandle = null; + LSA_UNICODE_STRING? trustedDomainName = null; int win32Error = 0; bool impersonated = false; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; IntPtr buffer = (IntPtr)0; serverName = Utils.GetPolicyServerName(sourceContext, isForest, false, sourceName); @@ -363,10 +363,10 @@ internal static void DeleteTrust(DirectoryContext sourceContext, string sourceNa catch { throw; } } - internal static void VerifyTrust(DirectoryContext context, string sourceName, string targetName, bool isForest, TrustDirection direction, bool forceSecureChannelReset, string preferredTargetServer) + internal static void VerifyTrust(DirectoryContext context, string? sourceName, string? targetName, bool isForest, TrustDirection direction, bool forceSecureChannelReset, string? preferredTargetServer) { - PolicySafeHandle policyHandle = null; - LSA_UNICODE_STRING trustedDomainName = null; + PolicySafeHandle? policyHandle = null; + LSA_UNICODE_STRING? trustedDomainName = null; int win32Error = 0; IntPtr data = (IntPtr)0; IntPtr ptr = (IntPtr)0; @@ -374,7 +374,7 @@ internal static void VerifyTrust(DirectoryContext context, string sourceName, st IntPtr buffer2 = (IntPtr)0; bool impersonated = true; IntPtr target = (IntPtr)0; - string policyServerName = null; + string? policyServerName = null; policyServerName = Utils.GetPolicyServerName(context, isForest, false, sourceName); @@ -478,19 +478,19 @@ internal static void VerifyTrust(DirectoryContext context, string sourceName, st catch { throw; } } - internal static void CreateTrust(DirectoryContext sourceContext, string sourceName, DirectoryContext targetContext, string targetName, bool isForest, TrustDirection direction, string password) + internal static void CreateTrust(DirectoryContext sourceContext, string? sourceName, DirectoryContext targetContext, string? targetName, bool isForest, TrustDirection direction, string password) { - LSA_AUTH_INFORMATION AuthData = null; - TRUSTED_DOMAIN_AUTH_INFORMATION AuthInfoEx = null; - TRUSTED_DOMAIN_INFORMATION_EX tdi = null; + LSA_AUTH_INFORMATION? AuthData = null; + TRUSTED_DOMAIN_AUTH_INFORMATION? AuthInfoEx = null; + TRUSTED_DOMAIN_INFORMATION_EX? tdi = null; IntPtr fileTime = (IntPtr)0; IntPtr unmanagedPassword = (IntPtr)0; IntPtr info = (IntPtr)0; IntPtr domainHandle = (IntPtr)0; - PolicySafeHandle policyHandle = null; + PolicySafeHandle? policyHandle = null; IntPtr unmanagedAuthData = (IntPtr)0; bool impersonated = false; - string serverName = null; + string? serverName = null; // get the domain info first info = GetTrustedDomainInfo(targetContext, targetName, isForest); @@ -597,21 +597,21 @@ internal static void CreateTrust(DirectoryContext sourceContext, string sourceNa catch { throw; } } - internal static string UpdateTrust(DirectoryContext context, string sourceName, string targetName, string password, bool isForest) + internal static string UpdateTrust(DirectoryContext context, string? sourceName, string? targetName, string password, bool isForest) { - PolicySafeHandle handle = null; + PolicySafeHandle? handle = null; IntPtr buffer = (IntPtr)0; - LSA_UNICODE_STRING trustedDomainName = null; + LSA_UNICODE_STRING? trustedDomainName = null; IntPtr newBuffer = (IntPtr)0; bool impersonated = false; - LSA_AUTH_INFORMATION AuthData = null; + LSA_AUTH_INFORMATION? AuthData = null; IntPtr fileTime = (IntPtr)0; IntPtr unmanagedPassword = (IntPtr)0; IntPtr unmanagedAuthData = (IntPtr)0; - TRUSTED_DOMAIN_AUTH_INFORMATION AuthInfoEx = null; + TRUSTED_DOMAIN_AUTH_INFORMATION? AuthInfoEx = null; TrustDirection direction; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; serverName = Utils.GetPolicyServerName(context, isForest, false, sourceName); @@ -651,10 +651,10 @@ internal static string UpdateTrust(DirectoryContext context, string sourceName, Marshal.PtrToStructure(buffer, domainInfo); // validate the trust attribute first - ValidateTrustAttribute(domainInfo.Information, isForest, sourceName, targetName); + ValidateTrustAttribute(domainInfo.Information!, isForest, sourceName, targetName); // get trust direction - direction = (TrustDirection)domainInfo.Information.TrustDirection; + direction = (TrustDirection)domainInfo.Information!.TrustDirection; // change the attribute value properly AuthData = new LSA_AUTH_INFORMATION(); @@ -731,20 +731,20 @@ internal static string UpdateTrust(DirectoryContext context, string sourceName, catch { throw; } } - internal static void UpdateTrustDirection(DirectoryContext context, string sourceName, string targetName, string password, bool isForest, TrustDirection newTrustDirection) + internal static void UpdateTrustDirection(DirectoryContext context, string? sourceName, string? targetName, string password, bool isForest, TrustDirection newTrustDirection) { - PolicySafeHandle handle = null; + PolicySafeHandle? handle = null; IntPtr buffer = (IntPtr)0; - LSA_UNICODE_STRING trustedDomainName = null; + LSA_UNICODE_STRING? trustedDomainName = null; IntPtr newBuffer = (IntPtr)0; bool impersonated = false; - LSA_AUTH_INFORMATION AuthData = null; + LSA_AUTH_INFORMATION? AuthData = null; IntPtr fileTime = (IntPtr)0; IntPtr unmanagedPassword = (IntPtr)0; IntPtr unmanagedAuthData = (IntPtr)0; - TRUSTED_DOMAIN_AUTH_INFORMATION AuthInfoEx = null; + TRUSTED_DOMAIN_AUTH_INFORMATION? AuthInfoEx = null; IntPtr target = (IntPtr)0; - string serverName = null; + string? serverName = null; serverName = Utils.GetPolicyServerName(context, isForest, false, sourceName); @@ -784,7 +784,7 @@ internal static void UpdateTrustDirection(DirectoryContext context, string sourc Marshal.PtrToStructure(buffer, domainInfo); // validate the trust attribute first - ValidateTrustAttribute(domainInfo.Information, isForest, sourceName, targetName); + ValidateTrustAttribute(domainInfo.Information!, isForest, sourceName, targetName); // change the attribute value properly AuthData = new LSA_AUTH_INFORMATION(); @@ -836,7 +836,7 @@ internal static void UpdateTrustDirection(DirectoryContext context, string sourc // reconstruct the unmanaged structure to set it back domainInfo.AuthInformation = AuthInfoEx; // reset the trust direction - domainInfo.Information.TrustDirection = (int)newTrustDirection; + domainInfo.Information!.TrustDirection = (int)newTrustDirection; newBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TRUSTED_DOMAIN_FULL_INFORMATION))); Marshal.StructureToPtr(domainInfo, newBuffer, false); @@ -876,7 +876,7 @@ internal static void UpdateTrustDirection(DirectoryContext context, string sourc catch { throw; } } - private static void ValidateTrust(PolicySafeHandle handle, LSA_UNICODE_STRING trustedDomainName, string sourceName, string targetName, bool isForest, int direction, string serverName) + private static void ValidateTrust(PolicySafeHandle handle, LSA_UNICODE_STRING trustedDomainName, string? sourceName, string? targetName, bool isForest, int direction, string serverName) { IntPtr buffer = (IntPtr)0; @@ -926,7 +926,7 @@ private static void ValidateTrust(PolicySafeHandle handle, LSA_UNICODE_STRING tr } } - private static void ValidateTrustAttribute(TRUSTED_DOMAIN_INFORMATION_EX domainInfo, bool isForest, string sourceName, string targetName) + private static void ValidateTrustAttribute(TRUSTED_DOMAIN_INFORMATION_EX domainInfo, bool isForest, string? sourceName, string? targetName) { if (isForest) { @@ -982,12 +982,12 @@ internal static string CreateTrustPassword() return password; } - private static IntPtr GetTrustedDomainInfo(DirectoryContext targetContext, string targetName, bool isForest) + private static IntPtr GetTrustedDomainInfo(DirectoryContext targetContext, string? targetName, bool isForest) { - PolicySafeHandle policyHandle = null; + PolicySafeHandle? policyHandle = null; IntPtr buffer = (IntPtr)0; bool impersonated = false; - string serverName = null; + string? serverName = null; try { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformation.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformation.cs index eb633fc8973f5..cc546f6684fb8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformation.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformation.cs @@ -23,15 +23,15 @@ public enum TrustDirection public class TrustRelationshipInformation { - internal string source; - internal string target; + internal string? source; + internal string? target; internal TrustType type; internal TrustDirection direction; - internal DirectoryContext context; + internal DirectoryContext context = null!; internal TrustRelationshipInformation() { } - internal TrustRelationshipInformation(DirectoryContext context, string source, TrustObject obj) + internal TrustRelationshipInformation(DirectoryContext context, string? source, TrustObject obj) { // security context this.context = context; @@ -51,9 +51,9 @@ internal TrustRelationshipInformation(DirectoryContext context, string source, T this.type = obj.TrustType; } - public string SourceName => source; + public string? SourceName => source; - public string TargetName => target; + public string? TargetName => target; public TrustType TrustType => type; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformationCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformationCollection.cs index 99b3cc91e3e27..caaa388feecc8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformationCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/TrustRelationshipInformationCollection.cs @@ -9,11 +9,11 @@ public class TrustRelationshipInformationCollection : ReadOnlyCollectionBase { internal TrustRelationshipInformationCollection() { } - internal TrustRelationshipInformationCollection(DirectoryContext context, string source, ArrayList trusts) + internal TrustRelationshipInformationCollection(DirectoryContext context, string? source, ArrayList trusts) { for (int i = 0; i < trusts.Count; i++) { - TrustObject obj = (TrustObject)trusts[i]; + TrustObject obj = (TrustObject)trusts[i]!; // we don't need self and forest trust if ((obj.TrustType == TrustType.Forest) || ((int)obj.TrustType == 7)) { @@ -27,7 +27,7 @@ internal TrustRelationshipInformationCollection(DirectoryContext context, string public TrustRelationshipInformation this[int index] { - get => (TrustRelationshipInformation)InnerList[index]; + get => (TrustRelationshipInformation)InnerList[index]!; } public bool Contains(TrustRelationshipInformation information) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs index f82d97e806520..a5b4e24c1cfdd 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs @@ -386,8 +386,8 @@ internal sealed class DS_DOMAIN_TRUSTS internal sealed class TrustObject { - public string NetbiosDomainName; - public string DnsDomainName; + public string? NetbiosDomainName; + public string? DnsDomainName; public int Flags; public int ParentIndex; public TrustType TrustType; @@ -410,13 +410,13 @@ internal sealed class LSA_FOREST_TRUST_RECORD [FieldOffset(4)] public LSA_FOREST_TRUST_RECORD_TYPE ForestTrustType; [FieldOffset(8)] - public LARGE_INTEGER Time; + public LARGE_INTEGER Time = null!; [FieldOffset(16)] - public LSA_UNICODE_STRING TopLevelName; + public LSA_UNICODE_STRING TopLevelName = null!; [FieldOffset(16)] - public LSA_FOREST_TRUST_BINARY_DATA Data; + public LSA_FOREST_TRUST_BINARY_DATA Data = null!; [FieldOffset(16)] - public LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo; + public LSA_FOREST_TRUST_DOMAIN_INFO? DomainInfo; } [StructLayout(LayoutKind.Sequential)] @@ -483,8 +483,8 @@ public LSA_OBJECT_ATTRIBUTES() [StructLayout(LayoutKind.Sequential)] internal sealed class TRUSTED_DOMAIN_INFORMATION_EX { - public LSA_UNICODE_STRING Name; - public LSA_UNICODE_STRING FlatName; + public LSA_UNICODE_STRING? Name; + public LSA_UNICODE_STRING? FlatName; public IntPtr Sid; public int TrustDirection; public int TrustType; @@ -504,7 +504,7 @@ internal sealed class LSA_FOREST_TRUST_COLLISION_RECORD public int Index; public ForestTrustCollisionType Type; public int Flags; - public LSA_UNICODE_STRING Name; + public LSA_UNICODE_STRING Name = null!; } [StructLayout(LayoutKind.Sequential)] @@ -539,7 +539,7 @@ internal sealed class TRUSTED_DOMAIN_AUTH_INFORMATION [StructLayout(LayoutKind.Sequential)] internal sealed class LSA_AUTH_INFORMATION { - public LARGE_INTEGER LastUpdateTime; + public LARGE_INTEGER? LastUpdateTime; public int AuthType; public int AuthInfoLength; public IntPtr AuthInfo; @@ -548,9 +548,9 @@ internal sealed class LSA_AUTH_INFORMATION [StructLayout(LayoutKind.Sequential)] internal sealed class POLICY_DNS_DOMAIN_INFO { - public LSA_UNICODE_STRING Name; - public LSA_UNICODE_STRING DnsDomainName; - public LSA_UNICODE_STRING DnsForestName; + public LSA_UNICODE_STRING? Name; + public LSA_UNICODE_STRING? DnsDomainName; + public LSA_UNICODE_STRING? DnsForestName; public Guid DomainGuid; public IntPtr Sid; } @@ -564,9 +564,9 @@ internal sealed class TRUSTED_POSIX_OFFSET_INFO [StructLayout(LayoutKind.Sequential)] internal sealed class TRUSTED_DOMAIN_FULL_INFORMATION { - public TRUSTED_DOMAIN_INFORMATION_EX Information; - internal TRUSTED_POSIX_OFFSET_INFO PosixOffset; - public TRUSTED_DOMAIN_AUTH_INFORMATION AuthInformation; + public TRUSTED_DOMAIN_INFORMATION_EX? Information; + internal TRUSTED_POSIX_OFFSET_INFO? PosixOffset; + public TRUSTED_DOMAIN_AUTH_INFORMATION? AuthInformation; } /* @@ -586,11 +586,11 @@ internal sealed class DSROLE_PRIMARY_DOMAIN_INFO_BASIC public DSROLE_MACHINE_ROLE MachineRole; public uint Flags; [MarshalAs(UnmanagedType.LPWStr)] - public string DomainNameFlat; + public string? DomainNameFlat; [MarshalAs(UnmanagedType.LPWStr)] - public string DomainNameDns; + public string? DomainNameDns; [MarshalAs(UnmanagedType.LPWStr)] - public string DomainForestName; + public string? DomainForestName; public Guid DomainGuid; } @@ -629,9 +629,9 @@ internal class UnsafeNativeMethods { public delegate int DsReplicaConsistencyCheck([In]IntPtr handle, int taskID, int flags); - public delegate int DsReplicaGetInfo2W(IntPtr handle, int type, [MarshalAs(UnmanagedType.LPWStr)] string objectPath, IntPtr sourceGUID, string attributeName, string value, int flag, int context, ref IntPtr info); + public delegate int DsReplicaGetInfo2W(IntPtr handle, int type, [MarshalAs(UnmanagedType.LPWStr)] string? objectPath, IntPtr sourceGUID, string? attributeName, string? value, int flag, int context, ref IntPtr info); - public delegate int DsReplicaGetInfoW(IntPtr handle, int type, [MarshalAs(UnmanagedType.LPWStr)] string objectPath, IntPtr sourceGUID, ref IntPtr info); + public delegate int DsReplicaGetInfoW(IntPtr handle, int type, [MarshalAs(UnmanagedType.LPWStr)] string? objectPath, IntPtr sourceGUID, ref IntPtr info); public delegate int DsReplicaFreeInfo(int type, IntPtr value); @@ -649,7 +649,7 @@ internal class UnsafeNativeMethods public static extern bool FreeADsMem(IntPtr pVoid); [DllImport("netapi32.dll", EntryPoint = "DsGetSiteNameW", CharSet = CharSet.Unicode)] - public static extern int DsGetSiteName(string dcName, ref IntPtr ptr); + public static extern int DsGetSiteName(string? dcName, ref IntPtr ptr); public delegate int DsListDomainsInSiteW(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string site, ref IntPtr info); @@ -662,7 +662,7 @@ internal class UnsafeNativeMethods public static extern int NetApiBufferFree(IntPtr buffer); [DllImport("Advapi32.dll", EntryPoint = "LogonUserW", CharSet = CharSet.Unicode, SetLastError = true)] - public static extern int LogonUserW(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); + public static extern int LogonUserW(string? lpszUsername, string? lpszDomain, string? lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); [DllImport("Advapi32.dll", EntryPoint = "ImpersonateLoggedOnUser", SetLastError = true)] public static extern int ImpersonateLoggedOnUser(IntPtr hToken); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs index 6bddb6fba29d0..69cd0a8f6712f 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs @@ -13,8 +13,8 @@ namespace System.DirectoryServices.ActiveDirectory { internal struct Component { - public string Name; - public string Value; + public string? Name; + public string? Value; } internal enum Capability : int @@ -101,7 +101,7 @@ private Utils() { } internal static string GetDnsNameFromDN(string distinguishedName) { int result = 0; - string dnsName = null; + string? dnsName = null; IntPtr results = IntPtr.Zero; Debug.Assert(distinguishedName != null); @@ -183,13 +183,13 @@ internal static string GetDnsNameFromDN(string distinguishedName) throw ExceptionHelper.GetExceptionFromErrorCode(result); } - return dnsName; + return dnsName!; } internal static string GetDNFromDnsName(string dnsName) { int result = 0; - string dn = null; + string? dn = null; IntPtr results = IntPtr.Zero; Debug.Assert(dnsName != null); @@ -251,7 +251,7 @@ internal static string GetDNFromDnsName(string dnsName) throw ExceptionHelper.GetExceptionFromErrorCode(result); } - return dn; + return dn!; } // @@ -262,7 +262,7 @@ internal static string GetDNFromDnsName(string dnsName) // internal static string GetDnsHostNameFromNTDSA(DirectoryContext context, string dn) { - string dcName = null; + string? dcName = null; int index = dn.IndexOf(','); if (index == -1) { @@ -275,7 +275,7 @@ internal static string GetDnsHostNameFromNTDSA(DirectoryContext context, string try { // the "dnsHostName" attribute contains the dns name of the computer - dcName = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.DnsHostName); + dcName = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.DnsHostName)!; } finally { @@ -286,7 +286,7 @@ internal static string GetDnsHostNameFromNTDSA(DirectoryContext context, string internal static string GetAdamDnsHostNameFromNTDSA(DirectoryContext context, string dn) { - string dnsHostName = null; + string? dnsHostName = null; int ldapPort = -1; string ntdsaDn = dn; string serverDn = GetPartialDN(dn, 1); @@ -314,16 +314,16 @@ internal static string GetAdamDnsHostNameFromNTDSA(DirectoryContext context, str foreach (SearchResult res in resCol) { - string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory); + string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory)!; if ((objectCategoryValue.Length >= ntdsdsa.Length) && (Utils.Compare(objectCategoryValue, 0, ntdsdsa.Length, ntdsdsa, 0, ntdsdsa.Length) == 0)) { // ntdsa object - ldapPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP); + ldapPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!; } else { // server object - dnsHostName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName); + dnsHostName = (string?)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName); } } } @@ -343,7 +343,7 @@ internal static string GetAdamDnsHostNameFromNTDSA(DirectoryContext context, str internal static string GetAdamHostNameAndPortsFromNTDSA(DirectoryContext context, string dn) { - string dnsHostName = null; + string? dnsHostName = null; int ldapPort = -1; int sslPort = -1; string ntdsaDn = dn; @@ -373,17 +373,17 @@ internal static string GetAdamHostNameAndPortsFromNTDSA(DirectoryContext context foreach (SearchResult res in resCol) { - string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory); + string objectCategoryValue = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory)!; if ((objectCategoryValue.Length >= ntdsdsa.Length) && (Utils.Compare(objectCategoryValue, 0, ntdsdsa.Length, ntdsdsa, 0, ntdsdsa.Length) == 0)) { // ntdsa object - ldapPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP); - sslPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortSSL); + ldapPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!; + sslPort = (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortSSL)!; } else { // server object - dnsHostName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName); + dnsHostName = (string?)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName); } } } @@ -463,13 +463,13 @@ internal static Component[] GetDNComponents(string distinguishedName) } dnComponents[i].Name = subComponents[0].Trim(); - if (dnComponents[i].Name.Length == 0) + if (dnComponents[i].Name!.Length == 0) { throw new ArgumentException(SR.InvalidDNFormat, nameof(distinguishedName)); } dnComponents[i].Value = subComponents[1].Trim(); - if (dnComponents[i].Value.Length == 0) + if (dnComponents[i].Value!.Length == 0) { throw new ArgumentException(SR.InvalidDNFormat, nameof(distinguishedName)); } @@ -499,13 +499,13 @@ internal static bool IsValidDNFormat(string distinguishedName) } dnComponents[i].Name = subComponents[0].Trim(); - if (dnComponents[i].Name.Length == 0) + if (dnComponents[i].Name!.Length == 0) { return false; } dnComponents[i].Value = subComponents[1].Trim(); - if (dnComponents[i].Value.Length == 0) + if (dnComponents[i].Value!.Length == 0) { return false; } @@ -571,18 +571,18 @@ public static string[] Split(string distinguishedName, char delim) results = new string[resultList.Count]; for (int i = 0; i < resultList.Count; i++) { - results[i] = (string)resultList[i]; + results[i] = (string)resultList[i]!; } return results; } - internal static DirectoryContext GetNewDirectoryContext(string name, DirectoryContextType contextType, DirectoryContext context) + internal static DirectoryContext GetNewDirectoryContext(string? name, DirectoryContextType contextType, DirectoryContext? context) { return new DirectoryContext(contextType, name, context); } - internal static void GetDomainAndUsername(DirectoryContext context, out string username, out string domain) + internal static void GetDomainAndUsername(DirectoryContext context, out string? username, out string? domain) { if ((context.UserName != null) && (context.UserName.Length > 0)) { @@ -611,8 +611,8 @@ internal static IntPtr GetAuthIdentity(DirectoryContext context, LoadLibrarySafe IntPtr authIdentity; int result = 0; - string username; - string domain; + string? username; + string? domain; // split the username from the context into username and domain (if possible) GetDomainAndUsername(context, out username, out domain); @@ -654,7 +654,7 @@ internal static void FreeAuthIdentity(IntPtr authIdentity, LoadLibrarySafeHandle } } - internal static IntPtr GetDSHandle(string domainControllerName, string domainName, IntPtr authIdentity, LoadLibrarySafeHandle libHandle) + internal static IntPtr GetDSHandle(string? domainControllerName, string? domainName, IntPtr authIdentity, LoadLibrarySafeHandle libHandle) { int result = 0; IntPtr handle; @@ -764,7 +764,7 @@ internal static DirectoryEntry GetCrossRefEntry(DirectoryContext context, Direct ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/); - SearchResult res = null; + SearchResult? res = null; try { @@ -781,7 +781,7 @@ internal static DirectoryEntry GetCrossRefEntry(DirectoryContext context, Direct throw ExceptionHelper.GetExceptionFromCOMException(context, e); } - _ = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); + _ = (string?)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); return res.GetDirectoryEntry(); } @@ -794,7 +794,7 @@ internal static ActiveDirectoryTransportType GetTransportTypeFromDN(string DN) Debug.Assert(component.Length == 1); - string transportName = component[0].Value; + string? transportName = component[0].Value; if (string.Equals(transportName, "IP", StringComparison.OrdinalIgnoreCase)) return ActiveDirectoryTransportType.Rpc; @@ -822,9 +822,9 @@ internal static string GetDNFromTransportType(ActiveDirectoryTransportType trans } } - internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid invocationID, DirectoryServer server) + internal static string? GetServerNameFromInvocationID(string? serverObjectDN, Guid invocationID, DirectoryServer server) { - string originatingServerName = null; + string? originatingServerName = null; if (serverObjectDN == null) { @@ -835,7 +835,7 @@ internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid // get the string representation of the invocationID byte[] byteGuid = invocationID.ToByteArray(); IntPtr ptr = (IntPtr)0; - string stringGuid = null; + string? stringGuid = null; // encode the byte arry into binary string representation int hr = UnsafeNativeMethods.ADsEncodeBinaryData(byteGuid, byteGuid.Length, ref ptr); @@ -864,7 +864,7 @@ internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid SearchScope.Subtree, false, /* don't need paged search */ false /* don't need to cache result */); - SearchResult srchResult = null; + SearchResult? srchResult = null; try { @@ -872,7 +872,7 @@ internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid if (srchResult != null) { DirectoryEntry srvEntry = srchResult.GetDirectoryEntry().Parent; - originatingServerName = (string)PropertyManager.GetPropertyValue(server.Context, srvEntry, PropertyManager.DnsHostName); + originatingServerName = (string?)PropertyManager.GetPropertyValue(server.Context, srvEntry, PropertyManager.DnsHostName); } } catch (COMException e) @@ -886,7 +886,7 @@ internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid try { - originatingServerName = (string)PropertyManager.GetPropertyValue(de.Parent, PropertyManager.DnsHostName); + originatingServerName = (string?)PropertyManager.GetPropertyValue(de.Parent, PropertyManager.DnsHostName); } catch (COMException e) { @@ -898,7 +898,7 @@ internal static string GetServerNameFromInvocationID(string serverObjectDN, Guid if (server is AdamInstance) { // we might need to add the port number - int portnumber = (int)PropertyManager.GetPropertyValue(server.Context, de, PropertyManager.MsDSPortLDAP); + int portnumber = (int)PropertyManager.GetPropertyValue(server.Context, de, PropertyManager.MsDSPortLDAP)!; if (portnumber != 389) originatingServerName = originatingServerName + ":" + portnumber; @@ -923,8 +923,8 @@ internal static bool Impersonate(DirectoryContext context) if ((context.UserName == null) && (context.Password == null)) return false; - string userName; - string domainName; + string? userName; + string? domainName; Utils.GetDomainAndUsername(context, out userName, out domainName); @@ -981,9 +981,9 @@ internal static void Revert() } } - internal static string GetPolicyServerName(DirectoryContext context, bool isForest, bool needPdc, string source) + internal static string GetPolicyServerName(DirectoryContext context, bool isForest, bool needPdc, string? source) { - string serverName = null; + string? serverName = null; PrivateLocatorFlags flag = PrivateLocatorFlags.DirectoryServicesRequired; // passes in either domain or forest name, just find the dc @@ -1011,11 +1011,11 @@ internal static string GetPolicyServerName(DirectoryContext context, bool isFore { // need first to decide whether this is a server in the root domain or not DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); - string namingContext = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.DefaultNamingContext); - string rootNamingContext = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.RootDomainNamingContext); + string? namingContext = (string?)PropertyManager.GetPropertyValue(context, de, PropertyManager.DefaultNamingContext); + string? rootNamingContext = (string?)PropertyManager.GetPropertyValue(context, de, PropertyManager.RootDomainNamingContext); if (Compare(namingContext, rootNamingContext) == 0) { - serverName = context.Name; + serverName = context.Name!; } else { @@ -1031,7 +1031,7 @@ internal static string GetPolicyServerName(DirectoryContext context, bool isFore } else { - serverName = context.Name; + serverName = context.Name!; } } @@ -1073,7 +1073,7 @@ internal static IntPtr GetPolicyHandle(string serverName) // (It always searches for one object matching the searching criteria and returns the values for the specified properties using // range retrieval) // - internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string filter, ArrayList propertiesToLoad, SearchScope searchScope) + internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesToLoad, SearchScope searchScope) { return GetValuesWithRangeRetrieval(searchRootEntry, filter, propertiesToLoad, new ArrayList(), searchScope); } @@ -1083,10 +1083,10 @@ internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootE // (It always searches for one object matching the searching criteria and returns the values for the specified properties using // range retrieval) // - internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) + internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootEntry, string? filter, ArrayList propertiesWithRangeRetrieval, ArrayList propertiesWithoutRangeRetrieval, SearchScope searchScope) { ADSearcher searcher = new ADSearcher(searchRootEntry, filter, Array.Empty(), searchScope, false /* paged search */, false /* cache results */); - SearchResult res = null; + SearchResult? res = null; int rangeStart = 0; Hashtable results = new Hashtable(); Hashtable propertyNamesWithRangeInfo = new Hashtable(); @@ -1143,7 +1143,7 @@ internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootE { int index = propertyNameWithRangeInfo.IndexOf(';'); - string propertyName = null; + string? propertyName = null; if (index != -1) { propertyName = propertyNameWithRangeInfo.Substring(0, index); @@ -1159,7 +1159,7 @@ internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootE continue; } - ArrayList values = (ArrayList)results[propertyName]; + ArrayList values = (ArrayList)results[propertyName]!; values.AddRange(res.Properties[propertyNameWithRangeInfo]); if (propertyNamesWithRangeInfo.Contains(propertyName)) @@ -1169,7 +1169,7 @@ internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootE // it in the next round. // - string propertyToLoad = (string)propertyNamesWithRangeInfo[propertyName]; + string propertyToLoad = (string)propertyNamesWithRangeInfo[propertyName]!; if ((propertyNameWithRangeInfo.Length >= propertyToLoad.Length) && (Utils.Compare(propertyToLoad, 0, propertyToLoad.Length, propertyNameWithRangeInfo, 0, propertyToLoad.Length) != 0)) { @@ -1192,7 +1192,7 @@ internal static Hashtable GetValuesWithRangeRetrieval(DirectoryEntry searchRootE return results; } - internal static ArrayList GetReplicaList(DirectoryContext context, string partitionName, string siteName, bool isDefaultNC, bool isADAM, bool isGC) + internal static ArrayList GetReplicaList(DirectoryContext context, string? partitionName, string? siteName, bool isDefaultNC, bool isADAM, bool isGC) { ArrayList ntdsaNames = new ArrayList(); ArrayList dnsNames = new ArrayList(); @@ -1218,7 +1218,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit StringBuilder roServerFilter = new StringBuilder(10); bool useReplicaInfo = false; - string configurationNamingContext = null; + string? configurationNamingContext = null; try { @@ -1248,8 +1248,8 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit if (useReplicaInfo) { - DirectoryEntry partitionsEntry = null; - DirectoryEntry fsmoPartitionsEntry = null; + DirectoryEntry? partitionsEntry = null; + DirectoryEntry? fsmoPartitionsEntry = null; try { @@ -1257,14 +1257,14 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit // get the partitions entry on the naming master // partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, "CN=Partitions," + configurationNamingContext); - string fsmoRoleOwnerName = null; + string? fsmoRoleOwnerName = null; if (isADAM) { - fsmoRoleOwnerName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)); + fsmoRoleOwnerName = Utils.GetAdamDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)!); } else { - fsmoRoleOwnerName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)); + fsmoRoleOwnerName = Utils.GetDnsHostNameFromNTDSA(context, (string)PropertyManager.GetPropertyValue(context, partitionsEntry, PropertyManager.FsmoRoleOwner)!); } DirectoryContext fsmoContext = Utils.GetNewDirectoryContext(fsmoRoleOwnerName, DirectoryContextType.DirectoryServer, context); @@ -1272,12 +1272,12 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit // get the properties using range retrieval // (since msDS-NC-Replica-Locations and msDS-NC-RO-Replica-Locations are multi-valued) - string filter = "(&(" + PropertyManager.ObjectCategory + "=crossRef)(" + PropertyManager.NCName + "=" + Utils.GetEscapedFilterValue(partitionName) + "))"; + string filter = "(&(" + PropertyManager.ObjectCategory + "=crossRef)(" + PropertyManager.NCName + "=" + Utils.GetEscapedFilterValue(partitionName!) + "))"; ArrayList propertyNames = new ArrayList(); propertyNames.Add(PropertyManager.MsDSNCReplicaLocations); propertyNames.Add(PropertyManager.MsDSNCROReplicaLocations); - Hashtable values = null; + Hashtable? values = null; try { values = Utils.GetValuesWithRangeRetrieval(fsmoPartitionsEntry, filter, propertyNames, SearchScope.OneLevel); @@ -1293,8 +1293,8 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit } // extract the property values - ArrayList replicaLocations = (ArrayList)values[PropertyManager.MsDSNCReplicaLocations.ToLowerInvariant()]; - ArrayList roReplicaLocations = (ArrayList)values[PropertyManager.MsDSNCROReplicaLocations.ToLowerInvariant()]; + ArrayList replicaLocations = (ArrayList)values[PropertyManager.MsDSNCReplicaLocations.ToLowerInvariant()]!; + ArrayList roReplicaLocations = (ArrayList)values[PropertyManager.MsDSNCROReplicaLocations.ToLowerInvariant()]!; Debug.Assert(replicaLocations != null); if (replicaLocations.Count == 0) @@ -1350,8 +1350,8 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit } } - string searchRootDN = null; - DirectoryEntry searchRootEntry = null; + string? searchRootDN = null; + DirectoryEntry? searchRootEntry = null; try { // check whether we can narrow down our search within a specific site @@ -1366,7 +1366,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit searchRootEntry = DirectoryEntryManager.GetDirectoryEntry(context, searchRootDN); // set up searcher object - string filter2 = null; + string? filter2 = null; if (ntdsaFilter.ToString().Length == 0) { // either this is the case when we want all the servers (partitionName = null or partitionName is Configuration/Schema) @@ -1447,7 +1447,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit } ADSearcher searcher2 = new ADSearcher(searchRootEntry, filter2, Array.Empty(), SearchScope.Subtree); - SearchResultCollection resCol = null; + SearchResultCollection? resCol = null; bool needToContinueRangeRetrieval = false; ArrayList ntdsaNamesForRangeRetrieval = new ArrayList(); int rangeStart = 0; @@ -1473,13 +1473,13 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit { foreach (SearchResult res in resCol) { - string objectCategory = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory); + string objectCategory = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.ObjectCategory)!; if ((objectCategory.Length >= objectCategoryValue.Length) && (Utils.Compare(objectCategory, 0, objectCategoryValue.Length, objectCategoryValue, 0, objectCategoryValue.Length) == 0)) { // // ntdsa objects (return only those servers which have the partition fully instantiated) // - string ntdsaName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); + string ntdsaName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName)!; if (useReplicaInfo) { if ((objectCategory.Length >= roObjectCategoryValue.Length) && (Utils.Compare(objectCategory, 0, roObjectCategoryValue.Length, roObjectCategoryValue, 0, roObjectCategoryValue.Length) == 0)) @@ -1490,7 +1490,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit ntdsaNames.Add(ntdsaName); if (isADAM) { - serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)); + serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!); } continue; } @@ -1498,7 +1498,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit // Here we need to check if we retrieved all the msDS-HasInstantiatedNCs values // if not we need to continue with the range retrieval (in parallel for the various ntdsa objects) - string propertyName = null; + string? propertyName = null; if (!res.Properties.Contains(propertyWithRangeInfo)) { // find the property name with the range info @@ -1529,7 +1529,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit { Debug.Assert(dnString.Length > 10, "ConfigurationSet::GetReplicaList - dnWithBinary is not in the expected format."); - if (((dnString.Length - 13) >= partitionName.Length) && (Utils.Compare(dnString, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)) + if (((dnString.Length - 13) >= partitionName!.Length) && (Utils.Compare(dnString, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)) { // found the entry that corresponds to this partition so even if we didn't get all the values of the // multivalues attribute we can stop here. @@ -1541,7 +1541,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit ntdsaNames.Add(ntdsaName); if (isADAM) { - serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)); + serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!); } break; } @@ -1563,7 +1563,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit ntdsaNames.Add(ntdsaName); if (isADAM) { - serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)); + serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!); } } } @@ -1573,8 +1573,8 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit // when we try to retrieve this info for a valid DC/GC if (res.Properties.Contains(PropertyManager.DnsHostName)) { - serverNames.Add("CN=NTDS Settings," + (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName), - (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName)); + serverNames.Add("CN=NTDS Settings," + (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName)!, + (string?)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DnsHostName)); } } } @@ -1635,10 +1635,10 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit { foreach (SearchResult res in resCol2) { - string ntdsaName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName); + string ntdsaName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.DistinguishedName)!; // Here we need to check if we retrieved all the msDS-HasInstantiatedNCs values // if not we need to continue with the range retrieval (in parallel for the various ntdsa objects) - string propertyName = null; + string? propertyName = null; if (!res.Properties.Contains(propertyWithRangeInfo2)) { // find the property name with the range info @@ -1669,7 +1669,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit { Debug.Assert(dnString.Length > 10, "ConfigurationSet::GetReplicaList - dnWithBinary is not in the expected format."); - if (((dnString.Length - 13) >= partitionName.Length) && (Utils.Compare(dnString, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)) + if (((dnString.Length - 13) >= partitionName!.Length) && (Utils.Compare(dnString, 13, partitionName.Length, partitionName, 0, partitionName.Length) == 0)) { foundPartitionEntry = true; @@ -1678,7 +1678,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit ntdsaNames.Add(ntdsaName); if (isADAM) { - serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)); + serverPorts.Add(ntdsaName, (int)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.MsDSPortLDAP)!); } break; } @@ -1726,7 +1726,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit // convert the ntdsa object names to server:port foreach (string ntdsaName in ntdsaNames) { - string hostName = (string)serverNames[ntdsaName]; + string? hostName = (string?)serverNames[ntdsaName]; if (hostName == null) { @@ -1752,7 +1752,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string partit if (isADAM) { - dnsNames.Add(hostName + ":" + (int)serverPorts[ntdsaName]); + dnsNames.Add(hostName + ":" + (int)serverPorts[ntdsaName]!); } else { @@ -1838,7 +1838,7 @@ internal static string GetEscapedPath(string originalPath) return pathCracker.GetEscapedElement(0, originalPath); } - internal static int Compare(string s1, string s2, uint compareFlags) + internal static int Compare(string? s1, string? s2, uint compareFlags) { // This code block was specifically written for handling string comparison // involving null strings. The unmanged API "NativeMethods.CompareString" @@ -1885,7 +1885,7 @@ internal static int Compare(string s1, string s2, uint compareFlags) return (result - 2); // to give the semantics of <0, ==0, >0 } - internal static int Compare(string s1, string s2) + internal static int Compare(string? s1, string? s2) { return Compare(s1, s2, DEFAULT_CMP_FLAGS); } @@ -1921,7 +1921,7 @@ internal static int Compare(string s1, int offset1, int length1, string s2, int // DC1 DC1 null // IPv4:Port IPv4 Port // [IPv6]:Port IPv6 Port - internal static string SplitServerNameAndPortNumber(string serverName, out string portNumber) + internal static string SplitServerNameAndPortNumber(string serverName, out string? portNumber) { portNumber = null; @@ -1975,7 +1975,7 @@ internal static string SplitServerNameAndPortNumber(string serverName, out strin return serverName; } - private static string s_NTAuthorityString; + private static string? s_NTAuthorityString; internal static string GetNtAuthorityString() { @@ -2135,7 +2135,7 @@ ref pTokenHandle } // Retrieve the user's SID from the user info - TOKEN_USER tokenUser = (TOKEN_USER)Marshal.PtrToStructure(pBuffer, typeof(TOKEN_USER)); + TOKEN_USER tokenUser = (TOKEN_USER)Marshal.PtrToStructure(pBuffer, typeof(TOKEN_USER))!; IntPtr pUserSid = tokenUser.sidAndAttributes.pSid; // this is a reference into the NATIVE memory (into pBuffer) Debug.Assert(UnsafeNativeMethods.IsValidSid(pUserSid)); @@ -2199,7 +2199,7 @@ internal static IntPtr GetMachineDomainSid() Debug.Assert(pBuffer != IntPtr.Zero); POLICY_ACCOUNT_DOMAIN_INFO info = (POLICY_ACCOUNT_DOMAIN_INFO) - Marshal.PtrToStructure(pBuffer, typeof(POLICY_ACCOUNT_DOMAIN_INFO)); + Marshal.PtrToStructure(pBuffer, typeof(POLICY_ACCOUNT_DOMAIN_INFO))!; Debug.Assert(UnsafeNativeMethods.IsValidSid(info.domainSid)); @@ -2229,7 +2229,7 @@ internal static IntPtr GetMachineDomainSid() } } - internal static bool IsMachineDC(string computerName) + internal static bool IsMachineDC(string? computerName) { IntPtr dsRoleInfoPtr = IntPtr.Zero; int err = -1; @@ -2250,7 +2250,7 @@ internal static bool IsMachineDC(string computerName) } DSROLE_PRIMARY_DOMAIN_INFO_BASIC dsRolePrimaryDomainInfo = - (DSROLE_PRIMARY_DOMAIN_INFO_BASIC)Marshal.PtrToStructure(dsRoleInfoPtr, typeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC)); + (DSROLE_PRIMARY_DOMAIN_INFO_BASIC)Marshal.PtrToStructure(dsRoleInfoPtr, typeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC))!; return (dsRolePrimaryDomainInfo.MachineRole == DSROLE_MACHINE_ROLE.DsRole_RoleBackupDomainController || dsRolePrimaryDomainInfo.MachineRole == DSROLE_MACHINE_ROLE.DsRole_RolePrimaryDomainController); @@ -2270,7 +2270,7 @@ internal static SidType ClassifySID(IntPtr pSid) IntPtr pIdentAuth = UnsafeNativeMethods.GetSidIdentifierAuthority(pSid); SID_IDENTIFIER_AUTHORITY identAuth = - (SID_IDENTIFIER_AUTHORITY)Marshal.PtrToStructure(pIdentAuth, typeof(SID_IDENTIFIER_AUTHORITY)); + (SID_IDENTIFIER_AUTHORITY)Marshal.PtrToStructure(pIdentAuth, typeof(SID_IDENTIFIER_AUTHORITY))!; IntPtr pRid = UnsafeNativeMethods.GetSidSubAuthority(pSid, 0); int rid = Marshal.ReadInt32(pRid); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/Design/DirectoryEntryConverter.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/Design/DirectoryEntryConverter.cs index 8aae67d06a6c2..2bb99779757c8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/Design/DirectoryEntryConverter.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/Design/DirectoryEntryConverter.cs @@ -9,7 +9,7 @@ namespace System.DirectoryServices.Design { internal class DirectoryEntryConverter : TypeConverter { - private static StandardValuesCollection s_values; + private static StandardValuesCollection? s_values; private static readonly Hashtable s_componentsCreated = new Hashtable(StringComparer.OrdinalIgnoreCase); public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) @@ -22,7 +22,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT return base.CanConvertFrom(context, sourceType); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object? ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object? value) { if (value != null && value is string) { @@ -33,7 +33,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (text.CompareTo(SR.DSNotSet) != 0) { - DirectoryEntry newEntry = GetFromCache(text); + DirectoryEntry? newEntry = GetFromCache(text); if (newEntry == null) { newEntry = new DirectoryEntry(text); @@ -49,7 +49,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c return null; } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object? ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object? value, Type? destinationType) { if (destinationType != null && destinationType == typeof(string)) { @@ -66,16 +66,16 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex { if (s_values == null) { - s_values = new StandardValuesCollection(new object[] { null }); + s_values = new StandardValuesCollection(new object?[] { null }); } return s_values; } - internal static DirectoryEntry GetFromCache(string path) + internal static DirectoryEntry? GetFromCache(string path) { if (s_componentsCreated.ContainsKey(path)) { - DirectoryEntry existingComponent = (DirectoryEntry)s_componentsCreated[path]; + DirectoryEntry existingComponent = (DirectoryEntry)s_componentsCreated[path]!; if (existingComponent.Site == null) s_componentsCreated.Remove(path); else diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntries.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntries.cs index f9d3668525b60..8672fd066c3c4 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntries.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntries.cs @@ -63,11 +63,11 @@ public DirectoryEntry Find(string name) /// /// Returns the child with the given name and of the given type. /// - public DirectoryEntry Find(string name, string schemaClassName) + public DirectoryEntry Find(string name, string? schemaClassName) { CheckIsContainer(); // Note: schemaClassName == null does not work for IIS: provider. - object o = null; + object? o = null; try { o = _container.ContainerObject.GetObject(schemaClassName, name); @@ -104,8 +104,8 @@ public void Remove(DirectoryEntry entry) private class ChildEnumerator : IEnumerator { private readonly DirectoryEntry _container; - private SafeNativeMethods.EnumVariant _enumVariant; - private DirectoryEntry _currentEntry; + private SafeNativeMethods.EnumVariant? _enumVariant; + private DirectoryEntry? _currentEntry; internal ChildEnumerator(DirectoryEntry container) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs index 3da8e109e6f68..0534418145746 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs @@ -10,6 +10,7 @@ using System.DirectoryServices.Design; using System.Globalization; using System.Net; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices { @@ -22,7 +23,7 @@ namespace System.DirectoryServices public class DirectoryEntry : Component { private string _path = ""; - private UnsafeNativeMethods.IAds _adsObject; + private UnsafeNativeMethods.IAds? _adsObject; private bool _useCache = true; private bool _cacheFilled; // disable csharp compiler warning #0414: field assigned unused value @@ -31,16 +32,16 @@ public class DirectoryEntry : Component #pragma warning restore 0414 private bool _disposed; private AuthenticationTypes _authenticationType = AuthenticationTypes.Secure; - private NetworkCredential _credentials; + private NetworkCredential? _credentials; private readonly DirectoryEntryConfiguration _options; - private PropertyCollection _propertyCollection; + private PropertyCollection? _propertyCollection; internal bool allowMultipleChange; private bool _userNameIsNull; private bool _passwordIsNull; private bool _objectSecurityInitialized; private bool _objectSecurityModified; - private ActiveDirectorySecurity _objectSecurity; + private ActiveDirectorySecurity? _objectSecurity; private const string SecurityDescriptorProperty = "ntSecurityDescriptor"; /// @@ -55,7 +56,7 @@ public DirectoryEntry() /// Initializes a new instance of the class that will bind /// to the directory entry at . /// - public DirectoryEntry(string path) : this() + public DirectoryEntry(string? path) : this() { Path = path; } @@ -63,14 +64,14 @@ public DirectoryEntry(string path) : this() /// /// Initializes a new instance of the class. /// - public DirectoryEntry(string path, string username, string password) : this(path, username, password, AuthenticationTypes.Secure) + public DirectoryEntry(string? path, string? username, string? password) : this(path, username, password, AuthenticationTypes.Secure) { } /// /// Initializes a new instance of the class. /// - public DirectoryEntry(string path, string username, string password, AuthenticationTypes authenticationType) : this(path) + public DirectoryEntry(string? path, string? username, string? password, AuthenticationTypes authenticationType) : this(path) { _credentials = new NetworkCredential(username, password); if (username == null) @@ -82,7 +83,7 @@ public DirectoryEntry(string path, string username, string password, Authenticat _authenticationType = authenticationType; } - internal DirectoryEntry(string path, bool useCache, string username, string password, AuthenticationTypes authenticationType) + internal DirectoryEntry(string path, bool useCache, string? username, string? password, AuthenticationTypes authenticationType) { _path = path; _useCache = useCache; @@ -107,12 +108,12 @@ public DirectoryEntry(object adsObject) { } - internal DirectoryEntry(object adsObject, bool useCache, string username, string password, AuthenticationTypes authenticationType) + internal DirectoryEntry(object adsObject, bool useCache, string? username, string? password, AuthenticationTypes authenticationType) : this(adsObject, useCache, username, password, authenticationType, false) { } - internal DirectoryEntry(object adsObject, bool useCache, string username, string password, AuthenticationTypes authenticationType, bool AdsObjIsExternal) + internal DirectoryEntry(object adsObject, bool useCache, string? username, string? password, AuthenticationTypes authenticationType, bool AdsObjIsExternal) { _adsObject = adsObject as UnsafeNativeMethods.IAds; if (_adsObject == null) @@ -170,6 +171,7 @@ public AuthenticationTypes AuthenticationType } } + [MemberNotNullWhen(true, nameof(_adsObject))] private bool Bound => _adsObject != null; /// @@ -222,7 +224,7 @@ public ActiveDirectorySecurity ObjectSecurity _objectSecurityInitialized = true; } - return _objectSecurity; + return _objectSecurity!; } set { @@ -303,7 +305,7 @@ public DirectoryEntry Parent /// Gets or sets the password to use when authenticating the client. /// [DefaultValue(null)] - public string Password + public string? Password { set { @@ -332,6 +334,7 @@ public string Password /// Gets or sets the path for this . /// [DefaultValue("")] + [AllowNull] public string Path { get => _path; @@ -423,7 +426,7 @@ public bool UsePropertyCache /// Gets or sets the username to use when authenticating the client. /// [DefaultValue(null)] - public string Username + public string? Username { get { @@ -454,7 +457,7 @@ public string Username } } - public DirectoryEntryConfiguration Options + public DirectoryEntryConfiguration? Options { get { @@ -473,7 +476,7 @@ internal void InitADsObjectOptions() //-------------------------------------------- // Check if ACCUMULATE_MODIFICATION is available //-------------------------------------------- - object o = null; + object? o = null; int unmanagedResult = 0; // check whether the new option is available @@ -505,9 +508,11 @@ internal void InitADsObjectOptions() /// /// Binds to the ADs object (if not already bound). /// + [MemberNotNull(nameof(_adsObject))] private void Bind() { Bind(true); + Debug.Assert(_adsObject != null); } internal void Bind(bool throwIfFail) @@ -527,7 +532,7 @@ internal void Bind(bool throwIfFail) //SECREVIEW: Looking at the root of the DS will demand browse permissions // on "*" or "LDAP://RootDSE". - string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"][0]; + string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"][0]!; rootDSE.Dispose(); pathToUse = "LDAP://" + defaultNamingContext; @@ -538,7 +543,7 @@ internal void Bind(bool throwIfFail) Thread.CurrentThread.SetApartmentState(ApartmentState.MTA); Guid g = new Guid("00000000-0000-0000-c000-000000000046"); // IID_IUnknown - object value = null; + object? value = null; int hr = UnsafeNativeMethods.ADsOpenObject(pathToUse, GetUsername(), GetPassword(), (int)_authenticationType, ref g, out value); if (hr != 0) @@ -587,7 +592,7 @@ public void CommitChanges() // SetObjectSecurityInCache(); - _adsObject.SetInfo(); + _adsObject!.SetInfo(); } catch (COMException e) { @@ -620,7 +625,7 @@ public void CommitChanges() // Write the security descriptor to the cache // SetObjectSecurityInCache(); - _adsObject.SetInfo(); + _adsObject!.SetInfo(); _objectSecurityInitialized = false; _objectSecurityModified = false; } @@ -650,7 +655,7 @@ internal void CommitIfNotCaching() // SetObjectSecurityInCache(); - _adsObject.SetInfo(); + _adsObject!.SetInfo(); _objectSecurityInitialized = false; _objectSecurityModified = false; } @@ -670,12 +675,12 @@ internal void CommitIfNotCaching() /// /// Creates a copy of this entry as a child of the given parent and gives it a new name. /// - public DirectoryEntry CopyTo(DirectoryEntry newParent, string newName) + public DirectoryEntry CopyTo(DirectoryEntry newParent, string? newName) { if (!newParent.IsContainer) throw new InvalidOperationException(SR.Format(SR.DSNotAContainer, newParent.Path)); - object copy = null; + object? copy = null; try { copy = newParent.ContainerObject.CopyHere(Path, newName); @@ -751,12 +756,16 @@ public static bool Exists(string path) /// If UsePropertyCache is true, calls GetInfo the first time it's necessary. /// If it's false, calls GetInfoEx on the given property name. /// + [MemberNotNull(nameof(_adsObject))] internal void FillCache(string propertyName) { if (UsePropertyCache) { if (_cacheFilled) + { + Debug.Assert(_adsObject != null); return; + } RefreshCache(); _cacheFilled = true; @@ -781,11 +790,11 @@ internal void FillCache(string propertyName) /// /// Calls a method on the native Active Directory. /// - public object Invoke(string methodName, params object[] args) + public object? Invoke(string methodName, params object?[] args) { object target = this.NativeObject; Type type = target.GetType(); - object result = null; + object? result = null; try { result = type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, target, args, CultureInfo.InvariantCulture); @@ -810,7 +819,6 @@ public object Invoke(string methodName, params object[] args) } if (result is UnsafeNativeMethods.IAds) - return new DirectoryEntry(result, UsePropertyCache, GetUsername(), GetPassword(), AuthenticationType); else return result; @@ -819,11 +827,11 @@ public object Invoke(string methodName, params object[] args) /// /// Reads a property on the native Active Directory object. /// - public object InvokeGet(string propertyName) + public object? InvokeGet(string propertyName) { object target = this.NativeObject; Type type = target.GetType(); - object result = null; + object? result = null; try { result = type.InvokeMember(propertyName, BindingFlags.GetProperty, null, target, null, CultureInfo.InvariantCulture); @@ -853,7 +861,7 @@ public object InvokeGet(string propertyName) /// /// Sets a property on the native Active Directory object. /// - public void InvokeSet(string propertyName, params object[] args) + public void InvokeSet(string propertyName, params object?[] args) { object target = this.NativeObject; Type type = target.GetType(); @@ -889,9 +897,9 @@ public void InvokeSet(string propertyName, params object[] args) /// /// Moves this entry to the given parent, and gives it a new name. /// - public void MoveTo(DirectoryEntry newParent, string newName) + public void MoveTo(DirectoryEntry newParent, string? newName) { - object newEntry = null; + object? newEntry = null; if (!(newParent.AdsObject is UnsafeNativeMethods.IAdsContainer)) throw new InvalidOperationException(SR.Format(SR.DSNotAContainer, newParent.Path)); try @@ -947,6 +955,7 @@ public void MoveTo(DirectoryEntry newParent, string newName) /// /// Loads the property values for this directory entry into the property cache. /// + [MemberNotNull(nameof(_adsObject))] public void RefreshCache() { Bind(); @@ -1035,7 +1044,7 @@ public void RefreshCache(string[] propertyNames) /// /// Changes the name of this entry. /// - public void Rename(string newName) => MoveTo(Parent, newName); + public void Rename(string? newName) => MoveTo(Parent, newName); private void Unbind() { @@ -1050,7 +1059,7 @@ private void Unbind() _objectSecurityModified = false; } - internal string GetUsername() + internal string? GetUsername() { if (_credentials == null || _userNameIsNull) return null; @@ -1058,7 +1067,7 @@ internal string GetUsername() return _credentials.UserName; } - internal string GetPassword() + internal string? GetPassword() { if (_credentials == null || _passwordIsNull) return null; @@ -1066,7 +1075,7 @@ internal string GetPassword() return _credentials.Password; } - private ActiveDirectorySecurity GetObjectSecurityFromCache() + private ActiveDirectorySecurity? GetObjectSecurityFromCache() { try { @@ -1094,7 +1103,7 @@ private ActiveDirectorySecurity GetObjectSecurityFromCache() // the security descriptor, we will retrieve the "ntSecurityDescriptor" each time // while initializing the ObjectSecurity property // - securityMasksUsedInRetrieval = this.Options.SecurityMasks; + securityMasksUsedInRetrieval = this.Options!.SecurityMasks; RefreshCache(new string[] { SecurityDescriptorProperty }); // diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs index 444455bdae31d..619714bd477f4 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs @@ -8,6 +8,7 @@ using System.ComponentModel; using INTPTR_INTPTRCAST = System.IntPtr; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices { @@ -16,9 +17,9 @@ namespace System.DirectoryServices /// public class DirectorySearcher : Component { - private DirectoryEntry _searchRoot; - private string _filter = defaultFilter; - private StringCollection _propertiesToLoad; + private DirectoryEntry? _searchRoot; + private string? _filter = defaultFilter; + private StringCollection? _propertiesToLoad; private bool _disposed; private static readonly TimeSpan s_minusOneSecond = new TimeSpan(0, 0, -1); @@ -36,17 +37,17 @@ public class DirectorySearcher : Component private bool _cacheResults = true; private bool _cacheResultsSpecified; private bool _rootEntryAllocated; // true: if a temporary entry inside Searcher has been created - private string _assertDefaultNamingContext; + private string? _assertDefaultNamingContext; private string _attributeScopeQuery = ""; private bool _attributeScopeQuerySpecified; private DereferenceAlias _derefAlias = DereferenceAlias.Never; private SecurityMasks _securityMask = SecurityMasks.None; private ExtendedDN _extendedDN = ExtendedDN.None; - private DirectorySynchronization _sync; + private DirectorySynchronization? _sync; internal bool directorySynchronizationSpecified; - private DirectoryVirtualListView _vlv; + private DirectoryVirtualListView? _vlv; internal bool directoryVirtualListViewSpecified; - internal SearchResultCollection searchResult; + internal SearchResultCollection? searchResult; private const string defaultFilter = "(objectClass=*)"; @@ -64,7 +65,7 @@ public DirectorySearcher() : this(null, defaultFilter, null, System.DirectorySer /// , , and set to their default /// values, and set to the given value. /// - public DirectorySearcher(DirectoryEntry searchRoot) : this(searchRoot, defaultFilter, null, System.DirectoryServices.SearchScope.Subtree) + public DirectorySearcher(DirectoryEntry? searchRoot) : this(searchRoot, defaultFilter, null, System.DirectoryServices.SearchScope.Subtree) { _scopeSpecified = false; } @@ -74,7 +75,7 @@ public DirectorySearcher(DirectoryEntry searchRoot) : this(searchRoot, defaultFi /// and set to their default /// values, and and set to the respective given values. /// - public DirectorySearcher(DirectoryEntry searchRoot, string filter) : this(searchRoot, filter, null, System.DirectoryServices.SearchScope.Subtree) + public DirectorySearcher(DirectoryEntry? searchRoot, string? filter) : this(searchRoot, filter, null, System.DirectoryServices.SearchScope.Subtree) { _scopeSpecified = false; } @@ -84,7 +85,7 @@ public DirectorySearcher(DirectoryEntry searchRoot, string filter) : this(search /// set to its default /// value, and , , and set to the respective given values. /// - public DirectorySearcher(DirectoryEntry searchRoot, string filter, string[] propertiesToLoad) : this(searchRoot, filter, propertiesToLoad, System.DirectoryServices.SearchScope.Subtree) + public DirectorySearcher(DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad) : this(searchRoot, filter, propertiesToLoad, System.DirectoryServices.SearchScope.Subtree) { _scopeSpecified = false; } @@ -94,7 +95,7 @@ public DirectorySearcher(DirectoryEntry searchRoot, string filter, string[] prop /// , and set to their default /// values, and set to the given value. /// - public DirectorySearcher(string filter) : this(null, filter, null, System.DirectoryServices.SearchScope.Subtree) + public DirectorySearcher(string? filter) : this(null, filter, null, System.DirectoryServices.SearchScope.Subtree) { _scopeSpecified = false; } @@ -104,7 +105,7 @@ public DirectorySearcher(string filter) : this(null, filter, null, System.Direct /// and set to their default /// values, and and set to the respective given values. /// - public DirectorySearcher(string filter, string[] propertiesToLoad) : this(null, filter, propertiesToLoad, System.DirectoryServices.SearchScope.Subtree) + public DirectorySearcher(string? filter, string[]? propertiesToLoad) : this(null, filter, propertiesToLoad, System.DirectoryServices.SearchScope.Subtree) { _scopeSpecified = false; } @@ -113,7 +114,7 @@ public DirectorySearcher(string filter, string[] propertiesToLoad) : this(null, /// Initializes a new instance of the class with set to its default /// value, and , , and set to the respective given values. /// - public DirectorySearcher(string filter, string[] propertiesToLoad, SearchScope scope) : this(null, filter, propertiesToLoad, scope) + public DirectorySearcher(string? filter, string[]? propertiesToLoad, SearchScope scope) : this(null, filter, propertiesToLoad, scope) { } @@ -121,7 +122,7 @@ public DirectorySearcher(string filter, string[] propertiesToLoad, SearchScope s /// Initializes a new instance of the class with the , , , and properties set to the given /// values. /// - public DirectorySearcher(DirectoryEntry searchRoot, string filter, string[] propertiesToLoad, SearchScope scope) + public DirectorySearcher(DirectoryEntry? searchRoot, string? filter, string[]? propertiesToLoad, SearchScope scope) { _searchRoot = searchRoot; _filter = filter; @@ -137,7 +138,7 @@ protected override void Dispose(bool disposing) if (!_disposed && disposing) { if (_rootEntryAllocated) - _searchRoot.Dispose(); + _searchRoot!.Dispose(); _rootEntryAllocated = false; _disposed = true; } @@ -195,7 +196,7 @@ public TimeSpan ClientTimeout /// Gets or sets the Lightweight Directory Access Protocol (LDAP) filter string format. /// [DefaultValue(defaultFilter)] - public string Filter + public string? Filter { get => _filter; set @@ -346,7 +347,7 @@ public int SizeLimit /// at which the search will start. /// [DefaultValue(null)] - public DirectoryEntry SearchRoot + public DirectoryEntry? SearchRoot { get { @@ -357,7 +358,7 @@ public DirectoryEntry SearchRoot //SECREVIEW: Searching the root of the DS will demand browse permissions // on "*" or "LDAP://RootDSE". - string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"][0]; + string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"][0]!; rootDSE.Dispose(); _searchRoot = new DirectoryEntry("LDAP://" + defaultNamingContext, true, null, null, AuthenticationTypes.Secure); @@ -369,7 +370,7 @@ public DirectoryEntry SearchRoot set { if (_rootEntryAllocated) - _searchRoot.Dispose(); + _searchRoot!.Dispose(); _rootEntryAllocated = false; _assertDefaultNamingContext = null; @@ -406,6 +407,7 @@ public SortOption Sort /// performed. /// [DefaultValue("")] + [AllowNull] public string AttributeScopeQuery { get => _attributeScopeQuery; @@ -494,14 +496,14 @@ public ExtendedDN ExtendedDN /// state. /// [DefaultValue(null)] - public DirectorySynchronization DirectorySynchronization + public DirectorySynchronization? DirectorySynchronization { get { // if user specifies dirsync search preference and search is executed if (directorySynchronizationSpecified && searchResult != null) { - _sync.ResetDirectorySynchronizationCookie(searchResult.DirsyncCookie); + _sync!.ResetDirectorySynchronizationCookie(searchResult.DirsyncCookie); } return _sync; } @@ -531,7 +533,7 @@ public DirectorySynchronization DirectorySynchronization /// control. /// [DefaultValue(null)] - public DirectoryVirtualListView VirtualListView + public DirectoryVirtualListView? VirtualListView { get { @@ -539,7 +541,7 @@ public DirectoryVirtualListView VirtualListView if (directoryVirtualListViewSpecified && searchResult != null) { DirectoryVirtualListView tempval = searchResult.VLVResponse; - _vlv.Offset = tempval.Offset; + _vlv!.Offset = tempval.Offset; _vlv.ApproximateTotal = tempval.ApproximateTotal; _vlv.DirectoryVirtualListViewContext = tempval.DirectoryVirtualListViewContext; if (_vlv.ApproximateTotal != 0) @@ -574,11 +576,11 @@ public DirectoryVirtualListView VirtualListView /// /// Executes the search and returns only the first entry that is found. /// - public SearchResult FindOne() + public SearchResult? FindOne() { - DirectorySynchronization tempsync = null; - DirectoryVirtualListView tempvlv = null; - SearchResult resultEntry = null; + DirectorySynchronization? tempsync = null; + DirectoryVirtualListView? tempvlv = null; + SearchResult? resultEntry = null; SearchResultCollection results = FindAll(false); @@ -616,7 +618,7 @@ public SearchResult FindOne() private SearchResultCollection FindAll(bool findMoreThanOne) { - DirectoryEntry clonedRoot = SearchRoot.CloneBrowsable(); + DirectoryEntry clonedRoot = SearchRoot!.CloneBrowsable(); UnsafeNativeMethods.IAds adsObject = clonedRoot.AdsObject; if (!(adsObject is UnsafeNativeMethods.IDirectorySearch)) @@ -636,7 +638,7 @@ private SearchResultCollection FindAll(bool findMoreThanOne) UnsafeNativeMethods.IDirectorySearch adsSearch = (UnsafeNativeMethods.IDirectorySearch)adsObject; SetSearchPreferences(adsSearch, findMoreThanOne); - string[] properties = null; + string[]? properties = null; if (PropertiesToLoad.Count > 0) { if (!PropertiesToLoad.Contains("ADsPath")) @@ -789,7 +791,7 @@ private unsafe void SetSearchPreferences(UnsafeNativeMethods.IDirectorySearch ad { info = default; info.dwSearchPref = (int)AdsSearchPreferences.DIRSYNC; - info.vValue = new AdsValueHelper(DirectorySynchronization.GetDirectorySynchronizationCookie(), AdsType.ADSTYPE_PROV_SPECIFIC).GetStruct(); + info.vValue = new AdsValueHelper(DirectorySynchronization!.GetDirectorySynchronizationCookie(), AdsType.ADSTYPE_PROV_SPECIFIC).GetStruct(); prefList.Add(info); if (DirectorySynchronization.Option != DirectorySynchronizationOptions.None) @@ -829,7 +831,7 @@ private unsafe void SetSearchPreferences(UnsafeNativeMethods.IDirectorySearch ad info = default; info.dwSearchPref = (int)AdsSearchPreferences.VLV; AdsVLV vlvValue = new AdsVLV(); - vlvValue.beforeCount = _vlv.BeforeCount; + vlvValue.beforeCount = _vlv!.BeforeCount; vlvValue.afterCount = _vlv.AfterCount; vlvValue.offset = _vlv.Offset; //we need to treat the empty string as null here @@ -880,7 +882,7 @@ private unsafe void SetSearchPreferences(UnsafeNativeMethods.IDirectorySearch ad AdsSearchPreferenceInfo[] prefs = new AdsSearchPreferenceInfo[prefList.Count]; for (int i = 0; i < prefList.Count; i++) { - prefs[i] = (AdsSearchPreferenceInfo)prefList[i]; + prefs[i] = (AdsSearchPreferenceInfo)prefList[i]!; } DoSetSearchPrefs(adsSearch, prefs); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs index 090dfc6d16fd2..8883d62821d45 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesCOMException.cs @@ -14,15 +14,15 @@ public class DirectoryServicesCOMException : COMException, ISerializable { public DirectoryServicesCOMException() { } - public DirectoryServicesCOMException(string message) : base(message) { } + public DirectoryServicesCOMException(string? message) : base(message) { } - public DirectoryServicesCOMException(string message, Exception inner) : base(message, inner) { } + public DirectoryServicesCOMException(string? message, Exception? inner) : base(message, inner) { } protected DirectoryServicesCOMException(SerializationInfo info, StreamingContext context) : base(info, context) { } - internal DirectoryServicesCOMException(string extendedMessage, int extendedError, COMException e) : base(e.Message, e.ErrorCode) + internal DirectoryServicesCOMException(string? extendedMessage, int extendedError, COMException e) : base(e.Message, e.ErrorCode) { ExtendedError = extendedError; ExtendedErrorMessage = extendedMessage; @@ -30,7 +30,7 @@ internal DirectoryServicesCOMException(string extendedMessage, int extendedError public int ExtendedError { get; } - public string ExtendedErrorMessage { get; } + public string? ExtendedErrorMessage { get; } public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermission.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermission.cs index 27cab3be2254c..4eb0362e1fbe2 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermission.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermission.cs @@ -9,9 +9,9 @@ namespace System.DirectoryServices public sealed class DirectoryServicesPermission : ResourcePermissionBase { public DirectoryServicesPermission() { } - public DirectoryServicesPermission(DirectoryServicesPermissionEntry[] permissionAccessEntries) { } + public DirectoryServicesPermission(DirectoryServicesPermissionEntry[]? permissionAccessEntries) { } public DirectoryServicesPermission(PermissionState state) { } - public DirectoryServicesPermission(DirectoryServicesPermissionAccess permissionAccess, string path) { } - public DirectoryServicesPermissionEntryCollection PermissionEntries { get; } + public DirectoryServicesPermission(DirectoryServicesPermissionAccess permissionAccess, string? path) { } + public DirectoryServicesPermissionEntryCollection? PermissionEntries { get; } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionAttribute.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionAttribute.cs index 43c3986daeaa9..4194422435f1d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionAttribute.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionAttribute.cs @@ -14,7 +14,7 @@ public class DirectoryServicesPermissionAttribute : CodeAccessSecurityAttribute { public DirectoryServicesPermissionAttribute(SecurityAction action) : base(default(SecurityAction)) { } public DirectoryServicesPermissionAccess PermissionAccess { get; set; } - public string Path { get; set; } - public override IPermission CreatePermission() { return default(IPermission); } + public string? Path { get; set; } + public override IPermission? CreatePermission() { return default(IPermission); } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntry.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntry.cs index b0652e16c1373..de30e7043ca42 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntry.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntry.cs @@ -5,8 +5,8 @@ namespace System.DirectoryServices { public class DirectoryServicesPermissionEntry { - public DirectoryServicesPermissionEntry(DirectoryServicesPermissionAccess permissionAccess, string path) { } - public string Path { get; } + public DirectoryServicesPermissionEntry(DirectoryServicesPermissionAccess permissionAccess, string? path) { } + public string? Path { get; } public DirectoryServicesPermissionAccess PermissionAccess { get; } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntryCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntryCollection.cs index 77c55d496887f..d7ac7cea79213 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntryCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryServicesPermissionEntryCollection.cs @@ -8,7 +8,7 @@ namespace System.DirectoryServices public class DirectoryServicesPermissionEntryCollection : CollectionBase { internal DirectoryServicesPermissionEntryCollection() { } - public DirectoryServicesPermissionEntry this[int index] { get { return null; } set { } } + public DirectoryServicesPermissionEntry? this[int index] { get { return null; } set { } } public int Add(DirectoryServicesPermissionEntry value) { return 0; } public void AddRange(DirectoryServicesPermissionEntryCollection value) { } public void AddRange(DirectoryServicesPermissionEntry[] value) { } @@ -17,9 +17,9 @@ public void CopyTo(DirectoryServicesPermissionEntry[] array, int index) { } public int IndexOf(DirectoryServicesPermissionEntry value) { return 0; } public void Insert(int index, DirectoryServicesPermissionEntry value) { } protected override void OnClear() { } - protected override void OnInsert(int index, object value) { } - protected override void OnRemove(int index, object value) { } - protected override void OnSet(int index, object oldValue, object newValue) { } - public void Remove(DirectoryServicesPermissionEntry value) { } + protected override void OnInsert(int index, object? value) { } + protected override void OnRemove(int index, object? value) { } + protected override void OnSet(int index, object? oldValue, object? newValue) { } + public void Remove(DirectoryServicesPermissionEntry? value) { } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySynchronization.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySynchronization.cs index fc624420ebd40..dc948c74a18d7 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySynchronization.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySynchronization.cs @@ -19,7 +19,7 @@ public DirectorySynchronization(DirectorySynchronizationOptions option) Option = option; } - public DirectorySynchronization(DirectorySynchronization sync) + public DirectorySynchronization(DirectorySynchronization? sync) { if (sync != null) { @@ -28,9 +28,9 @@ public DirectorySynchronization(DirectorySynchronization sync) } } - public DirectorySynchronization(byte[] cookie) => ResetDirectorySynchronizationCookie(cookie); + public DirectorySynchronization(byte[]? cookie) => ResetDirectorySynchronizationCookie(cookie); - public DirectorySynchronization(DirectorySynchronizationOptions option, byte[] cookie) + public DirectorySynchronization(DirectorySynchronizationOptions option, byte[]? cookie) { Option = option; ResetDirectorySynchronizationCookie(cookie); @@ -67,7 +67,7 @@ public byte[] GetDirectorySynchronizationCookie() public void ResetDirectorySynchronizationCookie() => _cookie = Array.Empty(); - public void ResetDirectorySynchronizationCookie(byte[] cookie) + public void ResetDirectorySynchronizationCookie(byte[]? cookie) { if (cookie == null) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListView.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListView.cs index c80bd878925a5..8a6b8b122afe3 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListView.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListView.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices { @@ -30,14 +31,14 @@ public DirectoryVirtualListView(int beforeCount, int afterCount, int offset) Offset = offset; } - public DirectoryVirtualListView(int beforeCount, int afterCount, string target) + public DirectoryVirtualListView(int beforeCount, int afterCount, string? target) { BeforeCount = beforeCount; AfterCount = afterCount; Target = target; } - public DirectoryVirtualListView(int beforeCount, int afterCount, int offset, DirectoryVirtualListViewContext context) + public DirectoryVirtualListView(int beforeCount, int afterCount, int offset, DirectoryVirtualListViewContext? context) { BeforeCount = beforeCount; AfterCount = afterCount; @@ -45,7 +46,7 @@ public DirectoryVirtualListView(int beforeCount, int afterCount, int offset, Dir DirectoryVirtualListViewContext = context; } - public DirectoryVirtualListView(int beforeCount, int afterCount, string target, DirectoryVirtualListViewContext context) + public DirectoryVirtualListView(int beforeCount, int afterCount, string? target, DirectoryVirtualListViewContext? context) { BeforeCount = beforeCount; AfterCount = afterCount; @@ -123,6 +124,7 @@ public int TargetPercentage } [DefaultValue("")] + [AllowNull] public string Target { get => _target; @@ -145,6 +147,6 @@ public int ApproximateTotal } [DefaultValue(null)] - public DirectoryVirtualListViewContext DirectoryVirtualListViewContext { get; set; } + public DirectoryVirtualListViewContext? DirectoryVirtualListViewContext { get; set; } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListViewContext.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListViewContext.cs index bdee39650abd9..cc1d2170acf7d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListViewContext.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryVirtualListViewContext.cs @@ -11,7 +11,7 @@ public DirectoryVirtualListViewContext() : this(null) { } - internal DirectoryVirtualListViewContext(byte[] context) + internal DirectoryVirtualListViewContext(byte[]? context) { if (context == null) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs index 260b3afc80ec5..5c8b1d57e5716 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs @@ -35,7 +35,7 @@ public PropertyValueCollection this[string propertyName] string name = propertyName.ToLowerInvariant(); if (valueTable.Contains(name)) - return (PropertyValueCollection)valueTable[name]; + return (PropertyValueCollection)valueTable[name]!; else { PropertyValueCollection value = new PropertyValueCollection(_entry, propertyName); @@ -69,7 +69,7 @@ public int Count public bool Contains(string propertyName) { - object var; + object? var; int unmanagedResult = _entry.AdsObject.GetEx(propertyName, out var); if (unmanagedResult != 0) { @@ -115,7 +115,7 @@ public IDictionaryEnumerator GetEnumerator() return new PropertyEnumerator(_entry, entryToUse); } - object IDictionary.this[object key] + object? IDictionary.this[object key] { get => this[(string)key]; set => throw new NotSupportedException(SR.DSPropertySetSupported); @@ -127,7 +127,7 @@ object IDictionary.this[object key] ICollection IDictionary.Keys => new KeysCollection(this); - void IDictionary.Add(object key, object value) + void IDictionary.Add(object key, object? value) { throw new NotSupportedException(SR.DSAddNotSupported); } @@ -175,7 +175,7 @@ private class PropertyEnumerator : IDictionaryEnumerator, IDisposable { private readonly DirectoryEntry _entry; // clone (to be disposed) private readonly DirectoryEntry _parentEntry; // original entry to pass to PropertyValueCollection - private string _currentPropName; + private string? _currentPropName; public PropertyEnumerator(DirectoryEntry parent, DirectoryEntry clone) { @@ -199,7 +199,7 @@ protected virtual void Dispose(bool disposing) } } - public object Current => Entry.Value; + public object? Current => Entry.Value; public DictionaryEntry Entry { @@ -214,11 +214,11 @@ public DictionaryEntry Entry public object Key => Entry.Key; - public object Value => Entry.Value; + public object? Value => Entry.Value; public bool MoveNext() { - object prop; + object? prop; int hr = 0; try { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyValueCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyValueCollection.cs index 20e3cefde6c6b..4ae15eb0b7a9d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyValueCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyValueCollection.cs @@ -46,7 +46,7 @@ internal PropertyValueCollection(DirectoryEntry entry, string propertyName) } } - public object this[int index] + public object? this[int index] { get => List[index]; set @@ -62,7 +62,7 @@ public object this[int index] public string PropertyName { get; } - public object Value + public object? Value { get { @@ -116,7 +116,7 @@ public object Value else _changeList.Add(value); - object[] allValues = new object[_changeList.Count]; + object?[] allValues = new object[_changeList.Count]; _changeList.CopyTo(allValues, 0); _entry.AdsObject.PutEx((int)AdsPropertyOperation.Update, PropertyName, allValues); @@ -130,12 +130,12 @@ public object Value /// /// Appends the value to the set of values for this property. /// - public int Add(object value) => List.Add(value); + public int Add(object? value) => List.Add(value); /// /// Appends the values to the set of values for this property. /// - public void AddRange(object[] value) + public void AddRange(object?[] value) { if (value == null) { @@ -163,20 +163,20 @@ public void AddRange(PropertyValueCollection value) } } - public bool Contains(object value) => List.Contains(value); + public bool Contains(object? value) => List.Contains(value); /// /// Copies the elements of this instance into an , /// starting at a particular index into the given . /// - public void CopyTo(object[] array, int index) + public void CopyTo(object?[] array, int index) { List.CopyTo(array, index); } - public int IndexOf(object value) => List.IndexOf(value); + public int IndexOf(object? value) => List.IndexOf(value); - public void Insert(int index, object value) => List.Insert(index, value); + public void Insert(int index, object? value) => List.Insert(index, value); private void PopulateList() { @@ -184,7 +184,7 @@ private void PopulateList() //call to GetInfo will be called against an uninitialized property //cache. Which is exactly what FillCache does. //entry.FillCache(propertyName); - object var; + object? var; int unmanagedResult = _entry.AdsObject.GetEx(PropertyName, out var); if (unmanagedResult != 0) { @@ -207,7 +207,7 @@ private void PopulateList() /// /// Removes the value from the collection. /// - public void Remove(object value) + public void Remove(object? value) { if (_needNewBehavior) { @@ -247,7 +247,7 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object value) + protected override void OnInsertComplete(int index, object? value) { if (_needNewBehavior) { @@ -268,7 +268,7 @@ protected override void OnInsertComplete(int index, object value) } else { - _entry.AdsObject.PutEx((int)AdsPropertyOperation.Append, PropertyName, new object[] { value }); + _entry.AdsObject.PutEx((int)AdsPropertyOperation.Append, PropertyName, new object?[] { value }); } } else @@ -280,7 +280,7 @@ protected override void OnInsertComplete(int index, object value) _entry.CommitIfNotCaching(); } - protected override void OnRemoveComplete(int index, object value) + protected override void OnRemoveComplete(int index, object? value) { if (_needNewBehavior) { @@ -292,7 +292,7 @@ protected override void OnRemoveComplete(int index, object value) } _changeList.Add(value); - object[] allValues = new object[_changeList.Count]; + object?[] allValues = new object[_changeList.Count]; _changeList.CopyTo(allValues, 0); _entry.AdsObject.PutEx((int)AdsPropertyOperation.Delete, PropertyName, allValues); @@ -300,12 +300,12 @@ protected override void OnRemoveComplete(int index, object value) } else { - _entry.AdsObject.PutEx((int)AdsPropertyOperation.Delete, PropertyName, new object[] { value }); + _entry.AdsObject.PutEx((int)AdsPropertyOperation.Delete, PropertyName, new object?[] { value }); } } else { - object[] allValues = new object[InnerList.Count]; + object?[] allValues = new object[InnerList.Count]; InnerList.CopyTo(allValues, 0); _entry.AdsObject.PutEx((int)AdsPropertyOperation.Update, PropertyName, allValues); } @@ -313,7 +313,7 @@ protected override void OnRemoveComplete(int index, object value) _entry.CommitIfNotCaching(); } - protected override void OnSetComplete(int index, object oldValue, object newValue) + protected override void OnSetComplete(int index, object? oldValue, object? newValue) { // no need to consider the not allowing accumulative change case as it does not support Set if (Count <= 1) @@ -324,12 +324,12 @@ protected override void OnSetComplete(int index, object oldValue, object newValu { if (_needNewBehavior) { - _entry.AdsObject.PutEx((int)AdsPropertyOperation.Delete, PropertyName, new object[] { oldValue }); - _entry.AdsObject.PutEx((int)AdsPropertyOperation.Append, PropertyName, new object[] { newValue }); + _entry.AdsObject.PutEx((int)AdsPropertyOperation.Delete, PropertyName, new object?[] { oldValue }); + _entry.AdsObject.PutEx((int)AdsPropertyOperation.Append, PropertyName, new object?[] { newValue }); } else { - object[] allValues = new object[InnerList.Count]; + object?[] allValues = new object[InnerList.Count]; InnerList.CopyTo(allValues, 0); _entry.AdsObject.PutEx((int)AdsPropertyOperation.Update, PropertyName, allValues); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyCollection.cs index ee2e3b55b37bb..b2a251d0b3b9d 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyCollection.cs @@ -25,7 +25,7 @@ public ResultPropertyValueCollection this[string name] object objectName = name.ToLowerInvariant(); if (Contains((string)objectName)) { - return (ResultPropertyValueCollection)InnerHashtable[objectName]; + return (ResultPropertyValueCollection)InnerHashtable[objectName]!; } else { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs index 91665d2b904d5..2dc1281b17c21 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs @@ -10,16 +10,16 @@ namespace System.DirectoryServices /// public class ResultPropertyValueCollection : ReadOnlyCollectionBase { - internal ResultPropertyValueCollection(object[] values) + internal ResultPropertyValueCollection(object?[] values) { InnerList.AddRange(values ?? Array.Empty()); } - public object this[int index] + public object? this[int index] { get { - object returnValue = InnerList[index]; + object? returnValue = InnerList[index]; if (returnValue is Exception) throw (Exception)returnValue; else @@ -27,10 +27,10 @@ public object this[int index] } } - public bool Contains(object value) => InnerList.Contains(value); + public bool Contains(object? value) => InnerList.Contains(value); - public int IndexOf(object value) => InnerList.IndexOf(value); + public int IndexOf(object? value) => InnerList.IndexOf(value); - public void CopyTo(object[] values, int index) => InnerList.CopyTo(values, index); + public void CopyTo(object?[] values, int index) => InnerList.CopyTo(values, index); } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SchemaNameCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SchemaNameCollection.cs index 0e243cdff3816..2a2c6ab2a6ba8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SchemaNameCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SchemaNameCollection.cs @@ -23,16 +23,16 @@ internal SchemaNameCollection(VariantPropGetter propGetter, VariantPropSetter pr /// /// Gets or sets the object at the given index. /// - public string this[int index] + public string? this[int index] { get { - object[] values = GetValue(); - return (string)values[index]; + object?[] values = GetValue(); + return (string?)values[index]; } set { - object[] values = GetValue(); + object?[] values = GetValue(); values[index] = value; _propSetter(values); } @@ -45,7 +45,7 @@ public int Count { get { - object[] values = GetValue(); + object?[] values = GetValue(); return values.Length; } } @@ -53,10 +53,10 @@ public int Count /// /// Appends the value to the collection. /// - public int Add(string value) + public int Add(string? value) { - object[] oldValues = GetValue(); - object[] newValues = new object[oldValues.Length + 1]; + object?[] oldValues = GetValue(); + object?[] newValues = new object[oldValues.Length + 1]; for (int i = 0; i < oldValues.Length; i++) newValues[i] = oldValues[i]; newValues[newValues.Length - 1] = value; @@ -67,14 +67,14 @@ public int Add(string value) /// /// Appends the values to the collection. /// - public void AddRange(string[] value) + public void AddRange(string?[] value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } - object[] oldValues = GetValue(); - object[] newValues = new object[oldValues.Length + value.Length]; + object?[] oldValues = GetValue(); + object?[] newValues = new object[oldValues.Length + value.Length]; for (int i = 0; i < oldValues.Length; i++) newValues[i] = oldValues[i]; for (int i = oldValues.Length; i < newValues.Length; i++) @@ -88,8 +88,8 @@ public void AddRange(SchemaNameCollection value) { throw new ArgumentNullException(nameof(value)); } - object[] oldValues = GetValue(); - object[] newValues = new object[oldValues.Length + value.Count]; + object?[] oldValues = GetValue(); + object?[] newValues = new object?[oldValues.Length + value.Count]; for (int i = 0; i < oldValues.Length; i++) newValues[i] = oldValues[i]; for (int i = oldValues.Length; i < newValues.Length; i++) @@ -108,38 +108,38 @@ public void Clear() /// /// Determines if the collection contains a specific value. /// - public bool Contains(string value) => IndexOf(value) != -1; + public bool Contains(string? value) => IndexOf(value) != -1; - public void CopyTo(string[] stringArray, int index) + public void CopyTo(string?[] stringArray, int index) { - object[] values = GetValue(); + object?[] values = GetValue(); values.CopyTo(stringArray, index); } public IEnumerator GetEnumerator() { - object[] values = GetValue(); + object?[] values = GetValue(); return values.GetEnumerator(); } - private object[] GetValue() + private object?[] GetValue() { - object value = _propGetter(); + object? value = _propGetter(); if (value == null) return Array.Empty(); else - return (object[])value; + return (object?[])value; } /// /// Determines the index of a specific item in the collection. /// - public int IndexOf(string value) + public int IndexOf(string? value) { - object[] values = GetValue(); + object?[] values = GetValue(); for (int i = 0; i < values.Length; i++) { - if (value == (string)values[i]) + if (value == (string?)values[i]) return i; } return -1; @@ -148,7 +148,7 @@ public int IndexOf(string value) /// /// Inserts an item at the specified position in the collection. /// - public void Insert(int index, string value) + public void Insert(int index, string? value) { ArrayList tmpList = new ArrayList((ICollection)GetValue()); tmpList.Insert(index, value); @@ -158,7 +158,7 @@ public void Insert(int index, string value) /// /// Removes an item from the collection. /// - public void Remove(string value) + public void Remove(string? value) { // this does take two scans of the array, but value isn't guaranteed to be there. int index = IndexOf(value); @@ -170,11 +170,11 @@ public void Remove(string value) /// public void RemoveAt(int index) { - object[] oldValues = GetValue(); + object?[] oldValues = GetValue(); if (index >= oldValues.Length || index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - object[] newValues = new object[oldValues.Length - 1]; + object?[] newValues = new object[oldValues.Length - 1]; for (int i = 0; i < index; i++) newValues[i] = oldValues[i]; for (int i = index + 1; i < oldValues.Length; i++) @@ -188,7 +188,7 @@ public void RemoveAt(int index) void ICollection.CopyTo(Array array, int index) { - object[] values = GetValue(); + object?[] values = GetValue(); values.CopyTo(array, index); } @@ -196,24 +196,24 @@ void ICollection.CopyTo(Array array, int index) object ICollection.SyncRoot => this; - object IList.this[int index] + object? IList.this[int index] { get => this[index]; - set => this[index] = (string)value; + set => this[index] = (string?)value; } - int IList.Add(object value) => Add((string)value); + int IList.Add(object? value) => Add((string?)value); - bool IList.Contains(object value) => Contains((string)value); + bool IList.Contains(object? value) => Contains((string?)value); - int IList.IndexOf(object value) => IndexOf((string)value); + int IList.IndexOf(object? value) => IndexOf((string?)value); - void IList.Insert(int index, object value) => Insert(index, (string)value); + void IList.Insert(int index, object? value) => Insert(index, (string?)value); - void IList.Remove(object value) => Remove((string)value); + void IList.Remove(object? value) => Remove((string?)value); - internal delegate object VariantPropGetter(); - internal delegate void VariantPropSetter(object value); + internal delegate object? VariantPropGetter(); + internal delegate void VariantPropSetter(object? value); // this class and HintsDelegateWrapper exist only because you can't create // a delegate to a property's accessors. You have to supply methods. So these @@ -230,9 +230,9 @@ internal FilterDelegateWrapper(UnsafeNativeMethods.IAdsContainer wrapped) public VariantPropSetter Setter => new VariantPropSetter(SetFilter); - private object GetFilter() => _obj.Filter; + private object? GetFilter() => _obj.Filter; - private void SetFilter(object value) => _obj.Filter = value; + private void SetFilter(object? value) => _obj.Filter = value; } } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResult.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResult.cs index cbe7b56fbbdc6..32e1a42ca3fb2 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResult.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResult.cs @@ -11,10 +11,10 @@ namespace System.DirectoryServices /// public class SearchResult { - private readonly NetworkCredential _parentCredentials; + private readonly NetworkCredential? _parentCredentials; private readonly AuthenticationTypes _parentAuthenticationType; - internal SearchResult(NetworkCredential parentCredentials, AuthenticationTypes parentAuthenticationType) + internal SearchResult(NetworkCredential? parentCredentials, AuthenticationTypes parentAuthenticationType) { _parentCredentials = parentCredentials; _parentAuthenticationType = parentAuthenticationType; @@ -38,7 +38,7 @@ public DirectoryEntry GetDirectoryEntry() /// /// Gets the path for this . /// - public string Path => (string)Properties["ADsPath"][0]; + public string Path => (string)Properties["ADsPath"][0]!; /// /// Gets a diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs index 4178c0524a38b..129df11fbebd2 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs @@ -18,8 +18,8 @@ namespace System.DirectoryServices public class SearchResultCollection : MarshalByRefObject, ICollection, IEnumerable, IDisposable { private IntPtr _handle; - private UnsafeNativeMethods.IDirectorySearch _searchObject; - private ArrayList _innerList; + private UnsafeNativeMethods.IDirectorySearch? _searchObject; + private ArrayList? _innerList; private bool _disposed; private readonly DirectoryEntry _rootEntry; // clone of parent entry object private const string ADS_DIRSYNC_COOKIE = "fc8cb04d-311d-406c-8cb9-1ae8b843b418"; @@ -37,11 +37,11 @@ internal SearchResultCollection(DirectoryEntry root, IntPtr searchHandle, string this.srch = srch; } - public SearchResult this[int index] => (SearchResult)InnerList[index]; + public SearchResult this[int index] => (SearchResult)InnerList[index]!; public int Count => InnerList.Count; - internal string Filter { get; } + internal string? Filter { get; } private ArrayList InnerList { @@ -50,10 +50,12 @@ private ArrayList InnerList if (_innerList == null) { _innerList = new ArrayList(); - IEnumerator enumerator = new ResultsEnumerator(this, - _rootEntry.GetUsername(), - _rootEntry.GetPassword(), - _rootEntry.AuthenticationType); + IEnumerator enumerator = new ResultsEnumerator( + this, + _rootEntry.GetUsername(), + _rootEntry.GetPassword(), + _rootEntry.AuthenticationType); + while (enumerator.MoveNext()) _innerList.Add(enumerator.Current); } @@ -228,14 +230,14 @@ void ICollection.CopyTo(Array array, int index) /// private class ResultsEnumerator : IEnumerator { - private readonly NetworkCredential _parentCredentials; + private readonly NetworkCredential? _parentCredentials; private readonly AuthenticationTypes _parentAuthenticationType; private readonly SearchResultCollection _results; private bool _initialized; - private SearchResult _currentResult; + private SearchResult? _currentResult; private bool _eof; - internal ResultsEnumerator(SearchResultCollection results, string parentUserName, string parentPassword, AuthenticationTypes parentAuthenticationType) + internal ResultsEnumerator(SearchResultCollection results, string? parentUserName, string? parentPassword, AuthenticationTypes parentAuthenticationType) { if (parentUserName != null && parentPassword != null) _parentCredentials = new NetworkCredential(parentUserName, parentPassword); @@ -285,7 +287,7 @@ private unsafe SearchResult GetCurrentResult() values[i] = new AdsValueHelper(*pValue).GetValue(); pValue++; } - entry.Properties.Add(Marshal.PtrToStringUni(pszColumnName), new ResultPropertyValueCollection(values)); + entry.Properties.Add(Marshal.PtrToStringUni(pszColumnName)!, new ResultPropertyValueCollection(values)); } finally { @@ -314,8 +316,8 @@ private unsafe SearchResult GetCurrentResult() /// public bool MoveNext() { - DirectorySynchronization tempsync = null; - DirectoryVirtualListView tempvlv = null; + DirectorySynchronization? tempsync = null; + DirectoryVirtualListView? tempvlv = null; int errorCode = 0; if (_eof) diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SortOption.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SortOption.cs index 4e70a2cfba19a..d549568538874 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SortOption.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SortOption.cs @@ -2,13 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices { [TypeConverter(typeof(ExpandableObjectConverter))] public class SortOption { - private string _propertyName; + private string? _propertyName; private SortDirection _sortDirection; public SortOption() @@ -22,7 +23,8 @@ public SortOption(string propertyName, SortDirection direction) } [DefaultValue(null)] - public string PropertyName + [DisallowNull] + public string? PropertyName { get => _propertyName; set => _propertyName = value ?? throw new ArgumentNullException(nameof(value)); From 4ff89aa70b102980034030aa32511d42c2d13c59 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 24 Feb 2021 13:54:46 +0100 Subject: [PATCH 2/3] apply PR feedback --- .../ref/System.DirectoryServices.cs | 16 ++++++++-------- .../ActiveDirectorySchemaClass.cs | 2 +- .../ActiveDirectory/ApplicationPartition.cs | 2 +- .../ActiveDirectory/ConfigSet.cs | 6 +++--- .../ActiveDirectory/DirectoryContext.cs | 4 ++-- .../ReadOnlySiteLinkCollection.cs | 1 + .../System/DirectoryServices/DirectoryEntry.cs | 4 ++-- .../DirectoryServices/PropertyCollection.cs | 4 ++-- .../ResultPropertyValueCollection.cs | 6 +++--- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs index dee8ad0a83a19..aa55816510d6f 100644 --- a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs +++ b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs @@ -177,9 +177,9 @@ public void CommitChanges() { } public void DeleteTree() { } protected override void Dispose(bool disposing) { } public static bool Exists(string path) { throw null; } - public object? Invoke(string methodName, params object?[] args) { throw null; } + public object? Invoke(string methodName, params object?[]? args) { throw null; } public object? InvokeGet(string propertyName) { throw null; } - public void InvokeSet(string propertyName, params object?[] args) { } + public void InvokeSet(string propertyName, params object?[]? args) { } public void MoveTo(System.DirectoryServices.DirectoryEntry newParent) { } public void MoveTo(System.DirectoryServices.DirectoryEntry newParent, string? newName) { } public void RefreshCache() { } @@ -469,7 +469,7 @@ public void CopyTo(System.DirectoryServices.ResultPropertyValueCollection[] arra public partial class ResultPropertyValueCollection : System.Collections.ReadOnlyCollectionBase { internal ResultPropertyValueCollection() { } - public object? this[int index] { get { throw null; } } + public object this[int index] { get { throw null; } } public bool Contains(object? value) { throw null; } public void CopyTo(object?[] values, int index) { } public int IndexOf(object? value) { throw null; } @@ -1062,7 +1062,7 @@ public partial class ConfigurationSet internal ConfigurationSet() { } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection AdamInstances { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ApplicationPartitionCollection ApplicationPartitions { get { throw null; } } - public string? Name { get { throw null; } } + public string Name { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AdamInstance NamingRoleOwner { get { throw null; } } public System.DirectoryServices.ActiveDirectory.ActiveDirectorySchema Schema { get { throw null; } } public System.DirectoryServices.ActiveDirectory.AdamInstance SchemaRoleOwner { get { throw null; } } @@ -1073,20 +1073,20 @@ protected virtual void Dispose(bool disposing) { } public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance(string partitionName) { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstance FindAdamInstance(string? partitionName, string siteName) { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances() { throw null; } - public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string partitionName) { throw null; } + public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string? partitionName) { throw null; } public System.DirectoryServices.ActiveDirectory.AdamInstanceCollection FindAllAdamInstances(string? partitionName, string? siteName) { throw null; } public static System.DirectoryServices.ActiveDirectory.ConfigurationSet GetConfigurationSet(System.DirectoryServices.ActiveDirectory.DirectoryContext context) { throw null; } public System.DirectoryServices.DirectoryEntry GetDirectoryEntry() { throw null; } public System.DirectoryServices.ActiveDirectory.ReplicationSecurityLevel GetSecurityLevel() { throw null; } public void SetSecurityLevel(System.DirectoryServices.ActiveDirectory.ReplicationSecurityLevel securityLevel) { } - public override string? ToString() { throw null; } + public override string ToString() { throw null; } } public partial class DirectoryContext { public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType) { } public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string name) { } - public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string username, string password) { } - public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string name, string username, string password) { } + public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string? username, string? password) { } + public DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType contextType, string name, string? username, string? password) { } public System.DirectoryServices.ActiveDirectory.DirectoryContextType ContextType { get { throw null; } } public string? Name { get { throw null; } } public string? UserName { get { throw null; } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs index a33c8f9a66b24..ab0cf6c41c59a 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClass.cs @@ -1002,7 +1002,7 @@ public Guid SchemaGuid if (_schemaGuidBinaryForm == null) { // get the property from the server - _schemaGuidBinaryForm = (byte[]?)GetValueFromCache(PropertyManager.SchemaIDGuid, true); + _schemaGuidBinaryForm = (byte[])GetValueFromCache(PropertyManager.SchemaIDGuid, true)!; } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs index a58745d718986..93dc06daf4495 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ApplicationPartition.cs @@ -89,7 +89,7 @@ protected override void Dispose(bool disposing) if (_domainDNSEntry != null) { _domainDNSEntry.Dispose(); - _domainDNSEntry = null!; + _domainDNSEntry = null; } _disposed = true; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs index aac9d85611bf7..6a812be37ee45 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ConfigSet.cs @@ -204,7 +204,7 @@ public AdamInstanceCollection FindAllAdamInstances(string partitionName) return FindAdamInstances(_context, partitionName, null); } - public AdamInstanceCollection FindAllAdamInstances(string? partitionName, string? siteName) + public AdamInstanceCollection FindAllAdamInstances(string? partitionName, string siteName) { CheckIfDisposed(); @@ -260,13 +260,13 @@ public void SetSecurityLevel(ReplicationSecurityLevel securityLevel) _cachedSecurityLevel = (ReplicationSecurityLevel)(-1); } - public override string? ToString() => Name; + public override string ToString() => Name; #endregion public methods #region public properties - public string? Name + public string Name { get { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs index 3fd08dcde513a..0ed4b80c55f04 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryContext.cs @@ -133,7 +133,7 @@ public DirectoryContext(DirectoryContextType contextType, string name) InitializeDirectoryContext(contextType, name, null, null); } - public DirectoryContext(DirectoryContextType contextType, string username, string password) + public DirectoryContext(DirectoryContextType contextType, string? username, string? password) { // // this constructor can only be called for DirectoryContextType.Forest or DirectoryContextType.Domain @@ -147,7 +147,7 @@ public DirectoryContext(DirectoryContextType contextType, string username, strin InitializeDirectoryContext(contextType, null, username, password); } - public DirectoryContext(DirectoryContextType contextType, string name, string username, string password) + public DirectoryContext(DirectoryContextType contextType, string name, string? username, string? password) { if (contextType < DirectoryContextType.Domain || contextType > DirectoryContextType.ApplicationPartition) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs index 89e804443f1a3..45f6294415fd4 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ReadOnlySiteLinkCollection.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. + using System.Collections; namespace System.DirectoryServices.ActiveDirectory diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs index 0534418145746..3b3a6d20515db 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs @@ -790,7 +790,7 @@ internal void FillCache(string propertyName) /// /// Calls a method on the native Active Directory. /// - public object? Invoke(string methodName, params object?[] args) + public object? Invoke(string methodName, params object?[]? args) { object target = this.NativeObject; Type type = target.GetType(); @@ -861,7 +861,7 @@ internal void FillCache(string propertyName) /// /// Sets a property on the native Active Directory object. /// - public void InvokeSet(string propertyName, params object?[] args) + public void InvokeSet(string propertyName, params object?[]? args) { object target = this.NativeObject; Type type = target.GetType(); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs index 5c8b1d57e5716..4ba6161ce1cd1 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/PropertyCollection.cs @@ -199,7 +199,7 @@ protected virtual void Dispose(bool disposing) } } - public object? Current => Entry.Value; + public object Current => Entry.Value!; public DictionaryEntry Entry { @@ -214,7 +214,7 @@ public DictionaryEntry Entry public object Key => Entry.Key; - public object? Value => Entry.Value; + public object Value => Entry.Value!; public bool MoveNext() { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs index 2dc1281b17c21..508802c99963e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ResultPropertyValueCollection.cs @@ -10,16 +10,16 @@ namespace System.DirectoryServices /// public class ResultPropertyValueCollection : ReadOnlyCollectionBase { - internal ResultPropertyValueCollection(object?[] values) + internal ResultPropertyValueCollection(object[] values) { InnerList.AddRange(values ?? Array.Empty()); } - public object? this[int index] + public object this[int index] { get { - object? returnValue = InnerList[index]; + object returnValue = InnerList[index]!; if (returnValue is Exception) throw (Exception)returnValue; else From b155f55308ed8562abc0689b23a95cd77e2a7e8b Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 4 Mar 2021 10:13:45 +0100 Subject: [PATCH 3/3] Fix nullability of classes deriving from CollectionBase --- .../ref/System.DirectoryServices.cs | 36 +++++++++---------- .../ActiveDirectorySchemaClassCollection.cs | 16 ++++++--- ...ActiveDirectorySchemaPropertyCollection.cs | 17 ++++++--- .../ActiveDirectorySiteCollection.cs | 18 ++++++---- .../ActiveDirectorySiteLinkCollection.cs | 16 ++++++--- .../ActiveDirectorySubnetCollection.cs | 16 ++++++--- .../DirectoryServerCollection.cs | 20 +++++++---- 7 files changed, 88 insertions(+), 51 deletions(-) diff --git a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs index aa55816510d6f..3e31f111d0eec 100644 --- a/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs +++ b/src/libraries/System.DirectoryServices/ref/System.DirectoryServices.cs @@ -707,9 +707,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchem public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaClass schemaClass) { } } @@ -754,9 +754,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchem public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySchemaProperty schemaProperty) { } } @@ -811,9 +811,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite[ public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySite site) { } } @@ -868,9 +868,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteL public int IndexOf(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { throw null; } public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink link) { } } @@ -918,9 +918,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.ActiveDirectorySubne public void Insert(int index, System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet subnet) { } protected override void OnClear() { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.ActiveDirectorySubnet subnet) { } } @@ -1138,9 +1138,9 @@ public void CopyTo(System.DirectoryServices.ActiveDirectory.DirectoryServer[] ar public void Insert(int index, System.DirectoryServices.ActiveDirectory.DirectoryServer server) { } protected override void OnClear() { } protected override void OnClearComplete() { } - protected override void OnInsertComplete(int index, object? value) { } - protected override void OnRemoveComplete(int index, object? value) { } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) { } + protected override void OnInsertComplete(int index, object value) { } + protected override void OnRemoveComplete(int index, object value) { } + protected override void OnSetComplete(int index, object oldValue, object newValue) { } protected override void OnValidate(object value) { } public void Remove(System.DirectoryServices.ActiveDirectory.DirectoryServer server) { } } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs index bf72e00ac2efe..bef900f6071c2 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaClassCollection.cs @@ -286,7 +286,9 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (_isBound) { @@ -297,7 +299,7 @@ protected override void OnInsertComplete(int index, object? value) try { - _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaClass)value!).Name); + _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaClass)value).Name); } catch (COMException e) { @@ -306,7 +308,9 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { if (_isBound) { @@ -319,7 +323,7 @@ protected override void OnRemoveComplete(int index, object? value) // these values would not exist in the classEntry // and therefore cannot be removed // we need to throw an exception here - string valueName = ((ActiveDirectorySchemaClass)value!).Name; + string valueName = ((ActiveDirectorySchemaClass)value).Name; try { @@ -339,7 +343,9 @@ protected override void OnRemoveComplete(int index, object? value) } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { if (_isBound) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs index c14b53e12eb5f..a07d77d39a72a 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySchemaPropertyCollection.cs @@ -299,7 +299,9 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (_isBound) { @@ -310,7 +312,7 @@ protected override void OnInsertComplete(int index, object? value) try { - _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaProperty)value!).Name); + _classEntry.Properties[_propertyName].Add(((ActiveDirectorySchemaProperty)value).Name); } catch (COMException e) { @@ -319,7 +321,9 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { if (_isBound) { @@ -332,7 +336,7 @@ protected override void OnRemoveComplete(int index, object? value) // these values would not exist in the classEntry // and therefore cannot be removed // we need to throw an exception here - string valueName = ((ActiveDirectorySchemaProperty)value!).Name; + string valueName = ((ActiveDirectorySchemaProperty)value).Name; try { @@ -351,7 +355,10 @@ protected override void OnRemoveComplete(int index, object? value) } } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) + +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { if (_isBound) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs index e8723e6a3f15a..9c428eaae46ba 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteCollection.cs @@ -181,11 +181,13 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (initialized) { - ActiveDirectorySite site = (ActiveDirectorySite)value!; + ActiveDirectorySite site = (ActiveDirectorySite)value; string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; try { @@ -198,9 +200,11 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { - ActiveDirectorySite site = (ActiveDirectorySite)value!; + ActiveDirectorySite site = (ActiveDirectorySite)value; string dn = (string)PropertyManager.GetPropertyValue(site.context, site.cachedEntry, PropertyManager.DistinguishedName)!; try { @@ -212,9 +216,11 @@ protected override void OnRemoveComplete(int index, object? value) } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { - ActiveDirectorySite newsite = (ActiveDirectorySite)newValue!; + ActiveDirectorySite newsite = (ActiveDirectorySite)newValue; string newdn = (string)PropertyManager.GetPropertyValue(newsite.context, newsite.cachedEntry, PropertyManager.DistinguishedName)!; try { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs index e280aa2f738d3..46e914c5efc6e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySiteLinkCollection.cs @@ -175,11 +175,13 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (initialized) { - ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value!; + ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value; string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; try { @@ -192,9 +194,11 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { - ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value!; + ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value; string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName)!; try { @@ -206,7 +210,9 @@ protected override void OnRemoveComplete(int index, object? value) } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { ActiveDirectorySiteLink newLink = (ActiveDirectorySiteLink)newValue!; string newdn = (string)PropertyManager.GetPropertyValue(newLink.context, newLink.cachedEntry, PropertyManager.DistinguishedName)!; diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs index a3432b67fc029..de4b4a5970040 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/ActiveDirectorySubnetCollection.cs @@ -200,11 +200,13 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (initialized) { - ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value!; + ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; try @@ -227,9 +229,11 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { - ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value!; + ActiveDirectorySubnet subnet = (ActiveDirectorySubnet)value; string dn = (string)PropertyManager.GetPropertyValue(subnet.context, subnet.cachedEntry, PropertyManager.DistinguishedName)!; try @@ -251,7 +255,9 @@ protected override void OnRemoveComplete(int index, object? value) } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { OnRemoveComplete(index, oldValue); OnInsertComplete(index, newValue); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs index 2cac72385a237..03c6df1f68ff0 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryServerCollection.cs @@ -268,7 +268,9 @@ protected override void OnClearComplete() } } - protected override void OnInsertComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnInsertComplete(int index, object value) +#pragma warning restore CS8765 { if (_isForNC) { @@ -276,7 +278,7 @@ protected override void OnInsertComplete(int index, object? value) { try { - DirectoryServer server = (DirectoryServer)value!; + DirectoryServer server = (DirectoryServer)value; string ntdsaName = (server is DomainController) ? ((DomainController)server).NtdsaObjectName : ((AdamInstance)server).NtdsaObjectName; _crossRefEntry.Properties[PropertyManager.MsDSNCReplicaLocations].Add(ntdsaName); } @@ -288,7 +290,7 @@ protected override void OnInsertComplete(int index, object? value) } else if (initialized) { - DirectoryServer server = (DirectoryServer)value!; + DirectoryServer server = (DirectoryServer)value; string name = server.Name; string serverName = (server is DomainController) ? ((DomainController)server).ServerObjectName : ((AdamInstance)server).ServerObjectName; @@ -313,7 +315,9 @@ protected override void OnInsertComplete(int index, object? value) } } - protected override void OnRemoveComplete(int index, object? value) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnRemoveComplete(int index, object value) +#pragma warning restore CS8765 { if (_isForNC) { @@ -321,7 +325,7 @@ protected override void OnRemoveComplete(int index, object? value) { if (_crossRefEntry != null) { - string ntdsaName = (value is DomainController) ? ((DomainController)value).NtdsaObjectName : ((AdamInstance)value!).NtdsaObjectName; + string ntdsaName = (value is DomainController) ? ((DomainController)value).NtdsaObjectName : ((AdamInstance)value).NtdsaObjectName; _crossRefEntry.Properties[PropertyManager.MsDSNCReplicaLocations].Remove(ntdsaName); } } @@ -332,7 +336,7 @@ protected override void OnRemoveComplete(int index, object? value) } else { - DirectoryServer server = (DirectoryServer)value!; + DirectoryServer server = (DirectoryServer)value; string name = server.Name; string serverName = (server is DomainController) ? ((DomainController)server).ServerObjectName : ((AdamInstance)server).ServerObjectName; @@ -357,7 +361,9 @@ protected override void OnRemoveComplete(int index, object? value) } } - protected override void OnSetComplete(int index, object? oldValue, object? newValue) +#pragma warning disable CS8765 // Nullability doesn't match overriden member + protected override void OnSetComplete(int index, object oldValue, object newValue) +#pragma warning restore CS8765 { OnRemoveComplete(index, oldValue); OnInsertComplete(index, newValue);