コード例 #1
0
ファイル: ObjectGraphParser.cs プロジェクト: ekolis/FrEee
        /// <summary>
        /// Adds an object.
        /// </summary>
        /// <param name="o"></param>
        /// <returns>The object's ID. IDs are unique within any any given object type but not across types.</returns>
        public int Add(object o)
        {
            if (o == null)
            {
                return(-1);
            }
            var type = o.GetType();

            if (!KnownTypes.ContainsKey(type.AssemblyQualifiedName))
            {
                KnownTypes.Add(type.AssemblyQualifiedName, type);
            }
            if (!KnownObjects.ContainsKey(type))
            {
                KnownObjects.Add(type, new List <object>());
            }
//			if (!KnownObjects[type].Contains(o))
            KnownObjects[type].Add(o);
            if (!KnownIDs.ContainsKey(type))
            {
                KnownIDs.Add(type, new SafeDictionary <object, int>());
            }
            var id = KnownObjects[type].Count - 1;

            KnownIDs[type].Add(o, id);
            AddProperties(type);
            return(id);
        }
コード例 #2
0
        private void RegisterType(Type type)
        {
            Contract.Requires(type != null);
            if (KnownTypes.Contains(type))
            {
                return;
            }

            if (type.IsMap && CommandLineOptions.Clo.TypeEncodingMethod == CommandLineOptions.TypeEncoding.Monomorphic)
            {
                KnownTypes.Add(type);
                MapType mapType = type.AsMap;
                Contract.Assert(mapType != null);

                foreach (Type t in mapType.Arguments)
                {
                    Contract.Assert(t != null);
                    RegisterType(t);
                }
                RegisterType(mapType.Result);

                if (!CommandLineOptions.Clo.UseArrayTheory)
                {
                    AddDeclaration("(declare-sort " + TypeToString(type) + " 0)");
                }

                return;
            }

            if (type.IsBool || type.IsInt || type.IsReal || type.IsBv || type.IsFloat || type.IsRMode || type.IsString || type.IsRegEx)
            {
                return;
            }

            CtorType ctorType = type as CtorType;

            if (ctorType != null)
            {
                // Check if this is a built-in type.  If so, no declaration is needed.
                string decl = ctorType.GetBuiltin();
                if (decl != null)
                {
                    KnownTypes.Add(type);
                    return;
                }
                if (ctorType.IsDatatype())
                {
                    return;
                }
            }

            if (CommandLineOptions.Clo.TypeEncodingMethod == CommandLineOptions.TypeEncoding.Monomorphic)
            {
                AddDeclaration("(declare-sort " + TypeToString(type) + " 0)");
                KnownTypes.Add(type);
                return;
            }
        }
コード例 #3
0
 public static void RegisterKnownType(IEnumerable <Type> types)
 {
     foreach (var type in types)
     {
         if (!KnownTypes.Contains(type))
         {
             KnownTypes.Add(type);
         }
     }
 }
コード例 #4
0
        public void Export(Type type)
        {
            //FIXME: Which types to exclude?
            KnownTypes.Add(type);
            SerializationMap map = KnownTypes.FindUserMap(type);

            if (map == null)
            {
                return;
            }

            map.GetSchemaType(Schemas, GeneratedTypes);
            Schemas.Compile();
        }
