Skip to content
Permalink
Browse files

housekeeping: fix analyzer warnings that have appeared in the fxcop (#…

  • Loading branch information...
glennawatson committed Jun 27, 2019
1 parent 780a4bb commit 3c185b10397fe2409db0ad146b5f05be832e230f
Showing with 1,006 additions and 362 deletions.
  1. +5 −0 src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs
  2. +16 −2 src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs
  3. +11 −1 src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs
  4. +1 −0 src/ReactiveUI.AndroidSupport/ReactiveUI.AndroidSupport.csproj
  5. +17 −8 src/ReactiveUI.Blend/FollowObservableStateBehavior.cs
  6. +5 −1 src/ReactiveUI.Blend/Platforms/net461/ObservableTrigger.cs
  7. +1 −0 src/ReactiveUI.Blend/ReactiveUI.Blend.csproj
  8. +13 −3 src/ReactiveUI.Fody.Helpers/ObservableAsPropertyExtensions.cs
  9. +1 −0 src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj
  10. +1 −1 src/ReactiveUI.Fody.Tests/API/ApiApprovalTests.ReactiveUIFody.net461.approved.txt
  11. +1 −1 src/ReactiveUI.Fody.Tests/API/ApiApprovalTests.ReactiveUIFody.netcoreapp2.0.approved.txt
  12. +1 −0 src/ReactiveUI.Fody.Tests/ReactiveUI.Fody.Tests.csproj
  13. +67 −44 src/ReactiveUI.Fody/CecilExtensions.cs
  14. +10 −0 src/ReactiveUI.Fody/ObservableAsPropertyWeaver.cs
  15. +1 −0 src/ReactiveUI.Fody/ReactiveUI.Fody.csproj
  16. +1 −0 src/ReactiveUI.LeakTests/ReactiveUI.LeakTests.csproj
  17. +1 −0 src/ReactiveUI.Splat.Tests/ReactiveUI.Splat.Tests.csproj
  18. +1 −0 src/ReactiveUI.Testing.Tests/ReactiveUI.Testing.Tests.csproj
  19. +2 −0 src/ReactiveUI.Testing.Tests/TestFixture.cs
  20. +8 −1 src/ReactiveUI.Testing.Tests/TestFixtureBuilder.cs
  21. +25 −0 src/ReactiveUI.Testing/IBuilderExtensions.cs
  22. +10 −0 src/ReactiveUI.Testing/MessageBusExtensions.cs
  23. +1 −0 src/ReactiveUI.Testing/ReactiveUI.Testing.csproj
  24. +20 −0 src/ReactiveUI.Testing/SchedulerExtensions.cs
  25. +26 −26 src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.net461.approved.txt
  26. +26 −26 src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.netcoreapp2.0.approved.txt
  27. +1 −0 src/ReactiveUI.Tests/ReactiveUI.Tests.csproj
  28. +5 −0 src/ReactiveUI.Uno/PlatformRegistrations.cs
  29. +1 −0 src/ReactiveUI.Uno/ReactiveUI.Uno.csproj
  30. +6 −1 src/ReactiveUI.Uno/WinRTAppDataDriver.cs
  31. +1 −1 src/ReactiveUI.Winforms/ActivationForViewFetcher.cs
  32. +5 −0 src/ReactiveUI.Winforms/ContentControlBindingHook.cs
  33. +15 −0 src/ReactiveUI.Winforms/CreatesWinformsCommandBinding.cs
  34. +6 −1 src/ReactiveUI.Winforms/PanelSetMethodBindingConverter.cs
  35. +1 −0 src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj
  36. +5 −0 src/ReactiveUI.Winforms/Registrations.cs
  37. +11 −2 src/ReactiveUI.Winforms/TableContentSetMethodBindingConverter.cs
  38. +5 −0 src/ReactiveUI.Winforms/WinformsCreatesObservableForProperty.cs
  39. +5 −0 src/ReactiveUI.Wpf/DependencyObjectObservableForProperty.cs
  40. +1 −0 src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj
  41. +5 −0 src/ReactiveUI.Wpf/Registrations.cs
  42. +1 −0 src/ReactiveUI.XamForms/ReactiveUI.XamForms.csproj
  43. +5 −0 src/ReactiveUI.XamForms/Registrations.cs
  44. +9 −2 src/ReactiveUI/Activation/CanActivateViewFetcher.cs
  45. +55 −30 src/ReactiveUI/Activation/ViewForMixins.cs
  46. +20 −0 src/ReactiveUI/Bindings/Command/CommandBinderImplementation.cs
  47. +5 −0 src/ReactiveUI/Bindings/Command/CommandBinderImplementationMixins.cs
  48. +5 −0 src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaCommandParameter.cs
  49. +5 −0 src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaEvent.cs
  50. +10 −0 src/ReactiveUI/Bindings/Converter/EqualityTypeConverter.cs
  51. +1 −1 src/ReactiveUI/Bindings/Converter/StringConverter.cs
  52. +45 −0 src/ReactiveUI/Bindings/Property/PropertyBinderImplementation.cs
  53. +13 −3 src/ReactiveUI/Expression/Reflection.cs
  54. +1 −0 src/ReactiveUI/Legacy/ReactiveList.cs
  55. +5 −0 src/ReactiveUI/Mixins/ChangeSetMixin.cs
  56. +11 −2 src/ReactiveUI/Mixins/DependencyResolverMixins.cs
  57. +11 −6 src/ReactiveUI/Mixins/DisposableMixins.cs
  58. +17 −2 src/ReactiveUI/Mixins/ExpressionMixins.cs
  59. +29 −21 src/ReactiveUI/Mixins/ObservedChangedMixin.cs
  60. +18 −9 src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs
  61. +5 −0 src/ReactiveUI/ObservableForProperty/INPCObservableForProperty.cs
  62. +5 −0 src/ReactiveUI/ObservableForProperty/IROObservableForProperty.cs
  63. +5 −0 src/ReactiveUI/ObservableForProperty/POCOObservableForProperty.cs
  64. +5 −0 src/ReactiveUI/Platforms/android/AndroidObservableForWidgets.cs
  65. +5 −0 src/ReactiveUI/Platforms/android/AutoSuspendHelper.cs
  66. +21 −2 src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs
  67. +10 −0 src/ReactiveUI/Platforms/android/FlexibleCommandBinder.cs
  68. +3 −3 src/ReactiveUI/Platforms/android/LayoutViewHost.cs
  69. +5 −0 src/ReactiveUI/Platforms/android/PlatformRegistrations.cs
  70. +3 −1 src/ReactiveUI/Platforms/android/ReactiveListAdapter.cs
  71. +18 −9 src/ReactiveUI/Platforms/android/ViewCommandExtensions.cs
  72. +7 −13 src/ReactiveUI/Platforms/android/ViewMixins.cs
  73. +2 −2 src/ReactiveUI/Platforms/apple-common/Converters/DateTimeNSDateConverter.cs
  74. +5 −0 src/ReactiveUI/Platforms/apple-common/ObservableForPropertyBase.cs
  75. +17 −6 src/ReactiveUI/Platforms/apple-common/TargetActionCommandBinder.cs
  76. +5 −0 src/ReactiveUI/Platforms/mac/PlatformRegistrations.cs
  77. +5 −0 src/ReactiveUI/Platforms/net461/PlatformRegistrations.cs
  78. +5 −0 src/ReactiveUI/Platforms/tizen/PlatformRegistrations.cs
  79. +5 −0 src/ReactiveUI/Platforms/uap/AutoSuspendHelper.cs
  80. +9 −14 src/ReactiveUI/Platforms/uap/DependencyObjectObservableForProperty.cs
  81. +5 −0 src/ReactiveUI/Platforms/uap/PlatformRegistrations.cs
  82. +5 −0 src/ReactiveUI/Platforms/uap/WinRTAppDataDriver.cs
  83. +15 −0 src/ReactiveUI/Platforms/uikit-common/FlexibleCommandBinder.cs
  84. +5 −0 src/ReactiveUI/Platforms/uikit-common/PlatformRegistrations.cs
  85. +15 −0 src/ReactiveUI/Platforms/uikit-common/ReactiveCollectionViewSource.cs
  86. +5 −0 src/ReactiveUI/Platforms/uikit-common/ReactiveCollectionViewSourceExtensions.cs
  87. +33 −11 src/ReactiveUI/Platforms/uikit-common/ReactiveTableViewSource.cs
  88. +5 −0 src/ReactiveUI/Platforms/uikit-common/ReactiveTableViewSourceExtensions.cs
  89. +5 −0 src/ReactiveUI/Platforms/uikit-common/RoutedViewHost.cs
  90. +18 −9 src/ReactiveUI/Platforms/uikit-common/UIControlCommandExtensions.cs
  91. +6 −6 src/ReactiveUI/Platforms/windows-common/AutoDataTemplateBindingHook.cs
  92. +27 −31 src/ReactiveUI/ReactiveCommand/ReactiveCommandMixins.cs
  93. +1 −0 src/ReactiveUI/ReactiveUI.csproj
  94. +5 −0 src/ReactiveUI/Registration/Registrations.cs
  95. +21 −21 src/ReactiveUI/Routing/MessageBus.cs
  96. +29 −14 src/ReactiveUI/Routing/RoutableViewModelMixin.cs
  97. +16 −6 src/ReactiveUI/Routing/RoutingStateMixins.cs
  98. +29 −19 src/ReactiveUI/Suspension/SuspensionHostExtensions.cs
  99. +2 −0 src/analyzers.ruleset
  100. +3 −0 src/analyzers.tests.ruleset
@@ -26,6 +26,11 @@ public static class ControlFetcherMixin
/// <param name="resolveMembers">The resolve members.</param>
public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit)
{
if (fragment == null)
{
throw new ArgumentNullException(nameof(fragment));
}

var members = fragment.GetWireUpMembers(resolveMembers);

foreach (var member in members)
@@ -81,9 +81,23 @@ public override Object InstantiateItem(ViewGroup container, int position)
}

