Beispiel #1
0
        private static Table ConvertStringToTable(string str)
        {
            str = str.Replace("\r", "");
            Parser    p    = new Parser(str, Parser.ReadOptions.STRING, Parser.ParseOptions.REMOVE_ONLY_TABS);
            ParseTree tree = new ParseTree(p.ParseTable);

            if (!tree.successfulParse)
            {
                return(null);
            }

            int                 size        = int.Parse(tree["<int>"][0].Data);
            string              name        = tree["<sentence>"][0].Data;
            ParseNode           relationPtr = tree["<relation_list>"];
            List <NameTypePair> ntpList     = new List <NameTypePair>();

            do
            {
                if (relationPtr.Data == "<relation_list_tail>")
                {
                    relationPtr = relationPtr[0];
                }
                NameTypePair ntp = new NameTypePair(relationPtr[0]);
                ntpList.Add(ntp);

                relationPtr = relationPtr[1];
            } while (relationPtr != null);
            Relation generatedRelation = new Relation(ntpList.ToArray());
            Table    output            = new Table(name, generatedRelation, true, size);



            var tupleListPtr = tree["<tuple_list>"];

            while (tupleListPtr != null)
            {
                if (tupleListPtr.Data == "<tuple_list_tail>")
                {
                    tupleListPtr = tupleListPtr[0];
                }
                int index = int.Parse(tupleListPtr[0][0].Data);

                output.AllLists[index].AddFirst(RADTuple.CreateFromParseNode(generatedRelation, tupleListPtr["<tuple>"]));                 // TODO: Tuple ParseNode to tuple Constructor
                var tuplePtr = tupleListPtr["<tuple_more>"];
                while (tuplePtr != null)
                {
                    ParseNode tupleNode = tuplePtr["<tuple>"];
                    RADTuple  tuple     = RADTuple.CreateFromParseNode(generatedRelation, tupleNode);
                    output.AllLists[index].AddLast(tuple);
                    tuplePtr = tuplePtr["<tuple_more>"];
                }


                tupleListPtr = tupleListPtr["<tuple_list_tail>"];
            }

            output.SecondaryIndexing.ReCreateSecondaryIndex();
            //Console.WriteLine("Created Table From File");
            return(output);
        }
Beispiel #2
0
        static void AddToMap(SourceType sourceType, string[] sourceNames)
        {
            NameTypePair pair = new NameTypePair(sourceNames[0], sourceType);

            foreach (string source in sourceNames)
            {
                sourceMap.Add(source, pair);
            }
        }
Beispiel #3
0
            public override bool Equals(object obj)
            {
                if (!(obj is NameTypePair))
                {
                    return(false);
                }
                NameTypePair other = obj as NameTypePair;

                return(Name.Equals(other.Name) && Type.Equals(other.Type));
            }
        private void ComboBoxSelected(object sender, RoutedEventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            NameTypePair serverNameType = comboBox.SelectedItem as NameTypePair;

            Type serverType = serverNameType.Type;

            Initializer.HasDirectoryList.Filter(serverType);
        }
Beispiel #5
0
        public static Expression <Func <TIn, TOut> > BuildSelectorClause <TIn, TOut>(string[] properties) where TOut : class, new()
        {
            Array.Sort(properties);

            var key = new NameTypePair(string.Join("_", properties), typeof(TIn), typeof(TOut));

            if (!ExpressionCache.ContainsKey(key))
            {
                var param = Expression.Parameter(typeof(TIn), "p");
                var ctor  = typeof(TOut).GetConstructor(Type.EmptyTypes);
                Debug.Assert(ctor != null, "ctor is null");

                var memberBindings = new MemberBinding[properties.Length];
                for (var i = 0; i < properties.Length; i++)
                {
                    var p = typeof(TOut).GetProperty(properties[i]);
                    Debug.Assert(p.CanWrite, string.Format("{0} not support set", properties[i]));

                    PropertyInfo p2;
                    var          attrs = (MappingAttribute[])p.GetCustomAttributes(typeof(MappingAttribute), false);
                    if (attrs.Length > 0)
                    {
                        var attr = attrs.FirstOrDefault(a => a.ToType == typeof(TIn)) ?? attrs[0];
                        p2 = typeof(TIn).GetProperty(attr.To ?? p.Name);
                        Debug.Assert(p2 != null, string.Format("{0} not found property: {1}", typeof(TIn), attr.To));
                    }
                    else
                    {
                        p2 = typeof(TIn).GetProperty(properties[i]);
                        Debug.Assert(p2 != null, string.Format("{0} not found property: {1}", typeof(TIn), properties[i]));
                    }

                    Debug.Assert(p2.CanRead, string.Format("{0} not support get", p2.Name));
                    if (p2.PropertyType.Name == typeof(Nullable <>).Name)
                    {
                        var member = Expression.Property(param, p2);
                        memberBindings[i] = Expression.Bind(typeof(TOut).GetProperty(properties[i]).SetMethod,
                                                            Expression.Call(member, p2.PropertyType.GetMethod("GetValueOrDefault", Type.EmptyTypes)));
                    }
                    else
                    {
                        memberBindings[i] = Expression.Bind(typeof(TOut).GetProperty(properties[i]).SetMethod,
                                                            Expression.Property(param, p2.GetMethod));
                    }
                }

                var newExp     = Expression.New(ctor);
                var memberInit = Expression.MemberInit(newExp, memberBindings);

                var rs = Expression.Lambda <Func <TIn, TOut> >(memberInit, param);
                ExpressionCache.Add(key, rs);
                return(rs);
            }
            return(ExpressionCache[key] as Expression <Func <TIn, TOut> >);
        }