コード例 #5
0
ファイル: TypeDeclCollector.cs プロジェクト: yanntm/boogie
        private void RegisterType(Type type)
        {
            Contract.Requires(type != null);
            if (KnownTypes.Contains(type))
            {
                return;
            }

            if (type.IsMap && CommandLineOptions.Clo.MonomorphicArrays)
            {
                KnownTypes.Add(type);
                MapType mapType = type.AsMap;
                Contract.Assert(mapType != null);

                foreach (Type t in mapType.Arguments)
                {
                    Contract.Assert(t != null);
                    RegisterType(t);
                }
                RegisterType(mapType.Result);

                if (!CommandLineOptions.Clo.UseArrayTheory)
                {
                    AddDeclaration("(declare-sort " + TypeToString(type) + " 0)");
                }

                return;
            }

            if (type.IsBool || type.IsInt || type.IsReal || type.IsBv || type.IsFloat)
            {
                return;
            }

            CtorType ctorType = type as CtorType;

            if (ctorType != null && ctorType.IsDatatype())
            {
                return;
            }

            if (CommandLineOptions.Clo.TypeEncodingMethod == CommandLineOptions.TypeEncoding.Monomorphic)
            {
                AddDeclaration("(declare-sort " + TypeToString(type) + " 0)");
                KnownTypes.Add(type);
                return;
            }
        }
 internal void Add(MessagePartDescription part, CodeTypeReference typeReference, ICollection <CodeTypeReference> knownTypeReferences, bool isNonNillableReferenceType)
 {
     OperationGenerator.ParameterTypes.Add(part, typeReference);
     if (knownTypeReferences != null)
     {
         KnownTypes.Add(part, knownTypeReferences);
     }
     if (isNonNillableReferenceType)
     {
         if (isNonNillableReferenceTypes == null)
         {
             isNonNillableReferenceTypes = new Dictionary <MessagePartDescription, bool>();
         }
         isNonNillableReferenceTypes.Add(part, isNonNillableReferenceType);
     }
 }
コード例 #7
0
        public JassMapScriptAdapterContext()
        {
            Diagnostics          = new();
            KnownTypes           = new(StringComparer.Ordinal);
            KnownFunctions       = new(StringComparer.Ordinal);
            KnownGlobalVariables = new(StringComparer.Ordinal);
            KnownLocalVariables  = new(StringComparer.Ordinal);
            DialogueTitles       = new(StringComparer.Ordinal);
            DialogueTexts        = new(StringComparer.Ordinal);

            KnownTypes.Add(JassKeyword.Integer, null);
            KnownTypes.Add(JassKeyword.Boolean, null);
            KnownTypes.Add(JassKeyword.Real, null);
            KnownTypes.Add(JassKeyword.String, null);
            KnownTypes.Add(JassKeyword.Handle, null);
            KnownTypes.Add(JassKeyword.Code, null);
        }
コード例 #8
0
        public static void AddKnownTypes(IReadOnlyList <Type> types)
        {
            var key = (short)KnownKeys.Count;

            foreach (var type in types)
            {
                if (KnownTypes.ContainsKey(type))
                {
                    continue;
                }

                KnownKeys.Add(key, type);
                KnownTypes.Add(type, key);

                key++;
            }
        }
コード例 #9
0
        List <DataMemberInfo> GetMembers(Type type, QName qname, bool declared_only)
        {
            List <DataMemberInfo> data_members = new List <DataMemberInfo> ();
            BindingFlags          flags        = AllInstanceFlags;

            if (declared_only)
            {
                flags |= BindingFlags.DeclaredOnly;
            }

            foreach (PropertyInfo pi in type.GetProperties(flags))
            {
                DataMemberAttribute dma =
                    GetDataMemberAttribute(pi);
                if (dma == null)
                {
                    continue;
                }
                KnownTypes.Add(pi.PropertyType);
                var map = KnownTypes.FindUserMap(pi.PropertyType);
                if (!pi.CanRead || (!pi.CanWrite && !(map is ICollectionTypeMap)))
                {
                    throw new InvalidDataContractException(String.Format(
                                                               "DataMember property '{0}' on type '{1}' must have both getter and setter.", pi, pi.DeclaringType));
                }
                data_members.Add(CreateDataMemberInfo(dma, pi, pi.PropertyType, KnownTypeCollection.GetStaticQName(pi.DeclaringType).Namespace));
            }

            foreach (FieldInfo fi in type.GetFields(flags))
            {
                DataMemberAttribute dma =
                    GetDataMemberAttribute(fi);
                if (dma == null)
                {
                    continue;
                }
                data_members.Add(CreateDataMemberInfo(dma, fi, fi.FieldType, KnownTypeCollection.GetStaticQName(fi.DeclaringType).Namespace));
            }

            return(data_members);
        }