/// <inheritdoc/>
public override void DestroyItem(ViewGroup container, int position, Object @object)
public override void DestroyItem(ViewGroup container, int position, Object item)
{
var view = (View)@object;
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}

if (item == null)
{
throw new ArgumentNullException(nameof(item));
}

if (!(item is View view))
{
throw new ArgumentException("Item must be of type View", nameof(item));
}

container.RemoveView(view);
}

@@ -73,7 +73,17 @@ public virtual int GetItemViewType(int position, TViewModel viewModel)
/// <inheritdoc/>
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
((IViewFor)holder).ViewModel = GetViewModelByPosition(position);
if (holder == null)
{
throw new ArgumentNullException(nameof(holder));
}

if (!(holder is IViewFor viewForHolder))
{
throw new ArgumentException("Holder must be derived from IViewFor", nameof(holder));
}

viewForHolder.ViewModel = GetViewModelByPosition(position);
}

/// <inheritdoc/>
@@ -4,6 +4,7 @@
<TargetFrameworks>MonoAndroid81</TargetFrameworks>
<Description>ReactiveUI extensions for the Android Support Library</Description>
<PackageId>ReactiveUI.AndroidSupport</PackageId>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
@@ -89,17 +89,26 @@ public FrameworkElement TargetObject
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
protected static void OnStateObservableChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var @this = (FollowObservableStateBehavior)sender;
if (@this._watcher != null)
if (e == null)
{
@this._watcher.Dispose();
@this._watcher = null;
throw new ArgumentNullException(nameof(e));
}

