private bool IsRequiresAvailableFor(out string parameterName, out IClrTypeName parameterType)
        {
            parameterName = null;
            parameterType = null;

            var parameterRequiresAvailability = ParameterRequiresAvailability.Create(_provider);

            if (parameterRequiresAvailability.IsAvailable)
            {
                parameterName = parameterRequiresAvailability.ParameterName;
                parameterType = parameterRequiresAvailability.ParameterType;
                return(true);
            }

            var propertySetterRequiresAvailability = new PropertySetterRequiresAvailability(_provider);

            if (propertySetterRequiresAvailability.IsAvailable)
            {
                parameterName = "value";
                parameterType = propertySetterRequiresAvailability.PropertyType;
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private bool ParameterSupportRequires(out string parameterName, out IClrTypeName parameterType)
        {
            var parameterDeclaration = ParameterRequiresAvailability.Create(_provider);

            if (parameterDeclaration.IsAvailable)
            {
                parameterName = parameterDeclaration.ParameterName;
                parameterType = parameterDeclaration.ParameterType;
                return(true);
            }

            parameterName = null;
            parameterType = null;
            return(false);
        }
Beispiel #3
0
        private bool ComputeIsAvailableForIndexer(out ICSharpFunctionDeclaration getterDeclaration,
                                                  out ICSharpFunctionDeclaration setterDeclaration, out string parameterName,
                                                  out IClrTypeName propertyType)
        {
            getterDeclaration = null;
            setterDeclaration = null;
            propertyType      = null;
            parameterName     = null;

            var indexerDeclaration = _provider.GetSelectedElement <IIndexerDeclaration>(true, true);

            if (indexerDeclaration == null)
            {
                return(false);
            }

            propertyType = indexerDeclaration.Type.GetClrTypeName();

            var accessorDeclaration = _provider.GetSelectedElement <IAccessorDeclaration>(true, true);

            if (accessorDeclaration != null)
            {
                parameterName = "value";

                if (accessorDeclaration.Kind == AccessorKind.GETTER)
                {
                    return(false);
                }

                setterDeclaration = accessorDeclaration;
                // Selected property setter. Action should be available for reference and non-nullable value types.
                return(indexerDeclaration.Type.IsReferenceOrNullableType());
            }

            getterDeclaration = indexerDeclaration.AccessorDeclarations.FirstOrDefault(a => a.Kind == AccessorKind.GETTER);
            setterDeclaration = indexerDeclaration.AccessorDeclarations.FirstOrDefault(a => a.Kind == AccessorKind.SETTER);
            if (getterDeclaration == null && setterDeclaration == null)
            {
                return(false);
            }

            var parameterDeclaration = ParameterRequiresAvailability.Create(_provider);

            parameterName = parameterDeclaration.ParameterName;
            return(parameterDeclaration.IsAvailable);
        }
Beispiel #4
0
        private List <ArgumentDescription> GetArgumentsAvailableForRequiresCheck(ICSharpFunctionDeclaration selectedMethod)
        {
            Contract.Requires(selectedMethod != null);
            Contract.Ensures(Contract.Result <List <ArgumentDescription> >() != null);

            var parameterRequiresAvailability =
                selectedMethod.DeclaredElement.Parameters
                .SelectMany(pm => pm.GetDeclarations())
                .Select(pm => pm as IParameterDeclaration)
                .Where(pm => pm != null)
                .Select(p => ParameterRequiresAvailability.Create(_provider, p))
                .Where(p => p.IsAvailable)
                .ToList();

            // Contract function could be absent, but in this case we'll generate contract
            // class (and function) before adding all preconditions!
            var contractFunction = selectedMethod.GetContractFunction();

            if (contractFunction == null)
            {
                return(parameterRequiresAvailability.Select(p =>
                                                            new ArgumentDescription {
                    Name = p.ParameterName, Type = p.ParameterType
                })
                       .ToList());
            }

            Func <ParameterRequiresAvailability, bool> isFuncAvailable =
                p => new FunctionRequiresAvailability(_provider, p.ParameterName, contractFunction).IsAvailable;

            var availableArguments =
                parameterRequiresAvailability
                .Where(isFuncAvailable)
                .Select(pa =>
                        new ArgumentDescription {
                Name = pa.ParameterName, Type = pa.ParameterType
            })
                .ToList();

            return(availableArguments);
        }