コード例 #10
0
ファイル: TypesManager.cs プロジェクト: gcanossa/N4pper.Ogm
        public void Entity(Type type, bool ignoreUnsupported = false)
        {
            type = type ?? throw new ArgumentNullException(nameof(type));
            if (!typeof(IOgmEntity).IsAssignableFrom(type))
            {
                throw new ArgumentException($"must be assignable to {typeof(IOgmEntity).FullName}", nameof(type));
            }

            if (type.IsSealed)
            {
                throw new ArgumentException("Unable to manage sealed types.", nameof(type));
            }
            if (type.GetMethods().Where(p => p.Name != nameof(Object.GetType) && !p.IsSpecialName).Any(p => !p.IsVirtual))
            {
                throw new ArgumentException("Unable to manage type with non virtual methods", nameof(type));
            }

            List <PropertyInfo> unsupported = type.GetProperties()
                                              .Where(
                p =>
                (
                    !typeof(IOgmConnection).IsAssignableFrom(type) ||
                    (p.Name != nameof(IOgmConnection.Source) && p.Name != nameof(IOgmConnection.Destination))
                ) && !IsGraphProperty(p)
                ).ToList();

            if (unsupported.Count > 0 && !ignoreUnsupported)
            {
                throw new ArgumentException($"Unable to manage type with non virtual properties or properties no deriving from {typeof(IOgmEntity).FullName} or compatible with {typeof(ICollection<IOgmEntity>).FullName}. Set '{nameof(ignoreUnsupported)}' parameter in order to ignore them.");
            }

            if (!KnownTypes.ContainsKey(type))
            {
                KnownTypes.Add(type, new KnownTypeDescriptor());
            }

            KnownTypes[type].IgnoredProperties.AddRange(unsupported);
        }
コード例 #11
0
 static SuspensionManager()
 {
     // Add known types for serialisation
     KnownTypes.Add(typeof(Dictionary <string, object>));
     KnownTypes.Add(typeof(Dictionary <string, Dictionary <string, object> >));
     KnownTypes.Add(typeof(Dictionary <string, Dictionary <string, Dictionary <string, object> > >));
     KnownTypes.Add(typeof(LayoutAwarePage.ObservableDictionary <string, object>));
     KnownTypes.Add(typeof(LayoutAwarePage.ObservableDictionary <string, Dictionary <string, object> >));
     KnownTypes.Add(typeof(LayoutAwarePage.ObservableDictionary <string, Dictionary <string, Dictionary <string, object> > >));
     KnownTypes.Add(typeof(EmailFlags));
     KnownTypes.Add(typeof(KeyValuePair <string, AccountSettingsData>));
     KnownTypes.Add(typeof(Dictionary <string, AccountSettingsData>));
     KnownTypes.Add(typeof(KeyValuePair <AccountSettingsData, ObservableCollection <MailboxListViewItem> >?));
     KnownTypes.Add(typeof(MailboxListViewItem));
     KnownTypes.Add(typeof(MailboxUnreadEmailCount));
     KnownTypes.Add(typeof(NotifyCollectionChangedEventHandler));
     KnownTypes.Add(typeof(MailHeaderDictionary));
     KnownTypes.Add(typeof(List <object>));
     KnownTypes.Add(typeof(MailHeader));
     KnownTypes.Add(typeof(PopMessage));
     KnownTypes.Add(typeof(ImapMessage));
     KnownTypes.Add(typeof(MessageNavigationContext));
 }
コード例 #12
0
        protected MathSyntax() : base(false)
        {
            SyntaxChars.Add(new Dictionary <int, TokenType>
            {
                { '(', TokenType.LParen },
                { ')', TokenType.RParen },
                { '|', TokenType.BitwiseOr },
                { '&', TokenType.BitwiseAnd },
                { '^', TokenType.BitwiseXOr },
                { '!', TokenType.LogicalNot },
                { '=', TokenType.Equal },
                { '<', TokenType.LessThan },
                { '>', TokenType.GreaterThan },
                { '~', TokenType.BitwiseNot },
                { '/', TokenType.Div },
                { '*', TokenType.Mul },
                { '+', TokenType.Add },
                { ',', TokenType.Delimiter }
            });


            Constants.Add(new Dictionary <string, object>
            {
                { "PI", Math.PI },
                { "E", Math.E },
                { "null", null },
                { "true", true },
                { "false", false },
                { "NaN", double.NaN },
                { "INF", double.PositiveInfinity }
            });


            Symbols.Add(new Dictionary <string, TokenType>
            {
                { "-", TokenType.Sub },
                { "&&", TokenType.LogicalAnd },
                { "||", TokenType.LogicalOr },
                { "==", TokenType.Equal },
                { "!=", TokenType.NotEqual },
                { "<=", TokenType.LessThanOrEqual },
                { ">=", TokenType.GreaterThanOrEqual },
                { ">>", TokenType.RightShift },
                { "<<", TokenType.LeftShift }
            });

            this.AddMathFunctions();


            KnownTypes.Add(new Dictionary <string, TypeParser>
            {
                { "byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "sbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) }
            });

            CompleteInitialization();
        }
