/// <summary> /// 根据名称获取客户类型,如果列表里不存在,创建空客户类型,放到列表中。 /// </summary> /// <param name="name">类型名称</param> /// <returns>客户类型</returns> public CustomType GetType(string name) { CustomType type; if (!_types.TryGetValue(name, out type)) { type = new CustomType(GetType()); _types[name] = type; } return type; }
/// <summary> /// 设置对象类型,从CustomTypes中找到类型的对象,可以调用这个方法设置对象类型。 /// </summary> /// <param name="type"></param> public void SetCustomType(CustomType type) { _ctype = type; }
/// <summary> /// 开始到后台加载类型信息 /// </summary> public void Load() { Uri uri = new Uri(WebClientInfo.BaseAddress + Path); WebClient client = new WebClient(); client.OpenReadCompleted += (o, a) => { if (a.Error == null) { JsonObject types = JsonValue.Load(a.Result) as JsonObject; //设置所有动态类型的属性 foreach (string type in types.Keys) { CustomType cType = new CustomType(typeof(GeneralObject)); JsonObject attrs = (JsonObject)types[type]; foreach (string attr in attrs.Keys) { string attrType = attrs[attr]; cType.AddProperty(attr, attrType.ToType()); } //把类型放到类型表中 _types[type] = cType; } State = State.Loaded; } else { State = State.LoadError; Error = a.Error.GetMessage(); } IsBusy = false; //通知加载完成 OnCompleted(a); OnDataLoaded(a); }; IsBusy = true; OnLoading(); State = State.StartLoad; client.OpenReadAsync(uri); }
/// <summary> /// 获取客户类型,如果获取时,不存在,就建立一个,这样,每个没有实体类型的对象就做到了一个对象一个类。 /// </summary> /// <returns>获取的对象类型</returns> public Type GetCustomType() { if (_ctype == null) { _ctype = new CustomType(GetType()); } return _ctype; }