Example #1
0
        public static object?Create(string image, ExpressionBuilderOptions options)
        {
            builderOptions = options;
            LiteralElement?element = CreateSingle(image);

            if (element != null)
            {
                return(element);
            }

            element = CreateDecimal(image);
            if (element != null)
            {
                return(element);
            }

            element = CreateDouble(image);
            if (element != null)
            {
                return(element);
            }

            element = CreateImplicitReal(image);

            return(element);
        }
Example #2
0
        /// <summary>
        /// Creates a new namespace import with a given namespace name
        /// </summary>
        /// <param name="importNamespace">The name of the namespace to import</param>
        /// <param name="options"></param>
        public NamespaceImport(string importNamespace, ExpressionBuilderOptions options) : base(options)
        {
            if (importNamespace == null)
            {
                throw new ArgumentNullException(nameof(importNamespace));
            }

            if (importNamespace.Length == 0)
            {
                throw new ArgumentException(GeneralErrors.InvalidNamespaceName);
            }

            _namespace = importNamespace;
            _imports   = new List <ImportBase>();
        }
Example #3
0
        public static LiteralElement?CreateFromInteger(string image, ExpressionBuilderOptions options)
        {
            builderOptions = options;
            LiteralElement element = CreateSingle(image);

            if (element != null)
            {
                return(element);
            }

            element = CreateDecimal(image);

            if (element != null)
            {
                return(element);
            }

            if (builderOptions.IntegerAsDouble)
            {
                return(DoubleLiteralElement.Parse(image));
            }

            return(null);
        }
Example #4
0
 public void CopyFrom(ExpressionBuilderOptions other)
 {
     this.LiftMemberAccessToNull = other.LiftMemberAccessToNull;
 }
 public void CopyFrom(ExpressionBuilderOptions other)
 {
     this.LiftMemberAccessToNull = other.LiftMemberAccessToNull;
 }
Example #6
0
 protected ExpressionBuilderBase(Type itemType)
 {
     this.itemType = itemType;
     options       = new ExpressionBuilderOptions();
 }
Example #7
0
 public TypeImport(Type importType, ExpressionBuilderOptions options) : this(importType, false, options)
 {
     Options.AssertTypeIsAccessible(Target);
 }
Example #8
0
        /// <summary>
        /// Attempt to find the first type of integer that a number can fit into
        /// </summary>
        /// <param name="image"></param>
        /// <param name="isHex"></param>
        /// <param name="negated"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static LiteralElement Create(string image, bool isHex, bool negated, ExpressionBuilderOptions options)
        {
            const StringComparison comparison = StringComparison.OrdinalIgnoreCase;

            if (isHex == false)
            {
                // Create a real element if required
                var realElement = RealLiteralElement.CreateFromInteger(image, options);

                if (realElement != null)
                {
                    return(realElement);
                }
            }

            var hasUSuffix  = image.EndsWith("u", comparison) & !image.EndsWith("lu", comparison);
            var hasLSuffix  = image.EndsWith("l", comparison) & !image.EndsWith("ul", comparison);
            var hasUlSuffix = image.EndsWith("ul", comparison) | image.EndsWith("lu", comparison);
            var hasSuffix   = hasUSuffix | hasLSuffix | hasUlSuffix;

            LiteralElement constant;
            var            numStyles = NumberStyles.Integer;

            if (isHex)
            {
                numStyles = NumberStyles.AllowHexSpecifier;
                image     = image.Remove(0, 2);
            }

            if (hasSuffix == false)
            {
                // If the literal has no suffix, it has the first of these types in which its value can be represented: int, uint, long, ulong.
                constant = Int32LiteralElement.TryCreate(image, isHex, negated);
                if (constant != null)
                {
                    return(constant);
                }

                constant = UInt32LiteralElement.TryCreate(image, numStyles);
                if (constant != null)
                {
                    return(constant);
                }

                constant = Int64LiteralElement.TryCreate(image, isHex, negated);
                if (constant != null)
                {
                    return(constant);
                }

                return(new UInt64LiteralElement(image, numStyles));
            }

            if (hasUSuffix)
            {
                image = image.Remove(image.Length - 1);
                // If the literal is suffixed by U or u, it has the first of these types in which its value can be represented: uint, ulong.

                constant = UInt32LiteralElement.TryCreate(image, numStyles);

                return(constant ?? new UInt64LiteralElement(image, numStyles));
            }

            if (hasLSuffix)
            {
                // If the literal is suffixed by L or l, it has the first of these types in which its value can be represented: long, ulong.
                image = image.Remove(image.Length - 1);

                constant = Int64LiteralElement.TryCreate(image, isHex, negated);

                return(constant ?? new UInt64LiteralElement(image, numStyles));
            }

            // If the literal is suffixed by UL, Ul, uL, ul, LU, Lu, lU, or lu, it is of type ulong.
            Debug.Assert(true, "expecting ul suffix");
            image = image.Remove(image.Length - 2);
            return(new UInt64LiteralElement(image, numStyles));
        }
Example #9
0
 internal ImportCollection(ExpressionBuilderOptions options)
 {
     this.options = options;
     RootImport   = new NamespaceImport("true", this.options);
     ImportOwner(typeof(object));
 }