コード例 #13
0
ファイル: TypesManager.cs プロジェクト: gcanossa/N4pper.Ogm
 public TypesManager()
 {
     KnownTypes.Add(typeof(Entities.OgmConnection), new KnownTypeDescriptor());
     KnownTypes[typeof(Entities.OgmConnection)].IgnoredProperties.Add(typeof(Entities.IOgmConnection).GetProperty(nameof(Entities.IOgmConnection.Source)));
     KnownTypes[typeof(Entities.OgmConnection)].IgnoredProperties.Add(typeof(Entities.IOgmConnection).GetProperty(nameof(Entities.IOgmConnection.Destination)));
 }
コード例 #14
0
ファイル: ODataSyntax.cs プロジェクト: jlamfers/XPression
        protected ODataSyntax() : base(true)
        {
            NonBreakingIdentifierChars.Add('.');

            SyntaxChars.Add(new Dictionary <int, TokenType>
            {
                { '-', TokenType.Negate },
                { '(', TokenType.LParen },
                { ')', TokenType.RParen },
                { ',', TokenType.Delimiter },
                { '/', TokenType.IdentifierDelimiter }
            });

            Symbols.Add(new Dictionary <string, TokenType>
            {
                { "and", TokenType.LogicalAnd },
                { "or", TokenType.LogicalOr },

                { "not", TokenType.LogicalNot },

                { "mod", TokenType.Mod },
                { "div", TokenType.Div },
                { "add", TokenType.Add },
                { "mul", TokenType.Mul },
                { "sub", TokenType.Sub },

                { "has", TokenType.Has },

                { "eq", TokenType.Equal },
                { "ne", TokenType.NotEqual },
                { "lt", TokenType.LessThan },
                { "gt", TokenType.GreaterThan },
                { "le", TokenType.LessThanOrEqual },
                { "ge", TokenType.GreaterThanOrEqual }
            });

            Functions.Add(new List <FunctionMap>
            {
                new FunctionMap("cast", new CastBuilder()),
                new FunctionMap("isof", new IsofBuilder()),

                new FunctionMap("contains", MemberTokens.String.Contains),
                new FunctionMap("startswith", MemberTokens.String.StartsWith),
                new FunctionMap("endswith", MemberTokens.String.EndsWith),
                new FunctionMap("concat", MemberTokens.String.Concat),
                new FunctionMap("indexof", MemberTokens.String.IndexOf),
                new FunctionMap("length", MemberTokens.String.Length),
                new FunctionMap("substring", MemberTokens.String.Substring1),
                new FunctionMap("substring", MemberTokens.String.Substring2), // overload
                new FunctionMap("toupper", MemberTokens.String.ToUpper),
                new FunctionMap("tolower", MemberTokens.String.ToLower),
                new FunctionMap("trim", MemberTokens.String.Trim),

                new FunctionMap("floor", MemberTokens.Math.FloorDecimal),
                new FunctionMap("floor", MemberTokens.Math.FloorDouble),
                new FunctionMap("round", MemberTokens.Math.RoundDecimalZeroDigits),
                new FunctionMap("round", MemberTokens.Math.RoundDoubleZeroDigits),
                new FunctionMap("ceiling", MemberTokens.Math.CeilingDecimal),
                new FunctionMap("ceiling", MemberTokens.Math.CeilingDouble),

                new FunctionMap("year", MemberTokens.DateTime.Year),
                new FunctionMap("year", MemberTokens.DateTimeOffset.Year),

                new FunctionMap("month", MemberTokens.DateTime.Month),
                new FunctionMap("month", MemberTokens.DateTimeOffset.Month),

                new FunctionMap("day", MemberTokens.DateTime.Day),
                new FunctionMap("day", MemberTokens.DateTimeOffset.Day),
                new FunctionMap("day", MemberTokens.TimeSpan.Days),

                new FunctionMap("hour", MemberTokens.DateTime.Hour),
                new FunctionMap("hour", MemberTokens.DateTimeOffset.Hour),
                new FunctionMap("hour", MemberTokens.TimeSpan.Hours),

                new FunctionMap("minute", MemberTokens.DateTime.Minute),
                new FunctionMap("minute", MemberTokens.DateTimeOffset.Minute),
                new FunctionMap("minute", MemberTokens.TimeSpan.Minutes),

                new FunctionMap("second", MemberTokens.DateTime.Second),
                new FunctionMap("second", MemberTokens.DateTimeOffset.Second),
                new FunctionMap("second", MemberTokens.TimeSpan.Seconds),

                new FunctionMap("fractionalseconds", MemberTokens.DateTime.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.DateTimeOffset.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.TimeSpan.Milliseconds),

                new FunctionMap("totalfractionalseconds", MemberTokens.TimeSpan.TotalMilliseconds),
                new FunctionMap("totalseconds", MemberTokens.TimeSpan.TotalSeconds),
                new FunctionMap("totalminutes", MemberTokens.TimeSpan.TotalMinutes),
                new FunctionMap("totalhours", MemberTokens.TimeSpan.TotalHours),
                new FunctionMap("totaldays", MemberTokens.TimeSpan.TotalDays),
                new FunctionMap("totaloffsetminutes", new TotalOffsetMinutesBuilder()),

                new FunctionMap("date", MemberTokens.DateTimeOffset.Date),
                new FunctionMap("time", MemberTokens.DateTimeOffset.TimeOfDay),
                new FunctionMap("time", MemberTokens.DateTime.TimeOfDay),
                new FunctionMap("now", MemberTokens.DateTimeOffset.Now),
                new FunctionMap("utcnow", MemberTokens.DateTimeOffset.UtcNow), // not OData specified

                new FunctionMap("mindatetime", MemberTokens.DateTimeOffset.MinValue),
                new FunctionMap("maxdatetime", MemberTokens.DateTimeOffset.MaxValue),


                new FunctionMap("dow", MemberTokens.DateTimeOffset.DayOfWeek), // not OData specified
                new FunctionMap("dow", MemberTokens.DateTime.DayOfWeek),
            });

            this.TryAddSqlServerSpatialTypes();


            Constants.Add(new Dictionary <string, object>
            {
                { "null", null },
                { "true", true },
                { "false", false },
                { "NaN", double.NaN },
                { "INF", double.PositiveInfinity }
            });

            KnownTypes.Add(new Dictionary <string, TypeParser>
            {
                { "X", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "binary", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "string", new TypeParser(typeof(string), lex => lex) },
                { "boolean", new TypeParser(typeof(bool), lex => bool.Parse(lex)) },
                { "byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "datetime", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "single", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "guid", new TypeParser(typeof(Guid), lex => Guid.Parse(lex)) },
                { "int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "sbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) },
                { "time", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "duration", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "datetimeoffset", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) },

                { "Edm.Binary", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "Edm.String", new TypeParser(typeof(string), lex => lex) },
                { "Edm.Boolean", new TypeParser(typeof(bool), lex => bool.Parse(lex)) },
                { "Edm.Byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "Edm.DateTime", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "Edm.Decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "Edm.Double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "Edm.Single", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "Edm.Float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "Edm.Guid", new TypeParser(typeof(Guid), lex => Guid.Parse(lex)) },
                { "Edm.Int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "Edm.Int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "Edm.Int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "Edm.SBbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) },
                { "Edm.Time", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "Edm.Duration", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "Edm.DateTimeOffset", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) }
            });

            CompleteInitialization();
        }
