public override object Clone() { ParameterDef obj = (ParameterDef)base.Clone(); obj.Direction = Direction; return(obj); }
public static ParameterDef[] CreateParameterRefs(RaisDataType[] dts) { if (dts == null) { return(null); } ParameterDef[] ps = new ParameterDef[dts.Length]; for (int i = 0; i < dts.Length; i++) { ps[i] = new ParameterDef(dts[i]); } return(ps); }
private void getSignature(MethodInfo mi) { _retType = new RaisDataType(mi.ReturnType); ParameterInfo[] ps = mi.GetParameters(); if (ps != null && ps.Length > 0) { _parameters = new ParameterDef[ps.Length]; for (int i = 0; i < ps.Length; i++) { _parameters[i] = new ParameterDef(ps[i].ParameterType, ps[i].Name); } } }
public void OnReadFromXmlNode(IXmlCodeReader serializer, XmlNode node) { XmlNode methodXmlNode = null; _methodName = XmlSerialization.GetAttribute(node, XmlSerialization.XMLATT_NAME); _methodId = XmlSerialization.GetAttributeInt(node, XmlSerialization.XMLATT_ID); _methodOwnerObjectRef = (ObjectRef)XmlSerialization.ReadFromChildXmlNode(serializer, node, XmlSerialization.XML_METHODOWNER, new object[] { null }); if (_methodId != 0) { methodXmlNode = node.OwnerDocument.SelectSingleNode( XmlSerialization.FormatString("//{0}[@{1}='{2}']", XmlSerialization.XML_METHOD, XmlSerialization.XMLATT_ID, _methodId)); } if (methodXmlNode == null) { if (_methodId != 0) { throw new MathException("Method {0} not found", _methodId); } _retType = (RaisDataType)XmlSerialization.ReadFromChildXmlNode(serializer, node, XmlSerialization.XML_RETURNTYPE); XmlNodeList pNodes = node.SelectNodes(XmlSerialization.XML_PARAM); if (pNodes != null) { _parameters = new ParameterDef[pNodes.Count]; for (int i = 0; i < pNodes.Count; i++) { _parameters[i] = (ParameterDef)XmlSerialization.ReadFromXmlNode(serializer, pNodes[i]); } } } else { MethodType mt = new MethodType(); mt.OnReadFromXmlNode(serializer, methodXmlNode); _retType = mt.ReturnType; Parameter[] ps = mt.Parameters; if (ps != null && ps.Length > 0) { _parameters = new ParameterDef[ps.Length]; for (int i = 0; i < ps.Length; i++) { _parameters[i] = new ParameterDef(ps[i], ps[i].Name); } } } }
/// <summary> /// retrieve _retyrnType and parameters /// </summary> private void getSignature() { if (string.IsNullOrEmpty(_methodName)) { throw new MathException("Accessing getSignature with empty method name"); } if (_methodOwnerObjectRef == null) { throw new MathException("Accessing getSignature with null owner"); } if (_methodOwnerObjectRef.Type == ObjectRefType.Type) { Type t = _methodOwnerObjectRef.Value.LibType; MethodInfo mi = t.GetMethod(_methodName); if (mi == null) { throw new MathException("Accessing getSignature with invalid method name '{0}'", _methodName); } getSignature(mi); } else if (_methodOwnerObjectRef.Type == ObjectRefType.Field || _methodOwnerObjectRef.Type == ObjectRefType.Property) { if (_methodOwnerObjectRef.Owner.Type == ObjectRefType.XPath) { } else if (_methodOwnerObjectRef.Owner.Type == ObjectRefType.Type) { MethodInfo mi = null; Type t = _methodOwnerObjectRef.Owner.Value.LibType; if (_methodOwnerObjectRef.Type == ObjectRefType.Field) { FieldInfo fi = t.GetField(_methodOwnerObjectRef.Name); if (fi == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature for Field with invalid field name {0} for type {1}", _methodOwnerObjectRef.Name, t)); } mi = fi.FieldType.GetMethod(_methodName); if (mi == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature for Field with invalid method name {0} for field name {1} and type {2}", _methodName, _methodOwnerObjectRef.Name, t)); } } else if (_methodOwnerObjectRef.Type == ObjectRefType.Property) { PropertyInfo pi = t.GetProperty(_methodOwnerObjectRef.Name); if (pi == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature for Property with invalid property name {0} for type {1}", _methodOwnerObjectRef.Name, t)); } mi = pi.PropertyType.GetMethod(_methodName); if (mi == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature for Property with invalid method name {0} for Property name {1} and type {2}", _methodName, _methodOwnerObjectRef.Name, t)); } } getSignature(mi); } throw new MathException(XmlSerialization.FormatString("Accessing getSignature for Field. Owner type {0} not implemented", _methodOwnerObjectRef.Owner.Type)); } else if (_methodOwnerObjectRef.Type == ObjectRefType.XPath) { XmlDocument doc = _methodOwnerObjectRef.GetXmlDocument(); if (doc == null) { throw new MathException("Accessing getSignature with null document"); } XmlNode prj = XmlSerialization.GetProjectNode(doc); if (prj == null) { throw new MathException("Accessing getSignature with null project"); } XmlNode ownNode = prj.SelectSingleNode(_methodOwnerObjectRef.XPath); if (ownNode == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature with invalid xpath {0}", _methodOwnerObjectRef.XPath)); } if (_methodName == XmlSerialization.CONSTRUCTOR_METHOD) { throw new MathException("Accessing getSignature when the method is a constructor"); } XmlNode methodNode = ownNode.SelectSingleNode(XmlSerialization.FormatString("{0}[@{1}='{2}']", XmlSerialization.XML_METHOD, XmlSerialization.XMLATT_NAME, _methodName)); if (methodNode == null) { Type t = XmlSerialization.GetObjectLibType(ownNode); if (t == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature with valid xpath {0} but method name {1} not found and owner library type not found", _methodOwnerObjectRef.XPath, _methodName)); } MethodInfo mif = t.GetMethod(_methodName); if (mif == null) { throw new MathException(XmlSerialization.FormatString("Accessing getSignature with valid xpath {0} but method name {1} not found in owner library type {2}", _methodOwnerObjectRef.XPath, _methodName, t.Name)); } getSignature(mif); } else { MethodType mt = new MethodType(); mt.OnReadFromXmlNode(null, methodNode); _retType = mt.ReturnType; Parameter[] ps = mt.Parameters; if (ps != null && ps.Length > 0) { _parameters = new ParameterDef[ps.Length]; for (int i = 0; i < ps.Length; i++) { _parameters[i] = new ParameterDef(ps[i]); } } } } throw new MathException(XmlSerialization.FormatString("Accessing getSignature: type not implemented: {0}", _methodOwnerObjectRef.Type)); }