@this._watcher = ((IObservable<string>)e.NewValue).ObserveOn(RxApp.MainThreadScheduler).Subscribe(
if (!(sender is FollowObservableStateBehavior item))
{
throw new ArgumentException("Sender must be of type " + nameof(FollowObservableStateBehavior), nameof(sender));
}

if (item._watcher != null)
{
item._watcher.Dispose();
item._watcher = null;
}

item._watcher = ((IObservable<string>)e.NewValue).ObserveOn(RxApp.MainThreadScheduler).Subscribe(
x =>
{
var target = @this.TargetObject ?? @this.AssociatedObject;
var target = item.TargetObject ?? item.AssociatedObject;
#if NETFX_CORE
VisualStateManager.GoToState(target, x, true);
#else
@@ -115,12 +124,12 @@ protected static void OnStateObservableChanged(DependencyObject sender, Dependen
},
ex =>
{
if (!@this.AutoResubscribeOnError)
if (!item.AutoResubscribeOnError)
{
return;
}

OnStateObservableChanged(@this, e);
OnStateObservableChanged(item, e);
});
}

@@ -47,7 +47,11 @@ public IObservable<object> Observable
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
protected static void OnObservableChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
ObservableTrigger triggerItem = (ObservableTrigger)sender;
if (!(sender is ObservableTrigger triggerItem))
{
throw new ArgumentException("Sender must be of type " + nameof(ObservableTrigger), nameof(sender));
}

if (triggerItem._watcher != null)
{
triggerItem._watcher.Dispose();
@@ -6,6 +6,7 @@
<RootNamespace>ReactiveUI.Blend</RootNamespace>
<Description>Blend behaviors for ReactiveUI</Description>
<PackageId>ReactiveUI.Blend</PackageId>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
@@ -20,7 +20,7 @@ public static class ObservableAsPropertyExtensions
/// </summary>
/// <typeparam name="TObj">The type of the object.</typeparam>
/// <typeparam name="TRet">The type of the ret.</typeparam>
/// <param name="this">The this.</param>
/// <param name="item">The observable with the return value.</param>
/// <param name="source">The source.</param>
/// <param name="property">The property.</param>
/// <param name="initialValue">The initial value.</param>
@@ -32,10 +32,20 @@ public static class ObservableAsPropertyExtensions
/// or
/// Backing field not found for " + propertyInfo.
/// </exception>
public static ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this IObservable<TRet> @this, TObj source, Expression<Func<TObj, TRet>> property, TRet initialValue = default(TRet), bool deferSubscription = false, IScheduler scheduler = null)
public static ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this IObservable<TRet> item, TObj source, Expression<Func<TObj, TRet>> property, TRet initialValue = default, bool deferSubscription = false, IScheduler scheduler = null)
where TObj : ReactiveObject
{
var result = @this.ToProperty(source, property, initialValue, deferSubscription, scheduler);
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}