コード例 #15
0
 public SysXmlCursorTestCase()
 {
     KnownTypes.Add(ItemType, true);
     KnownTypes.Add(OtherType, true);
 }
コード例 #16
0
ファイル: ScriptSyntax.cs プロジェクト: jlamfers/XPression
        protected ScriptSyntax() : base(false)
        {
            LineComment = '#';

            NonBreakingIdentifierChars.Add('$');

            SyntaxChars.Add(new Dictionary <int, TokenType>
            {
                { '-', TokenType.Negate },
                { '(', TokenType.LParen },
                { ')', TokenType.RParen },
                { '[', TokenType.LArrayBracket },
                { ']', TokenType.RArrayBracket },
                { ',', TokenType.Delimiter },
                { ';', TokenType.LogicalAnd }, // statement seperarator
                { '|', TokenType.BitwiseOr },
                { '&', TokenType.BitwiseAnd },
                { '^', TokenType.BitwiseXOr },
                { '!', TokenType.LogicalNot },
                { '<', TokenType.LessThan },
                { '>', TokenType.GreaterThan },
                { '~', TokenType.BitwiseNot },
                { '/', TokenType.Div },
                { '*', TokenType.Mul },
                { '+', TokenType.Add },
                { '.', TokenType.IdentifierDelimiter },
                { '=', TokenType.Assignment },
                { '@', TokenType.SyntaxEscape }
            });


            Constants.Add(new Dictionary <string, object>
            {
                { "PI", Math.PI },
                { "E", Math.E },
                { "null", null },
                { "true", true },
                { "false", false },
                { "NaN", double.NaN },
                { "INF", double.PositiveInfinity }
            });


            Symbols.Add(new Dictionary <string, TokenType>
            {
                { "-", TokenType.Sub },
                { "==", TokenType.Equal },
                { "!=", TokenType.NotEqual },
                { "||", TokenType.LogicalOr },
                { "&&", TokenType.LogicalAnd },
                { ">>", TokenType.RightShift },
                { "<<", TokenType.LeftShift },
                { "var", TokenType.Declaration }
            });


            Functions.Add(new List <FunctionMap>
            {
                new FunctionMap("if", new IffBuilder()),
                new FunctionMap("else", new ElseBuilder()),
                new FunctionMap("format", new FormatBuilder()),
                new FunctionMap("cast", new CastBuilder()),
                new FunctionMap("contains", MemberTokens.String.Contains),
                new FunctionMap("startswith", MemberTokens.String.StartsWith),
                new FunctionMap("endswith", MemberTokens.String.EndsWith),
                new FunctionMap("concat", MemberTokens.String.Concat),
                new FunctionMap("indexof", MemberTokens.String.IndexOf),
                new FunctionMap("length", MemberTokens.String.Length),
                new FunctionMap("substring", MemberTokens.String.Substring1),
                new FunctionMap("substring", MemberTokens.String.Substring2), // overload
                new FunctionMap("toupper", MemberTokens.String.ToUpper),
                new FunctionMap("tolower", MemberTokens.String.ToLower),
                new FunctionMap("trim", MemberTokens.String.Trim),

                new FunctionMap("year", MemberTokens.DateTime.Year),
                new FunctionMap("year", MemberTokens.DateTimeOffset.Year),

                new FunctionMap("month", MemberTokens.DateTime.Month),
                new FunctionMap("month", MemberTokens.DateTimeOffset.Month),

                new FunctionMap("day", MemberTokens.DateTime.Day),
                new FunctionMap("day", MemberTokens.DateTimeOffset.Day),
                new FunctionMap("day", MemberTokens.TimeSpan.Days),

                new FunctionMap("hour", MemberTokens.DateTime.Hour),
                new FunctionMap("hour", MemberTokens.DateTimeOffset.Hour),
                new FunctionMap("hour", MemberTokens.TimeSpan.Hours),

                new FunctionMap("minute", MemberTokens.DateTime.Minute),
                new FunctionMap("minute", MemberTokens.DateTimeOffset.Minute),
                new FunctionMap("minute", MemberTokens.TimeSpan.Minutes),

                new FunctionMap("second", MemberTokens.DateTime.Second),
                new FunctionMap("second", MemberTokens.DateTimeOffset.Second),
                new FunctionMap("second", MemberTokens.TimeSpan.Seconds),

                new FunctionMap("fractionalseconds", MemberTokens.DateTime.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.DateTimeOffset.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.TimeSpan.Milliseconds),

                new FunctionMap("totalfractionalseconds", MemberTokens.TimeSpan.TotalMilliseconds),
                new FunctionMap("totalseconds", MemberTokens.TimeSpan.TotalSeconds),
                new FunctionMap("totalminutes", MemberTokens.TimeSpan.TotalMinutes),
                new FunctionMap("totalhours", MemberTokens.TimeSpan.TotalHours),
                new FunctionMap("totaldays", MemberTokens.TimeSpan.TotalDays),

                new FunctionMap("date", MemberTokens.DateTimeOffset.Date),
                new FunctionMap("time", MemberTokens.DateTimeOffset.TimeOfDay),
                new FunctionMap("time", MemberTokens.DateTime.TimeOfDay),
                new FunctionMap("now", MemberTokens.DateTimeOffset.Now),
                new FunctionMap("utcnow", MemberTokens.DateTimeOffset.UtcNow),

                new FunctionMap("dow", MemberTokens.DateTimeOffset.DayOfWeek),
                new FunctionMap("dow", MemberTokens.DateTime.DayOfWeek),
            });


            foreach (var m in typeof(TExtender).GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(m => Attribute.IsDefined(m, typeof(ScriptMethodAttribute))))
            {
                Functions.Add(new FunctionMap(m.GetCustomAttribute <ScriptMethodAttribute>().Name, m));
            }

            this.AddMathFunctions();

            KnownTypes.Add(new Dictionary <string, TypeParser>
            {
                { "X", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "string", new TypeParser(typeof(string), lex => lex) },
                { "bool", new TypeParser(typeof(bool), lex => bool.Parse(lex)) },
                { "byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "dt", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "datetime", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "guid", new TypeParser(typeof(Guid), lex => Guid.Parse(lex)) },
                { "int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "sbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) },
                { "ts", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "timespan", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "dto", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) },
                { "datetimeoffset", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) }
            });

            CompleteInitialization();
        }