Beispiel #6
0
        static void AddToMap(string displayName, SourceType sourceType, params string[] sourceNames)
        {
            NameTypePair pair = new NameTypePair(displayName, sourceType);

            foreach (string source in sourceNames)
            {
                sourceMap.Add(source, pair);
            }

            sourceMap.Add(displayName, pair);
        }
Beispiel #7
0
        public static string GetMappingPropertyName <TSource, T>(string propertyName)
        {
            if (!string.IsNullOrEmpty(propertyName))
            {
                var key = new NameTypePair(propertyName, typeof(TSource), typeof(T));
                if (!MappingCache.ContainsKey(key))
                {
                    var p     = typeof(TSource).GetProperty(propertyName);
                    var attrs = (MappingAttribute[])p.GetCustomAttributes(typeof(MappingAttribute), false);
                    if (attrs.Length == 0)
                    {
                        throw new NotSupportedException(string.Format("property {0} not supported mapping", propertyName));
                    }

                    var          attr = attrs.FirstOrDefault(a => a.ToType == typeof(T)) ?? attrs[0];
                    PropertyInfo p2   = typeof(T).GetProperty(attr.To ?? p.Name);
                    Debug.Assert(p2 != null, string.Format("{0} not found property: {1}", typeof(T), attr.To));

                    MappingCache.Add(key, p2.Name);
                }
                return(MappingCache[key]);
            }
            return(null);
        }
Beispiel #8
0
        public static Expression <Func <T, TKey> > BuildOrderClause <T, TKey>(string propertyName) where T : class
        {
            var key = new NameTypePair(propertyName, typeof(T), typeof(TKey));

            if (!ExpressionCache.ContainsKey(key))
            {
                var        param  = Expression.Parameter(typeof(T), "p");
                var        pi     = typeof(T).GetProperty(propertyName);
                Expression member = null;
                if (pi.PropertyType.Name == typeof(Nullable <>).Name)
                {
                    var property = Expression.Property(param, pi.GetMethod);
                    member = Expression.Call(property, pi.PropertyType.GetMethod("GetValueOrDefault", Type.EmptyTypes));
                }
                else
                {
                    member = Expression.Property(param, pi.GetMethod);
                }
                var rs = Expression.Lambda <Func <T, TKey> >(member, param);
                ExpressionCache.Add(key, rs);
                return(rs);
            }
            return(ExpressionCache[key] as Expression <Func <T, TKey> >);
        }
Beispiel #9
0
        private CodeParameterDeclarationExpression GenerateParameterDeclaration(NameTypePair<CppType> param)
        {
            CodeParameterDeclarationExpression paramDecl;

            if (param.Type.ElementType == CppTypes.Typename)
                paramDecl = new CodeParameterDeclarationExpression (param.Type.ElementTypeName, param.Name);

            else {
                Type managedType = param.Type.ToManagedType ();
                CodeTypeReference typeRef = param.Type.TypeReference ();

                if (managedType != null && managedType.IsByRef)
                    paramDecl = new CodeParameterDeclarationExpression (managedType.GetElementType (), param.Name) { Direction = FieldDirection.Ref };

                else if (managedType != null && managedType != typeof (ICppObject))
                    paramDecl = new CodeParameterDeclarationExpression (managedType, param.Name);

                else if (typeRef != null)
                    paramDecl = new CodeParameterDeclarationExpression (typeRef, param.Name);

                else
                    return null;

            }

            return paramDecl;
        }
 public BasicPropertyDescriptor(NameTypePair pair, Type componentType)
     : base(pair.Name, new Attribute[] { })
 {
     this.propertyType = pair.Type;
     this.componentType = componentType;
 }