if (property == null)
{
throw new ArgumentNullException(nameof(property));
}

var result = item.ToProperty(source, property, initialValue, deferSubscription, scheduler);

// Now assign the field via reflection.
var propertyInfo = property.GetPropertyInfo();
@@ -11,6 +11,7 @@

<!-- Due to fody insisting on having .net 4 classes, we can't pack on non-windows -->
<IsPackable Condition=" '$(OS)' != 'Windows_NT' ">false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
@@ -13,7 +13,7 @@ namespace ReactiveUI.Fody.Helpers
}
public class static ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> @this, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue = null, bool deferSubscription = False, System.Reactive.Concurrency.IScheduler scheduler = null)
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue = null, bool deferSubscription = False, System.Reactive.Concurrency.IScheduler scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.All)]
@@ -13,7 +13,7 @@ namespace ReactiveUI.Fody.Helpers
}
public class static ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> @this, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue = null, bool deferSubscription = False, System.Reactive.Concurrency.IScheduler scheduler = null)
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue = null, bool deferSubscription = False, System.Reactive.Concurrency.IScheduler scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.All)]
@@ -4,6 +4,7 @@
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net461</TargetFrameworks>
<FodyTargetFramework>netstandard2.0</FodyTargetFramework>
<FodyTargetFramework Condition=" $(TargetFramework.StartsWith('net4')) ">$(TargetFramework)</FodyTargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
@@ -23,6 +23,16 @@ public static class CecilExtensions
/// <param name="il">The il.</param>
public static void Emit(this MethodBody body, Action<ILProcessor> il)
{
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}

if (il == null)
{
throw new ArgumentNullException(nameof(il));
}

il(body.GetILProcessor());
}