コード例 #17
0
 public virtual void OneTimeSetUp()
 {
     KnownTypes.Add(ItemType, true);
     KnownTypes.Add(OtherType, true);
 }
コード例 #18
0
        protected CompactSyntax() : base(ignoreCase: false)
        {
            SyntaxChars.Add(new Dictionary <int, TokenType>
            {
                { '-', TokenType.Negate },
                { '(', TokenType.LParen },
                { ')', TokenType.RParen },
                { '^', TokenType.StartsWith },
                { '$', TokenType.EndsWith },
                { '?', TokenType.Contains },
                { '!', TokenType.LogicalNot },
                { '=', TokenType.Equal },
                { '|', TokenType.LogicalOr },
                { '&', TokenType.LogicalAnd },
                { '<', TokenType.LessThan },
                { '>', TokenType.GreaterThan },
                { '~', TokenType.Has },
                { '/', TokenType.Div },
                { '*', TokenType.Mul },
                { '+', TokenType.Add },
                { '%', TokenType.Mod },
                { ',', TokenType.Delimiter },
                { '@', TokenType.SyntaxEscape },
                { '.', TokenType.IdentifierDelimiter }
            });


            Constants.Add(new Dictionary <string, object>
            {
                { "PI", Math.PI },
                { "E", Math.E },
                { "null", null },
                { "true", true },
                { "false", false },
                { "NaN", double.NaN },
                { "INF", double.PositiveInfinity }
            });


            Symbols.Add(new Dictionary <string, TokenType>
            {
                { "-", TokenType.Sub }, // context dependent
                { "like", TokenType.Like },
                { "!=", TokenType.NotEqual },
                { "<=", TokenType.LessThanOrEqual },
                { ">=", TokenType.GreaterThanOrEqual }
            });

            Functions.Add(new List <FunctionMap>
            {
                new FunctionMap("cast", new CastBuilder()),
                new FunctionMap("contains", MemberTokens.String.Contains),
                new FunctionMap("startswith", MemberTokens.String.StartsWith),
                new FunctionMap("endswith", MemberTokens.String.EndsWith),
                new FunctionMap("concat", MemberTokens.String.Concat),
                new FunctionMap("indexof", MemberTokens.String.IndexOf),
                new FunctionMap("length", MemberTokens.String.Length),
                new FunctionMap("substring", MemberTokens.String.Substring1),
                new FunctionMap("substring", MemberTokens.String.Substring2), // overload
                new FunctionMap("toupper", MemberTokens.String.ToUpper),
                new FunctionMap("tolower", MemberTokens.String.ToLower),
                new FunctionMap("trim", MemberTokens.String.Trim),

                new FunctionMap("year", MemberTokens.DateTime.Year),
                new FunctionMap("year", MemberTokens.DateTimeOffset.Year),

                new FunctionMap("month", MemberTokens.DateTime.Month),
                new FunctionMap("month", MemberTokens.DateTimeOffset.Month),

                new FunctionMap("day", MemberTokens.DateTime.Day),
                new FunctionMap("day", MemberTokens.DateTimeOffset.Day),
                new FunctionMap("day", MemberTokens.TimeSpan.Days),

                new FunctionMap("hour", MemberTokens.DateTime.Hour),
                new FunctionMap("hour", MemberTokens.DateTimeOffset.Hour),
                new FunctionMap("hour", MemberTokens.TimeSpan.Hours),

                new FunctionMap("minute", MemberTokens.DateTime.Minute),
                new FunctionMap("minute", MemberTokens.DateTimeOffset.Minute),
                new FunctionMap("minute", MemberTokens.TimeSpan.Minutes),

                new FunctionMap("second", MemberTokens.DateTime.Second),
                new FunctionMap("second", MemberTokens.DateTimeOffset.Second),
                new FunctionMap("second", MemberTokens.TimeSpan.Seconds),

                new FunctionMap("fractionalseconds", MemberTokens.DateTime.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.DateTimeOffset.Millisecond),
                new FunctionMap("fractionalseconds", MemberTokens.TimeSpan.Milliseconds),

                new FunctionMap("totalfractionalseconds", MemberTokens.TimeSpan.TotalMilliseconds),
                new FunctionMap("totalseconds", MemberTokens.TimeSpan.TotalSeconds),
                new FunctionMap("totalminutes", MemberTokens.TimeSpan.TotalMinutes),
                new FunctionMap("totalhours", MemberTokens.TimeSpan.TotalHours),
                new FunctionMap("totaldays", MemberTokens.TimeSpan.TotalDays),

                new FunctionMap("date", MemberTokens.DateTimeOffset.Date),
                new FunctionMap("time", MemberTokens.DateTimeOffset.TimeOfDay),
                new FunctionMap("time", MemberTokens.DateTime.TimeOfDay),
                new FunctionMap("now", MemberTokens.DateTimeOffset.Now),
                new FunctionMap("utcnow", MemberTokens.DateTimeOffset.UtcNow),

                new FunctionMap("dow", MemberTokens.DateTimeOffset.DayOfWeek),
                new FunctionMap("dow", MemberTokens.DateTime.DayOfWeek),
            });

            this.TryAddSqlServerSpatialTypes();

            KnownTypes.Add(new Dictionary <string, TypeParser>()
            {
                { "X", new TypeParser(typeof(byte[]), lex => lex.ParseBinary()) },
                { "string", new TypeParser(typeof(string), lex => lex) },
                { "bool", new TypeParser(typeof(bool), lex => bool.Parse(lex)) },
                { "byte", new TypeParser(typeof(byte), lex => byte.Parse(lex)) },
                { "datetime", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "dt", new TypeParser(typeof(DateTime), lex => XmlConvert.ToDateTime(lex, XmlDateTimeSerializationMode.Local)) },
                { "decimal", new TypeParser(typeof(decimal), lex => decimal.Parse(lex)) },
                { "double", new TypeParser(typeof(double), lex => double.Parse(lex)) },
                { "float", new TypeParser(typeof(float), lex => float.Parse(lex)) },
                { "guid", new TypeParser(typeof(Guid), lex => Guid.Parse(lex)) },
                { "int16", new TypeParser(typeof(Int16), lex => Int16.Parse(lex)) },
                { "int32", new TypeParser(typeof(Int32), lex => int.Parse(lex)) },
                { "int64", new TypeParser(typeof(Int64), lex => long.Parse(lex)) },
                { "sbyte", new TypeParser(typeof(sbyte), lex => sbyte.Parse(lex)) },
                { "duration", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "timespan", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "ts", new TypeParser(typeof(TimeSpan), lex => XmlConvert.ToTimeSpan(lex)) },
                { "dto", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) },
                { "datetimeoffset", new TypeParser(typeof(DateTimeOffset), lex => XmlConvert.ToDateTimeOffset(lex)) }
            });

            CompleteInitialization();
        }