/// <summary> /// 构造函数 /// </summary> /// <param name="scriptFunction"></param> public ScriptAPI(string baseUrl, ScriptFunction scriptFunction) { this.Url = baseUrl; this.ScriptFunction = scriptFunction; MethodInfo minfo = scriptFunction.GetMethodInfo(); this.Id = minfo.DeclaringType.FullName + minfo.Name; ScriptMethAttribute = minfo.GetCustomAttribute(typeof(ScriptMethAttribute), false) as ScriptMethAttribute; if (ScriptMethAttribute.Name.Equals("")) { ScriptMethAttribute.Name = minfo.Name; } ScriptMethAttribute.Url = this.Url; }
/// <summary> /// 在tdfather子内容中添加一个对象的方法作为itembox /// </summary> /// <param name="tdfather"></param> /// <param name="obj"></param> /// <param name="medthname"></param> public static IItemBox AddMeodthToItemBox <IBox, IParat>(TreeData tdfather, ScriptFunction sf) { string medthname = sf.GetMethodInfo().Name; IBox box = (IBox)Activator.CreateInstance(typeof(IBox)); IItemBox opitem = box as IItemBox; if (opitem == null) { throw new Exception("IBox, 不是一个有效的实现于IItemBox的类"); } opitem.BoxType = ItemBoxEnum.FUNCTION; MethodInfo minfo = sf.GetMethodInfo(); if (minfo != null) { ScriptMethAttribute attribute = minfo.GetCustomAttribute(typeof(ScriptMethAttribute), false) as ScriptMethAttribute; if (attribute != null) { if (attribute.Name != "") { opitem.Name = attribute.Name; } else { opitem.Name = medthname; } opitem.BoxType = attribute.ItemBoxEnum; opitem.TipText = attribute.Describe; if (attribute.InputData.Count > 0) { foreach (var item in attribute.InputData) { IParat ipa = (IParat)Activator.CreateInstance(typeof(IParat)); IParatItem op = ipa as IParatItem; //ParatItem op = new ParatItem(item.Name, LogLib.TClassOption.GetEnumTypeByString<ParaItemEnum>(item.Type), item.EnumDatas) op.Name = item.Name; op.PIEnum = LogLib.TClassOption.GetEnumTypeByString <ParaItemEnum>(item.Type); op.EnumDatas = item.EnumDatas; op.Value = item.DefultValue; opitem.AddInput(op); op.TipText = item.TipText; } } if (attribute.OutputData.Count > 0) { foreach (var item in attribute.OutputData) { IParat ipa = (IParat)Activator.CreateInstance(typeof(IParat)); IParatItem op = ipa as IParatItem; op.Name = item.Name; op.PIEnum = LogLib.TClassOption.GetEnumTypeByString <ParaItemEnum>(item.Type); op.EnumDatas = item.EnumDatas; op.Value = item.DefultValue; opitem.AddOutput(op); op.TipText = item.TipText; } } tdfather.Children.Add(new TreeData(opitem)); } } //opitem = null; return(opitem); }