示例#1
0
        public void visit_member_initializer(MemberInitializer init, DataType type)
        {
            init.symbol_reference = symbol_lookup_inherited(type.data_type, init.name);
            if (!(init.symbol_reference is Field || init.symbol_reference is Property))
            {
                init.error = true;
                Report.error(init.source_reference, "Invalid member `%s' in `%s'".printf(init.name, type.data_type.get_full_name()));
                return;
            }
            if (init.symbol_reference.access != SymbolAccessibility.PUBLIC)
            {
                init.error = true;
                Report.error(init.source_reference, "Access to private member `%s' denied".printf(init.symbol_reference.get_full_name()));
                return;
            }
            DataType member_type = null;

            if (init.symbol_reference is Field)
            {
                var f = (Field)init.symbol_reference;
                member_type = f.variable_type;
            }
            else if (init.symbol_reference is Property)
            {
                var prop = (Property)init.symbol_reference;
                member_type = prop.property_type;
                if (prop.set_accessor == null || !prop.set_accessor.writable)
                {
                    init.error = true;
                    Report.error(init.source_reference, "Property `%s' is read-only".printf(prop.get_full_name()));
                    return;
                }
            }

            init.initializer.formal_target_type = member_type;
            init.initializer.target_type        = init.initializer.formal_target_type.get_actual_type(type, null, init);

            init.check(context);

            if (init.initializer.value_type == null || !init.initializer.value_type.compatible(init.initializer.target_type))
            {
                init.error = true;
                Report.error(init.source_reference, "Invalid type for member `%s'".printf(init.name));
                return;
            }
        }
示例#2
0
文件: DbContext.cs 项目: yinmin/elinq
        private void InitializeDbSets()
        {
            var type = GetType();

            if (type == typeof(InternalDbContext))
            {
                return;
            }

            List <MemberInitializer> items;

            if (!MemberInitializersGroup.TryGetValue(DbConfiguration.Name, out items))
            {
                items = new List <MemberInitializer>();
                foreach (var item in type.GetFields().Where(p => typeof(IDbSet).IsAssignableFrom(p.FieldType)))
                {
                    var initiazer = new MemberInitializer();
                    initiazer.EntityModel     = DbConfiguration.GetMapping(ReflectionHelper.GetElementType(item.FieldType));
                    initiazer.Setter          = item.GetSetter();
                    initiazer.DbSetConstrctor = typeof(DbSet <>).MakeGenericType(initiazer.EntityModel.EntityType).GetConstructors().FirstOrDefault().GetCreator();
                    items.Add(initiazer);
                }
                foreach (var item in type.GetProperties().Where(p => typeof(IDbSet).IsAssignableFrom(p.PropertyType)).Where(p => p.CanWrite))
                {
                    var initiazer = new MemberInitializer();
                    initiazer.EntityModel     = DbConfiguration.GetMapping(ReflectionHelper.GetElementType(item.PropertyType));
                    initiazer.Setter          = item.GetSetter();
                    initiazer.DbSetConstrctor = typeof(DbSet <>).MakeGenericType(initiazer.EntityModel.EntityType).GetConstructors().FirstOrDefault().GetCreator();
                    items.Add(initiazer);
                }
                lock (MemberInitializersGroup)
                    MemberInitializersGroup[DbConfiguration.Name] = items;
            }

            foreach (var item in items)
            {
                item.Init(this);
            }
        }
 /// <summary>
 /// Appends the specified member initializer to the object initializer.
 ///
 /// <param name="init">a member initializer</param>
 /// </summary>
 public void add_member_initializer(MemberInitializer init)
 {
     object_initializer.Add(init);
     init.parent_node = this;
 }
示例#4
0
            protected internal override MemberInitializer VisitMemberInitializer(MemberInitializer node)
            {
                Visited = true;

                return(base.VisitMemberInitializer(node));
            }
 NewObjectExpression(Constructor<?> constructor, Expression[] arguments, MemberInitializer[] initializers)
     : super(ExpressionKind.NewObject, constructor.getDeclaringClass()) {