Esempio n. 1
0
File: Type.cs Progetto: e2wugui/zeze
        public static Type Compile(ModuleSpace space, String name, String key, String value)
        {
            Type type = null;

            if (Types.TryGetValue(name, out type))
            {
                return(type.Compile(space, key, value));
            }

            if (false == Program.IsFullName(name))
            {
                name = space.Path(".", name);
                if (Types.TryGetValue(name, out type))
                {
                    return(type.Compile(space, key, value));
                }
            }

            throw new Exception("type NOT FOUND! '" + name + "'" + key + "." + value);
        }
Esempio n. 2
0
        private TypeList(global::Zeze.Gen.ModuleSpace space, String key, String value)
        {
            if (key != null && key.Length > 0)
            {
                throw new Exception(Name + " type does not need a key. " + key);
            }

            ValueType = Type.Compile(space, value, null, null);
            //if (ValueType is TypeBinary)
            //	throw new Exception(Name + " Error : value type is binary.");
            if (ValueType is TypeDynamic)
            {
                throw new Exception(Name + " Error : value type is dynamic.");
            }
        }
Esempio n. 3
0
        // value=BeanName[:SpecialTypeId],BeanName2[:SpecialTypeId2]
        // 如果指定特别的TypeId,必须全部都指定。虽然部分指定也可以处理,感觉这样不大好。
        private TypeDynamic(ModuleSpace space, string value)
        {
            foreach (var beanWithSpecialTypeId in value.Split(','))
            {
                if (beanWithSpecialTypeId.Length == 0) // empty
                {
                    continue;
                }
                var beanWithSpecialTypeIdArray = beanWithSpecialTypeId.Split(':');
                if (beanWithSpecialTypeIdArray.Length == 0)
                {
                    continue;
                }
                Type type = Type.Compile(space, beanWithSpecialTypeIdArray[0], null, null);
                if (false == type.IsNormalBean)
                {
                    throw new Exception("dynamic only support normal bean");
                }
                Bean bean          = type as Bean;
                long specialTypeId = bean.TypeId; // default
                if (beanWithSpecialTypeIdArray.Length > 1)
                {
                    SpecialCount++;
                    specialTypeId = long.Parse(beanWithSpecialTypeIdArray[1]);
                    if (specialTypeId <= 0)
                    {
                        throw new Exception("SpecialTypeId <= 0 is reserved");
                    }
                }
                RealBeans.Add(specialTypeId, bean);
            }

            if (SpecialCount == 0) // 没有配置特别的TypeId,全部使用Bean本身的TypeId。
            {
                return;
            }

            if (RealBeans.Count == 0) // 动态类型没有配置任何具体的Bean。允许。
            {
                return;
            }

            if (SpecialCount != RealBeans.Count)
            {
                throw new Exception("dynamic setup special TypeId,But Not All.");
            }
        }
Esempio n. 4
0
        protected void _compile(ModuleSpace space, String key, String value)
        {
            if (key != null && key.Length > 0)
            {
                throw new Exception(Name + " type does not need a key. " + key);
            }

            ValueType = Type.Compile(space, value, null, null);
            if (ValueType is TypeBinary)
            {
                throw new Exception(Name + " Error : value type is binary.");
            }
            if (ValueType is TypeDynamic)
            {
                throw new Exception(Name + " Error : value type is dynamic.");
            }
        }
Esempio n. 5
0
        public override void Depends(HashSet <Type> includes)
        {
            if (includes.Add(this))
            {
                foreach (Variable var in Variables)
                {
                    var.VariableType.Depends(includes);

                    // 常量初始化引用到的Bean也加入depends中。 BeanName.ConstStaticVarName
                    //
                    String[] initial      = var.Initial.Split('.');
                    String   beanNameMabe = "";
                    for (int i = 0; i < initial.Length - 1; ++i)
                    {
                        if (i > 0)
                        {
                            beanNameMabe += '.';
                        }
                        beanNameMabe += initial[i];
                    }
                    if (beanNameMabe.Length == 0)
                    {
                        continue;
                    }
                    try
                    {
                        Type type = Type.Compile(Space, beanNameMabe);
                        if (null != type)
                        {
                            includes.Add(type);                             // type.depends(type); 肯定是 Bean,不需要递归包含。
                        }
                    }
                    catch (Exception)
                    {
                        // skip depends error
                    }
                }
            }
        }
Esempio n. 6
0
        private TypeMap(global::Zeze.Gen.ModuleSpace space, String key, String value)
        {
            if (key.Length == 0)
            {
                throw new Exception("map type need a key");
            }
            if (value.Length == 0)
            {
                throw new Exception("map type need a value");
            }

            KeyType = Type.Compile(space, key, null, null);
            if (!KeyType.IsKeyable)
            {
                throw new Exception("map key need a keyable type");
            }
            ValueType = Type.Compile(space, value, null, null);
            //if (ValueType is TypeBinary)
            //	throw new Exception(Name + " Error : value type is binary.");
            if (ValueType is TypeDynamic)
            {
                throw new Exception(Name + " Error : value type is dynamic.");
            }
        }