Esempio n. 1
0
        public static ExpressionAction ResolveMetadataDeclarationFor(MethodCallExpression expression, IRequirementsBuilder requirementsBuiler, out Expression replacement)
        {
            replacement = null;
            if (!IsMetadataDeclarationForMethod(expression.Method))
                return ExpressionAction.None;

            if (expression.Arguments.Count == 0 || typeof(Expression).IsAssignableFrom(expression.Arguments[0].Type))
                return ExpressionAction.None;

            // if any parameters are referenced, fail the expression (cannot port, cannot invoke)
            if (RegionAnalysisStrategy.GetReferencedParameters(expression.Object).Count() > 0)
                return ExpressionAction.Fail;

            // if object is a constant, set a metadata requirement and continue
            if (expression.Object == null)
                throw new ArgumentNullException();
            if (expression.Object is ConstantExpression)
            {
                var constexp = (ConstantExpression) expression.Object;
                requirementsBuiler.NoteMetadataRequirement(new MetadataInfo(expression.Arguments[0].Type, (IExodataDeclaration)constexp.Value, expression.Method,
                    (expression.Arguments.Count == 2) ? expression.Arguments[1] : null));
                return ExpressionAction.Retain;
            }

            // otherwise, attempt to convert the constant expression to a constant
            var constval = (IExodataDeclaration)Expression.Lambda(expression.Object).Compile().DynamicInvoke();
            var objectValue = Expression.Constant(constval);

            replacement = Expression.Call(objectValue, expression.Method, expression.Arguments);
            return ExpressionAction.Replace;
        }
Esempio n. 2
0
        public static ExpressionAction ResolveBindingGetValue(MethodCallExpression expression, IRequirementsBuilder requirementsBuiler, out Expression replacement)
        {
            replacement = null;
            if (!IsBindingGetValueMethod(expression.Method))
                return ExpressionAction.None;

            return ExpressionAction.Retain;
        }
Esempio n. 3
0
        public RequirementsBuilderTests()
        {
            _tempDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
            while (Directory.Exists(_tempDirectory))
            {
                _tempDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
            }

            _requirementsBuilder = new DocGen.Requirements.Impl.RequirementsBuilder(new DocGen.Requirements.Impl.RequirementsParser(new DocGen.Core.Markdown.Impl.YamlParser()));
        }
 public RequirementsContextBuilder(
     IOptions <DocGenOptions> options,
     IRequirementsBuilder requirementsBuilder,
     IServiceProvider serviceProvider,
     IMarkdownRenderer markdownRenderer)
 {
     _options             = options.Value;
     _requirementsBuilder = requirementsBuilder;
     _serviceProvider     = serviceProvider;
     _markdownRenderer    = markdownRenderer;
 }
Esempio n. 5
0
        public static ExpressionAction ResolveStringCompare(MethodCallExpression expression, IRequirementsBuilder requirementsBuiler,
            out Expression replacement)
        {
            replacement = null;
            if (expression.Method != StringCompareMethodInfo)
                return ExpressionAction.None;

            return ExpressionAction.Retain;
        }