public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { FunctionForControls mf = value as FunctionForControls; if (mf != null && destinationType == typeof(InstanceDescriptor)) { MethodInfo ci = value.GetType().GetMethod("Parse", new Type[] { typeof(string), typeof(Type), typeof(string) }); return(new InstanceDescriptor(ci, new object[] { mf.ToString(), mf.View.DefineClassType, mf.View.Name })); } else { return(base.ConvertTo(context, culture, value, destinationType)); } }
/// <summary> /// Разбор /// </summary> /// <param name="value"></param> /// <param name="v"></param> /// <returns></returns> static public FunctionForControls Parse(string value, ICSSoft.STORMNET.View v) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(value); ICSSoft.STORMNET.FunctionalLanguage.FunctionalLanguageDef lang = ICSSoft.STORMNET.FunctionalLanguage.SQLWhere.SQLWhereLanguageDef.LanguageDef; ICSSoft.STORMNET.FunctionalLanguage.VariableDef[] vars; ArrayList arvars = new ArrayList(); arvars.Add(new ICSSoft.STORMNET.FunctionalLanguage.VariableDef((lang as ICSSoft.STORMNET.FunctionalLanguage.SQLWhere.SQLWhereLanguageDef).GuidType, "STORMMainObjectKey")); foreach (ICSSoft.STORMNET.PropertyInView piv in v.Properties) { System.Type propType = ICSSoft.STORMNET.Information.GetPropertyType(v.DefineClassType, piv.Name); try { ICSSoft.STORMNET.FunctionalLanguage.ObjectType t = lang.GetObjectTypeForNetType(propType); if (t != null) { arvars.Add(new ICSSoft.STORMNET.FunctionalLanguage.VariableDef(t, piv.Name, piv.Caption)); } } catch { } } vars = (ICSSoft.STORMNET.FunctionalLanguage.VariableDef[])arvars.ToArray(typeof(ICSSoft.STORMNET.FunctionalLanguage.VariableDef)); ICSSoft.STORMNET.FunctionalLanguage.Function fnc = FromXMLElements((System.Xml.XmlElement)doc.FirstChild, lang, vars); FunctionForControls res = null; if (fnc == null) { res = new FunctionForControls(v, fnc); } else { res = new FunctionForControls(v, fnc.FunctionDef, fnc.Parameters.ToArray()); } try { res.Name = ((System.Xml.XmlElement)doc.FirstChild).GetAttribute("___Name"); } catch { } return(res); }