diff --git a/common/ASC.Common/Data/DataExtensions.cs b/common/ASC.Common/Data/DataExtensions.cs index 28d098ed4a..ada8bbd088 100644 --- a/common/ASC.Common/Data/DataExtensions.cs +++ b/common/ASC.Common/Data/DataExtensions.cs @@ -92,8 +92,7 @@ namespace ASC.Common.Data return DBNull.Value; } - var @enum = value as Enum; - if (@enum != null) + if (value is Enum @enum) { return @enum.ToString("d"); } diff --git a/common/ASC.Common/Data/DbManager.cs b/common/ASC.Common/Data/DbManager.cs index 73ce3396ed..e8c8fbac58 100644 --- a/common/ASC.Common/Data/DbManager.cs +++ b/common/ASC.Common/Data/DbManager.cs @@ -128,8 +128,7 @@ namespace ASC.Common.Data { if (HttpContext.Current != null) { - var dbManager = DisposableHttpContext.Current[databaseId] as DbManager; - if (dbManager == null || dbManager.disposed) + if (!(DisposableHttpContext.Current[databaseId] is DbManager dbManager) || dbManager.disposed) { var localDbManager = new DbManager(databaseId); var dbManagerAdapter = new DbManagerProxy(localDbManager); diff --git a/common/ASC.Common/DependencyInjection/DictionaryElementCollection.cs b/common/ASC.Common/DependencyInjection/DictionaryElementCollection.cs index 79f25e7ee8..4a5147729c 100644 --- a/common/ASC.Common/DependencyInjection/DictionaryElementCollection.cs +++ b/common/ASC.Common/DependencyInjection/DictionaryElementCollection.cs @@ -46,8 +46,7 @@ namespace ASC.Common.DependencyInjection public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { var instantiableType = GetInstantiableType(destinationType); - var elementCollection = value as DictionaryElementCollection; - if (elementCollection == null || !(instantiableType != null)) + if (!(value is DictionaryElementCollection elementCollection) || !(instantiableType != null)) return base.ConvertTo(context, culture, value, destinationType); var dictionary = (IDictionary)Activator.CreateInstance(instantiableType); var genericArguments = instantiableType.GetGenericArguments(); diff --git a/common/ASC.Common/DependencyInjection/TypeManipulation.cs b/common/ASC.Common/DependencyInjection/TypeManipulation.cs index c2dabc7248..2e0e60bbf1 100644 --- a/common/ASC.Common/DependencyInjection/TypeManipulation.cs +++ b/common/ASC.Common/DependencyInjection/TypeManipulation.cs @@ -77,8 +77,7 @@ namespace ASC.Common.DependencyInjection private static TypeConverter GetTypeConverterFromName(string converterTypeName) { - var typeConverter = Activator.CreateInstance(Type.GetType(converterTypeName, true)) as TypeConverter; - if (typeConverter == null) + if (!(Activator.CreateInstance(Type.GetType(converterTypeName, true)) is TypeConverter typeConverter)) throw new ConfigurationErrorsException(""); return typeConverter; } diff --git a/common/ASC.Common/Security/Authentication/Account.cs b/common/ASC.Common/Security/Authentication/Account.cs index 96cfab0af5..a81ecadba5 100644 --- a/common/ASC.Common/Security/Authentication/Account.cs +++ b/common/ASC.Common/Security/Authentication/Account.cs @@ -65,8 +65,7 @@ namespace ASC.Common.Security.Authentication public override bool Equals(object obj) { - var a = obj as IAccount; - return a != null && ID.Equals(a.ID); + return obj is IAccount a && ID.Equals(a.ID); } public override int GetHashCode() diff --git a/common/ASC.Common/Security/Authorizing/Domain/Action.cs b/common/ASC.Common/Security/Authorizing/Domain/Action.cs index d4e294a83f..6ad1db4f41 100644 --- a/common/ASC.Common/Security/Authorizing/Domain/Action.cs +++ b/common/ASC.Common/Security/Authorizing/Domain/Action.cs @@ -62,8 +62,7 @@ namespace ASC.Common.Security.Authorizing public override bool Equals(object obj) { - var a = obj as Action; - return a != null && a.ID == ID; + return obj is Action a && a.ID == ID; } public override string ToString() diff --git a/common/ASC.Common/Security/Authorizing/Domain/Role.cs b/common/ASC.Common/Security/Authorizing/Domain/Role.cs index 123fa4940f..5cc7590125 100644 --- a/common/ASC.Common/Security/Authorizing/Domain/Role.cs +++ b/common/ASC.Common/Security/Authorizing/Domain/Role.cs @@ -70,8 +70,7 @@ namespace ASC.Common.Security.Authorizing public override bool Equals(object obj) { - var r = obj as Role; - return r != null && r.ID == ID; + return obj is Role r && r.ID == ID; } public override string ToString() diff --git a/common/ASC.Common/Security/SecurityObjectId.cs b/common/ASC.Common/Security/SecurityObjectId.cs index 92287a91d0..d81152cdc7 100644 --- a/common/ASC.Common/Security/SecurityObjectId.cs +++ b/common/ASC.Common/Security/SecurityObjectId.cs @@ -51,8 +51,7 @@ namespace ASC.Common.Security public override bool Equals(object obj) { - var other = obj as SecurityObjectId; - return other != null && + return obj is SecurityObjectId other && Equals(AzObjectIdHelper.GetFullObjectId(other), AzObjectIdHelper.GetFullObjectId(this)); } } diff --git a/common/ASC.Common/Threading/Workers/WorkItem.cs b/common/ASC.Common/Threading/Workers/WorkItem.cs index 89c29e1898..65f3c7fe76 100644 --- a/common/ASC.Common/Threading/Workers/WorkItem.cs +++ b/common/ASC.Common/Threading/Workers/WorkItem.cs @@ -64,8 +64,7 @@ namespace ASC.Common.Threading.Workers { if (disposing) { - var disposable = Item as IDisposable; - if (disposable != null) + if (Item is IDisposable disposable) { disposable.Dispose(); } diff --git a/common/ASC.Core.Common/Billing/Tariff.cs b/common/ASC.Core.Common/Billing/Tariff.cs index 6ccf53a6da..4e998b7936 100644 --- a/common/ASC.Core.Common/Billing/Tariff.cs +++ b/common/ASC.Core.Common/Billing/Tariff.cs @@ -69,8 +69,7 @@ namespace ASC.Core.Billing public override bool Equals(object obj) { - var t = obj as Tariff; - return t != null && t.QuotaId == QuotaId; + return obj is Tariff t && t.QuotaId == QuotaId; } } } \ No newline at end of file diff --git a/common/ASC.Core.Common/Billing/TariffService.cs b/common/ASC.Core.Common/Billing/TariffService.cs index a5df0bdd52..ed597ad217 100644 --- a/common/ASC.Core.Common/Billing/TariffService.cs +++ b/common/ASC.Core.Common/Billing/TariffService.cs @@ -256,8 +256,7 @@ namespace ASC.Core.Billing ? GetBillingUrlCacheKey(tenant.Value) : string.Format("notenant{0}", !string.IsNullOrEmpty(affiliateId) ? "_" + affiliateId : ""); key += quota.Visible ? "" : "0"; - var urls = cache.Get>>(key) as IDictionary>; - if (urls == null) + if (!(cache.Get>>(key) is IDictionary> urls)) { urls = new Dictionary>(); if (billingConfigured) diff --git a/common/ASC.Core.Common/Caching/CachedUserService.cs b/common/ASC.Core.Common/Caching/CachedUserService.cs index 3554bfa02b..28ce9f8bc0 100644 --- a/common/ASC.Core.Common/Caching/CachedUserService.cs +++ b/common/ASC.Core.Common/Caching/CachedUserService.cs @@ -221,8 +221,7 @@ namespace ASC.Core.Caching GetChangesFromDb(); var key = GetRefCacheKey(tenant); - var refs = cache.Get(key) as IDictionary; - if (refs == null) + if (!(cache.Get(key) is IDictionary refs)) { refs = service.GetUserGroupRefs(tenant, default); cache.Insert(key, new UserGroupRefStore(refs), CacheExpiration); diff --git a/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs b/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs index 88917242c0..720efcf3c6 100644 --- a/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs +++ b/common/ASC.Core.Common/Context/Impl/AuthorizationManager.cs @@ -118,8 +118,7 @@ namespace ASC.Core private IEnumerable FilterAces(IEnumerable aces, Guid subjectId, Guid actionId, ISecurityObjectId objectId) { var objId = AzObjectIdHelper.GetFullObjectId(objectId); - var store = aces as AzRecordStore; - return store != null ? + return aces is AzRecordStore store ? store.Get(objId).Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty)) : aces.Where(a => (a.SubjectId == subjectId || subjectId == Guid.Empty) && (a.ActionId == actionId || actionId == Guid.Empty) && a.ObjectId == objId); } diff --git a/common/ASC.Core.Common/Context/Impl/TenantManager.cs b/common/ASC.Core.Common/Context/Impl/TenantManager.cs index 4d1d27d514..409c249f66 100644 --- a/common/ASC.Core.Common/Context/Impl/TenantManager.cs +++ b/common/ASC.Core.Common/Context/Impl/TenantManager.cs @@ -127,8 +127,7 @@ namespace ASC.Core { var newTenant = tenantService.SaveTenant(tenant); - var oldTenant = CallContext.GetData(CURRENT_TENANT) as Tenant; - if (oldTenant != null) SetCurrentTenant(newTenant); + if (CallContext.GetData(CURRENT_TENANT) is Tenant oldTenant) SetCurrentTenant(newTenant); return newTenant; } diff --git a/common/ASC.Core.Common/Context/Impl/UserManager.cs b/common/ASC.Core.Common/Context/Impl/UserManager.cs index bfbb6b94c5..55a67c392e 100644 --- a/common/ASC.Core.Common/Context/Impl/UserManager.cs +++ b/common/ASC.Core.Common/Context/Impl/UserManager.cs @@ -280,8 +280,7 @@ namespace ASC.Core var refs = GetRefsInternal(tenant.TenantId); IEnumerable userRefs = null; - var store = refs as UserGroupRefStore; - if (store != null) + if (refs is UserGroupRefStore store) { userRefs = store.GetRefsByUser(userID); } @@ -313,8 +312,7 @@ namespace ASC.Core var refs = GetRefsInternal(tenantId); - var store = refs as UserGroupRefStore; - if (store != null) + if (refs is UserGroupRefStore store) { var userRefs = store.GetRefsByUser(userID); diff --git a/common/ASC.Core.Common/Context/WorkContext.cs b/common/ASC.Core.Common/Context/WorkContext.cs index 07291c2ef1..df455b7e4c 100644 --- a/common/ASC.Core.Common/Context/WorkContext.cs +++ b/common/ASC.Core.Common/Context/WorkContext.cs @@ -144,8 +144,7 @@ namespace ASC.Core private static void NotifyEngine_AfterTransferRequest(NotifyEngine sender, NotifyRequest request) { - var tenant = (request.Properties.Contains("Tenant") ? request.Properties["Tenant"] : null) as Tenant; - if (tenant != null) + if ((request.Properties.Contains("Tenant") ? request.Properties["Tenant"] : null) is Tenant tenant) { CoreContext.TenantManager.SetCurrentTenant(tenant); } diff --git a/common/ASC.Core.Common/Core/AzRecord.cs b/common/ASC.Core.Common/Core/AzRecord.cs index 84fa2f933b..c50b53657d 100644 --- a/common/ASC.Core.Common/Core/AzRecord.cs +++ b/common/ASC.Core.Common/Core/AzRecord.cs @@ -106,8 +106,7 @@ namespace ASC.Core public override bool Equals(object obj) { - var r = obj as AzRecord; - return r != null && + return obj is AzRecord r && r.Tenant == Tenant && r.SubjectId == SubjectId && r.ActionId == ActionId && diff --git a/common/ASC.Core.Common/Core/DBResourceManager.cs b/common/ASC.Core.Common/Core/DBResourceManager.cs index d9bfccdc39..3b0176dfc3 100644 --- a/common/ASC.Core.Common/Core/DBResourceManager.cs +++ b/common/ASC.Core.Common/Core/DBResourceManager.cs @@ -234,8 +234,7 @@ namespace TMResourceData private Dictionary GetResources() { var key = string.Format("{0}/{1}", filename, culture); - var dic = cache.Get(key) as Dictionary; - if (dic == null) + if (!(cache.Get(key) is Dictionary dic)) { lock (locker) { diff --git a/common/ASC.Core.Common/Core/Group.cs b/common/ASC.Core.Common/Core/Group.cs index d028ac8a0b..e8feec8ab0 100644 --- a/common/ASC.Core.Common/Core/Group.cs +++ b/common/ASC.Core.Common/Core/Group.cs @@ -90,8 +90,7 @@ namespace ASC.Core public override bool Equals(object obj) { - var g = obj as Group; - return g != null && g.Id == Id; + return obj is Group g && g.Id == Id; } } } diff --git a/common/ASC.Core.Common/Core/GroupInfo.cs b/common/ASC.Core.Common/Core/GroupInfo.cs index 93e640057a..514d020af8 100644 --- a/common/ASC.Core.Common/Core/GroupInfo.cs +++ b/common/ASC.Core.Common/Core/GroupInfo.cs @@ -65,8 +65,7 @@ namespace ASC.Core.Users public override bool Equals(object obj) { - var g = obj as GroupInfo; - if (g == null) return false; + if (!(obj is GroupInfo g)) return false; if (ID == Guid.Empty && g.ID == Guid.Empty) return ReferenceEquals(this, g); return g.ID == ID; } diff --git a/common/ASC.Core.Common/Core/Partner.cs b/common/ASC.Core.Common/Core/Partner.cs index 7b681d88af..b8eb0b3632 100644 --- a/common/ASC.Core.Common/Core/Partner.cs +++ b/common/ASC.Core.Common/Core/Partner.cs @@ -169,8 +169,7 @@ namespace ASC.Core public override bool Equals(object obj) { - var p = obj as Partner; - return p != null && p.Id == Id; + return obj is Partner p && p.Id == Id; } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Core/UserGroupRef.cs b/common/ASC.Core.Common/Core/UserGroupRef.cs index bbec0474bb..6598adbb87 100644 --- a/common/ASC.Core.Common/Core/UserGroupRef.cs +++ b/common/ASC.Core.Common/Core/UserGroupRef.cs @@ -74,8 +74,7 @@ namespace ASC.Core public override bool Equals(object obj) { - var r = obj as UserGroupRef; - return r != null && r.Tenant == Tenant && r.UserId == UserId && r.GroupId == GroupId && r.RefType == RefType; + return obj is UserGroupRef r && r.Tenant == Tenant && r.UserId == UserId && r.GroupId == GroupId && r.RefType == RefType; } public static implicit operator UserGroupRef(UserGroupRefCacheItem cache) diff --git a/common/ASC.Core.Common/Core/UserInfo.cs b/common/ASC.Core.Common/Core/UserInfo.cs index c6823871b3..de518ab8e6 100644 --- a/common/ASC.Core.Common/Core/UserInfo.cs +++ b/common/ASC.Core.Common/Core/UserInfo.cs @@ -116,8 +116,7 @@ namespace ASC.Core.Users public override bool Equals(object obj) { - var ui = obj as UserInfo; - return ui != null && ID.Equals(ui.ID); + return obj is UserInfo ui && ID.Equals(ui.ID); } public CultureInfo GetCulture() diff --git a/common/ASC.Core.Common/Notify/Engine/InterceptorStorage.cs b/common/ASC.Core.Common/Notify/Engine/InterceptorStorage.cs index e4971a6642..51e704a223 100644 --- a/common/ASC.Core.Common/Notify/Engine/InterceptorStorage.cs +++ b/common/ASC.Core.Common/Notify/Engine/InterceptorStorage.cs @@ -41,8 +41,7 @@ namespace ASC.Notify.Engine { get { - var storage = CallContext.GetData(CallContext_Prefix) as Dictionary; - if (storage == null) + if (!(CallContext.GetData(CallContext_Prefix) is Dictionary storage)) { storage = new Dictionary(10); CallContext.SetData(CallContext_Prefix, storage); diff --git a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs index 707f1cf014..9841ee8892 100644 --- a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs +++ b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs @@ -401,8 +401,7 @@ namespace ASC.Notify.Engine private SendResponse SendDirectNotify(int tenantId, NotifyRequest request, ISenderChannel channel) { - var recipient = request.Recipient as IDirectRecipient; - if (recipient == null) throw new ArgumentException("request.Recipient not IDirectRecipient", "request"); + if (!(request.Recipient is IDirectRecipient recipient)) throw new ArgumentException("request.Recipient not IDirectRecipient", "request"); request.CurrentSender = channel.SenderName; @@ -488,8 +487,7 @@ namespace ASC.Notify.Engine { if (!stylers.ContainsKey(message.Pattern.Styler)) { - var styler = Activator.CreateInstance(Type.GetType(message.Pattern.Styler, true)) as IPatternStyler; - if (styler != null) + if (Activator.CreateInstance(Type.GetType(message.Pattern.Styler, true)) is IPatternStyler styler) { stylers.Add(message.Pattern.Styler, styler); } diff --git a/common/ASC.Core.Common/Notify/Model/NotifyAction.cs b/common/ASC.Core.Common/Notify/Model/NotifyAction.cs index 6f3e4cb306..31b247560f 100644 --- a/common/ASC.Core.Common/Notify/Model/NotifyAction.cs +++ b/common/ASC.Core.Common/Notify/Model/NotifyAction.cs @@ -59,8 +59,7 @@ namespace ASC.Notify.Model public override bool Equals(object obj) { - var a = obj as INotifyAction; - return a != null && a.ID == ID; + return obj is INotifyAction a && a.ID == ID; } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Notify/Patterns/NVelocityPatternFormatter.cs b/common/ASC.Core.Common/Notify/Patterns/NVelocityPatternFormatter.cs index b36caa7283..4603abb7d7 100644 --- a/common/ASC.Core.Common/Notify/Patterns/NVelocityPatternFormatter.cs +++ b/common/ASC.Core.Common/Notify/Patterns/NVelocityPatternFormatter.cs @@ -71,8 +71,7 @@ namespace ASC.Notify.Patterns private static void EventCartridgeReferenceInsertion(object sender, ReferenceInsertionEventArgs e) { - var originalString = e.OriginalValue as string; - if (originalString == null) return; + if (!(e.OriginalValue is string originalString)) return; var lines = originalString.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) return; e.NewValue = string.Empty; diff --git a/common/ASC.Core.Common/Notify/Patterns/Pattern.cs b/common/ASC.Core.Common/Notify/Patterns/Pattern.cs index 788f4a7ad0..3c2605273c 100644 --- a/common/ASC.Core.Common/Notify/Patterns/Pattern.cs +++ b/common/ASC.Core.Common/Notify/Patterns/Pattern.cs @@ -60,8 +60,7 @@ namespace ASC.Notify.Patterns public override bool Equals(object obj) { - var p = obj as IPattern; - return p != null && p.ID == ID; + return obj is IPattern p && p.ID == ID; } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Notify/Patterns/XmlPatternProvider2.cs b/common/ASC.Core.Common/Notify/Patterns/XmlPatternProvider2.cs index c87f6736b8..b5896d3700 100644 --- a/common/ASC.Core.Common/Notify/Patterns/XmlPatternProvider2.cs +++ b/common/ASC.Core.Common/Notify/Patterns/XmlPatternProvider2.cs @@ -59,8 +59,7 @@ namespace ASC.Notify.Patterns var xdoc = new XmlDocument(); xdoc.LoadXml(xml); - var xformatter = xdoc.SelectSingleNode("/patterns/formatter") as XmlElement; - if (xformatter != null) + if (xdoc.SelectSingleNode("/patterns/formatter") is XmlElement xformatter) { var type = xformatter.GetAttribute("type"); if (!string.IsNullOrEmpty(type)) diff --git a/common/ASC.Core.Common/Notify/Recipients/DirectRecipient.cs b/common/ASC.Core.Common/Notify/Recipients/DirectRecipient.cs index 9fb2dcd7d2..17c8447f0e 100644 --- a/common/ASC.Core.Common/Notify/Recipients/DirectRecipient.cs +++ b/common/ASC.Core.Common/Notify/Recipients/DirectRecipient.cs @@ -77,8 +77,7 @@ namespace ASC.Notify.Recipients public override bool Equals(object obj) { - var recD = obj as IDirectRecipient; - if (recD == null) return false; + if (!(obj is IDirectRecipient recD)) return false; return Equals(recD.ID, ID); } diff --git a/common/ASC.Core.Common/Notify/Recipients/RecipientsGroup.cs b/common/ASC.Core.Common/Notify/Recipients/RecipientsGroup.cs index 9d452ee2e1..bef149944a 100644 --- a/common/ASC.Core.Common/Notify/Recipients/RecipientsGroup.cs +++ b/common/ASC.Core.Common/Notify/Recipients/RecipientsGroup.cs @@ -48,8 +48,7 @@ namespace ASC.Notify.Recipients public override bool Equals(object obj) { - var recGr = obj as IRecipientsGroup; - if (recGr == null) return false; + if (!(obj is IRecipientsGroup recGr)) return false; return Equals(recGr.ID, ID); } diff --git a/common/ASC.Core.Common/Security/Authentication/UserAccount.cs b/common/ASC.Core.Common/Security/Authentication/UserAccount.cs index 3ec64757ea..d45bdf0435 100644 --- a/common/ASC.Core.Common/Security/Authentication/UserAccount.cs +++ b/common/ASC.Core.Common/Security/Authentication/UserAccount.cs @@ -71,8 +71,7 @@ namespace ASC.Core.Security.Authentication public override bool Equals(object obj) { - var a = obj as IUserAccount; - return a != null && ID.Equals(a.ID); + return obj is IUserAccount a && ID.Equals(a.ID); } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Tenants/Tenant.cs b/common/ASC.Core.Common/Tenants/Tenant.cs index 7d57bc4bed..e31bd5b37e 100644 --- a/common/ASC.Core.Common/Tenants/Tenant.cs +++ b/common/ASC.Core.Common/Tenants/Tenant.cs @@ -122,8 +122,7 @@ namespace ASC.Core.Tenants public override bool Equals(object obj) { - var t = obj as Tenant; - return t != null && t.TenantId == TenantId; + return obj is Tenant t && t.TenantId == TenantId; } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Tenants/TenantQuota.cs b/common/ASC.Core.Common/Tenants/TenantQuota.cs index d84459f335..2b5b94018d 100644 --- a/common/ASC.Core.Common/Tenants/TenantQuota.cs +++ b/common/ASC.Core.Common/Tenants/TenantQuota.cs @@ -211,8 +211,7 @@ namespace ASC.Core.Tenants public override bool Equals(object obj) { - var q = obj as TenantQuota; - return q != null && q.Id == Id; + return obj is TenantQuota q && q.Id == Id; } diff --git a/common/ASC.Core.Common/Tenants/TenantVersion.cs b/common/ASC.Core.Common/Tenants/TenantVersion.cs index 5906cfe5a4..29cbe440d6 100644 --- a/common/ASC.Core.Common/Tenants/TenantVersion.cs +++ b/common/ASC.Core.Common/Tenants/TenantVersion.cs @@ -57,8 +57,7 @@ namespace ASC.Core public override bool Equals(object obj) { - var v = obj as TenantVersion; - return v != null && v.Id == Id; + return obj is TenantVersion v && v.Id == Id; } public override string ToString() diff --git a/common/ASC.Core.Common/Tests/Class1.cs b/common/ASC.Core.Common/Tests/Class1.cs index 6f6bf8fd7a..2358826d90 100644 --- a/common/ASC.Core.Common/Tests/Class1.cs +++ b/common/ASC.Core.Common/Tests/Class1.cs @@ -56,8 +56,7 @@ namespace ASC.Common.Tests.Security.Authorizing public override bool Equals(object obj) { - var class1 = obj as Class1; - return class1 != null && Equals(class1.Id, Id); + return obj is Class1 class1 && Equals(class1.Id, Id); } public override int GetHashCode() diff --git a/common/ASC.Core.Common/Tests/DomainStub.cs b/common/ASC.Core.Common/Tests/DomainStub.cs index 85a91a49fe..d5ce8a21b3 100644 --- a/common/ASC.Core.Common/Tests/DomainStub.cs +++ b/common/ASC.Core.Common/Tests/DomainStub.cs @@ -334,8 +334,7 @@ namespace ASC.Common.Tests.Security.Authorizing public override bool Equals(object obj) { - var p = obj as PermissionRecord; - return p != null && Id == p.Id; + return obj is PermissionRecord p && Id == p.Id; } } } diff --git a/common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs b/common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs index 20e0796b31..57287d02a0 100644 --- a/common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs +++ b/common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs @@ -145,9 +145,8 @@ namespace ASC.Data.Storage.DiscStorage //Copy stream //optimaze disk file copy - var fileStream = buffered as FileStream; long fslen; - if (fileStream != null && WorkContext.IsMono) + if (buffered is FileStream fileStream && WorkContext.IsMono) { File.Copy(fileStream.Name, target, true); fslen = fileStream.Length; diff --git a/common/ASC.MessagingSystem/MessageTarget.cs b/common/ASC.MessagingSystem/MessageTarget.cs index d96908f02b..71a3e4b194 100644 --- a/common/ASC.MessagingSystem/MessageTarget.cs +++ b/common/ASC.MessagingSystem/MessageTarget.cs @@ -40,9 +40,8 @@ namespace ASC.MessagingSystem try { var res = new List(); - var ids = value as System.Collections.IEnumerable; - if (ids != null) + if (value is System.Collections.IEnumerable ids) { res.AddRange(from object id in ids select id.ToString()); } diff --git a/web/ASC.Web.Api/Models/QuotaWrapper.cs b/web/ASC.Web.Api/Models/QuotaWrapper.cs index 1067f4bd8a..00b0f6d892 100644 --- a/web/ASC.Web.Api/Models/QuotaWrapper.cs +++ b/web/ASC.Web.Api/Models/QuotaWrapper.cs @@ -107,8 +107,7 @@ namespace ASC.Web.Studio.Core.Quota result.UserStorageSize = CoreContext.Configuration.PersonalMaxSpace; var webItem = WebItemManager.Instance[WebItemManager.DocumentsProductID]; - var spaceUsageManager = webItem.Context.SpaceUsageStatManager as IUserSpaceUsage; - if (spaceUsageManager != null) + if (webItem.Context.SpaceUsageStatManager is IUserSpaceUsage spaceUsageManager) result.UserUsedSize = spaceUsageManager.GetUserSpaceUsage(SecurityContext.CurrentAccount.ID); } diff --git a/web/ASC.Web.Core/NavigationWebItem.cs b/web/ASC.Web.Core/NavigationWebItem.cs index d92500754a..a20f2dbc10 100644 --- a/web/ASC.Web.Core/NavigationWebItem.cs +++ b/web/ASC.Web.Core/NavigationWebItem.cs @@ -58,8 +58,7 @@ namespace ASC.Web.Core public override bool Equals(object obj) { - var m = obj as IWebItem; - return m != null && ID == m.ID; + return obj is IWebItem m && ID == m.ID; } public override int GetHashCode() diff --git a/web/ASC.Web.Core/Tfa/TfaAppUserSettings.cs b/web/ASC.Web.Core/Tfa/TfaAppUserSettings.cs index 4ce2071045..229ddfbe6c 100644 --- a/web/ASC.Web.Core/Tfa/TfaAppUserSettings.cs +++ b/web/ASC.Web.Core/Tfa/TfaAppUserSettings.cs @@ -106,8 +106,7 @@ namespace ASC.Web.Studio.Core.TFA public static void DisableForUser(Guid guid) { - var defaultSettings = new TfaAppUserSettings().GetDefault() as TfaAppUserSettings; - if (defaultSettings != null) + if (new TfaAppUserSettings().GetDefault() is TfaAppUserSettings defaultSettings) { defaultSettings.SaveForUser(guid); } diff --git a/web/ASC.Web.Core/WebItemManager.cs b/web/ASC.Web.Core/WebItemManager.cs index d380c38c3d..564ed2bbc0 100644 --- a/web/ASC.Web.Core/WebItemManager.cs +++ b/web/ASC.Web.Core/WebItemManager.cs @@ -229,8 +229,7 @@ namespace ASC.Web.Core public Guid GetParentItemID(Guid itemID) { - var m = this[itemID] as IModule; - return m != null ? m.ProjectId : Guid.Empty; + return this[itemID] is IModule m ? m.ProjectId : Guid.Empty; } public static int GetSortOrder(IWebItem item) diff --git a/web/ASC.Web.Core/WebItemSecurity.cs b/web/ASC.Web.Core/WebItemSecurity.cs index 9d1d0b8a5c..80febe8c60 100644 --- a/web/ASC.Web.Core/WebItemSecurity.cs +++ b/web/ASC.Web.Core/WebItemSecurity.cs @@ -370,11 +370,9 @@ namespace ASC.Web.Core public ISecurityObjectId InheritFrom(ISecurityObjectId objectId) { - var s = objectId as WebItemSecurityObject; - if (s != null) + if (objectId is WebItemSecurityObject s) { - var parent = WebItemSecurityObject.Create(WebItemManager.Instance.GetParentItemID(s.WebItemId).ToString("N")) as WebItemSecurityObject; - return parent != null && parent.WebItemId != s.WebItemId && parent.WebItemId != Guid.Empty ? parent : null; + return WebItemSecurityObject.Create(WebItemManager.Instance.GetParentItemID(s.WebItemId).ToString("N")) is WebItemSecurityObject parent && parent.WebItemId != s.WebItemId && parent.WebItemId != Guid.Empty ? parent : null; } return null; } diff --git a/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs b/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs index 46ca95f9aa..ec97a76ff9 100644 --- a/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs +++ b/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs @@ -76,9 +76,7 @@ namespace ASC.Web.Core.WhiteLabel { get { - var defaultSettings = GetDefault() as AdditionalWhiteLabelSettings; - - if (defaultSettings == null) return false; + if (!(GetDefault() is AdditionalWhiteLabelSettings defaultSettings)) return false; return StartDocsEnabled == defaultSettings.StartDocsEnabled && HelpCenterEnabled == defaultSettings.HelpCenterEnabled && diff --git a/web/ASC.Web.Core/WhiteLabel/CompanyWhiteLabelSettings.cs b/web/ASC.Web.Core/WhiteLabel/CompanyWhiteLabelSettings.cs index 3251883893..ea92bdfa7a 100644 --- a/web/ASC.Web.Core/WhiteLabel/CompanyWhiteLabelSettings.cs +++ b/web/ASC.Web.Core/WhiteLabel/CompanyWhiteLabelSettings.cs @@ -58,9 +58,7 @@ namespace ASC.Web.Core.WhiteLabel { get { - var defaultSettings = GetDefault() as CompanyWhiteLabelSettings; - - if (defaultSettings == null) return false; + if (!(GetDefault() is CompanyWhiteLabelSettings defaultSettings)) return false; return CompanyName == defaultSettings.CompanyName && Site == defaultSettings.Site && diff --git a/web/ASC.Web.Core/WhiteLabel/MailWhiteLabelSettings.cs b/web/ASC.Web.Core/WhiteLabel/MailWhiteLabelSettings.cs index 69e662c330..966262a07c 100644 --- a/web/ASC.Web.Core/WhiteLabel/MailWhiteLabelSettings.cs +++ b/web/ASC.Web.Core/WhiteLabel/MailWhiteLabelSettings.cs @@ -61,9 +61,7 @@ namespace ASC.Web.Core.WhiteLabel { get { - var defaultSettings = GetDefault() as MailWhiteLabelSettings; - - if (defaultSettings == null) return false; + if (!(GetDefault() is MailWhiteLabelSettings defaultSettings)) return false; return FooterEnabled == defaultSettings.FooterEnabled && FooterSocialEnabled == defaultSettings.FooterSocialEnabled &&