@@ -34,6 +44,11 @@ public static void Emit(this MethodBody body, Action<ILProcessor> il)
/// <returns>A generic method with generic typed arguments.</returns>
public static GenericInstanceMethod MakeGenericMethod(this MethodReference method, params TypeReference[] genericArguments)
{
if (genericArguments == null)
{
throw new ArgumentNullException(nameof(genericArguments));
}

var result = new GenericInstanceMethod(method);
foreach (var argument in genericArguments)
{
@@ -54,6 +69,16 @@ public static GenericInstanceMethod MakeGenericMethod(this MethodReference metho
/// </returns>
public static bool IsAssignableFrom(this TypeReference baseType, TypeReference type, Action<string> logger = null)
{
if (baseType == null)
{
throw new ArgumentNullException(nameof(baseType));
}

if (type == null)
{
throw new ArgumentNullException(nameof(type));
}

return baseType.Resolve().IsAssignableFrom(type.Resolve(), logger);
}

@@ -107,6 +132,11 @@ public static bool IsAssignableFrom(this TypeDefinition baseType, TypeDefinition
/// </returns>
public static bool IsDefined(this IMemberDefinition member, TypeReference attributeType)
{
if (member == null)
{
throw new ArgumentNullException(nameof(member));
}

return member.HasCustomAttributes && member.CustomAttributes.Any(x => x.AttributeType.FullName == attributeType.FullName);
}

@@ -118,41 +148,25 @@ public static bool IsDefined(this IMemberDefinition member, TypeReference attrib
/// <returns>The method bound to the generic type.</returns>
public static MethodReference Bind(this MethodReference method, GenericInstanceType genericType)
{
var reference = new MethodReference(method.Name, method.ReturnType, genericType);
reference.HasThis = method.HasThis;
reference.ExplicitThis = method.ExplicitThis;
reference.CallingConvention = method.CallingConvention;

foreach (var parameter in method.Parameters)
if (method == null)
{
reference.Parameters.Add(new ParameterDefinition(parameter.ParameterType));
throw new ArgumentNullException(nameof(method));
}

return reference;
}

/*
public static MethodReference BindDefinition(this MethodReference method, TypeReference genericTypeDefinition)
{
if (!genericTypeDefinition.HasGenericParameters)
return method;
var genericDeclaration = new GenericInstanceType(genericTypeDefinition);
foreach (var parameter in genericTypeDefinition.GenericParameters)
{
genericDeclaration.GenericArguments.Add(parameter);
}
var reference = new MethodReference(method.Name, method.ReturnType, genericDeclaration);
reference.HasThis = method.HasThis;
reference.ExplicitThis = method.ExplicitThis;
reference.CallingConvention = method.CallingConvention;
var reference = new MethodReference(method.Name, method.ReturnType, genericType)
{
HasThis = method.HasThis,
ExplicitThis = method.ExplicitThis,
CallingConvention = method.CallingConvention
};

foreach (var parameter in method.Parameters)
{
reference.Parameters.Add(new ParameterDefinition(parameter.ParameterType));
}

return reference;
}
*/

/// <summary>
/// Binds the generic type definition to a field.
@@ -162,6 +176,16 @@ public static MethodReference BindDefinition(this MethodReference method, TypeRe
/// <returns>The field bound to the generic type.</returns>
public static FieldReference BindDefinition(this FieldReference field, TypeReference genericTypeDefinition)
{
if (field == null)
{
throw new ArgumentNullException(nameof(field));
}

if (genericTypeDefinition == null)
{
throw new ArgumentNullException(nameof(genericTypeDefinition));
}

if (!genericTypeDefinition.HasGenericParameters)
{
return field;
@@ -185,6 +209,11 @@ public static FieldReference BindDefinition(this FieldReference field, TypeRefer
/// <returns>The assembly if found, null if not.</returns>
public static AssemblyNameReference FindAssembly(this ModuleDefinition currentModule, string assemblyName)
{
if (currentModule == null)
{
throw new ArgumentNullException(nameof(currentModule));
}

return currentModule.AssemblyReferences.SingleOrDefault(x => x.Name == assemblyName);
}

@@ -199,6 +228,11 @@ public static AssemblyNameReference FindAssembly(this ModuleDefinition currentMo
/// <returns>The type reference.</returns>
public static TypeReference FindType(this ModuleDefinition currentModule, string @namespace, string typeName, IMetadataScope scope = null, params string[] typeParameters)
{
if (typeParameters == null)
{
throw new ArgumentNullException(nameof(typeParameters));
}

var result = new TypeReference(@namespace, typeName, currentModule, scope);
foreach (var typeParameter in typeParameters)
{
@@ -216,28 +250,17 @@ public static TypeReference FindType(this ModuleDefinition currentModule, string
/// <returns>A value indicating the result of the comparison.</returns>
public static bool CompareTo(this TypeReference type, TypeReference compareTo)
{
return type.FullName == compareTo.FullName;
}

/*
public static IEnumerable<TypeDefinition> GetAllTypes(this ModuleDefinition module)
{
var stack = new Stack<TypeDefinition>();
foreach (var type in module.Types)
if (type == null)
{
stack.Push(type);
throw new ArgumentNullException(nameof(type));
}
while (stack.Any())
{
var current = stack.Pop();
yield return current;

foreach (var nestedType in current.NestedTypes)
{
stack.Push(nestedType);
}
if (compareTo == null)
{
throw new ArgumentNullException(nameof(compareTo));
}

return type.FullName == compareTo.FullName;
}
*/
}
}

0 comments on commit 3c185b1

Please sign in to comment.
You can’t perform that action at this time.