Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 11 additions & 1 deletion src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
25 changes: 17 additions & 8 deletions src/ReactiveUI.Blend/FollowObservableStateBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/ReactiveUI.Blend/Platforms/net461/ObservableTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/ReactiveUI.Blend/ReactiveUI.Blend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<RootNamespace>ReactiveUI.Blend</RootNamespace>
<Description>Blend behaviors for ReactiveUI</Description>
<PackageId>ReactiveUI.Blend</PackageId>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions src/ReactiveUI.Fody.Helpers/ObservableAsPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/ReactiveUI.Fody.Tests/ReactiveUI.Fody.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
111 changes: 67 additions & 44 deletions src/ReactiveUI.Fody/CecilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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)
{
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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)
{
Expand All @@ -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;
}
*/
}
}
Loading