4 using System.Collections.Generic;
6 namespace DynVarManagement {
18 private XmlDocument document;
19 private string fileName;
23 #region ".dyn" XML constants: Extension, tags and attributes
32 public static readonly
string ClassTag =
"class";
37 public static readonly
string NameAtt =
"name";
45 get {
return fileName; }
59 this.fileName = fileName;
60 document =
new XmlDocument();
62 document.Load(fileName);
68 el.SetAttribute(
NameAtt, Path.GetFileNameWithoutExtension(fileName));
69 document.AppendChild(el);
81 if (document != null) {
92 XmlNode node = getOrCreateUntilParent(path);
98 (node as XmlElement).SetAttribute(
DynReturnAtt, true.ToString());
107 XmlNode node = getOrCreateUntilParent(path);
110 XmlNode varNode = node.SelectSingleNode(
112 node.RemoveChild(varNode);
116 XmlNode methodNode = node.SelectSingleNode(
118 XmlElement methodElement = methodNode as XmlElement;
119 if (methodElement != null)
120 methodElement.SetAttribute(
DynReturnAtt, false.ToString());
130 XmlNode node = getOrCreateUntilParent(path);
133 node = node.SelectSingleNode(
140 XmlElement methodElement = node as XmlElement;
141 return true.ToString().Equals(methodElement.GetAttribute(
DynReturnAtt));
149 #region Private methods
151 private XmlNode getOrCreateNode(XmlNode node,
string name,
string attribute,
string value) {
152 XmlNode newNode = node.SelectSingleNode(name +
"[@" + attribute +
" = '" + value +
"']");
153 if (newNode == null) {
154 newNode = document.CreateElement(name);
155 ((XmlElement)newNode).SetAttribute(attribute, value);
156 node.AppendChild(newNode);
161 private XmlNode getOrCreateUntilParent(VarPath path) {
162 XmlNode node = document.DocumentElement;
163 if (path.NamespaceName != null) {
166 if (path.ClassName != null) {
169 else if (path.InterfaceName != null) {
172 if (path.MethodName != null) {
223 get {
return this.ready; }
244 public void Load(
string name) {
245 this.fileName = name;
246 document =
new XmlDocument();
250 }
catch (Exception e) {
261 path.NamespaceName = ns;
262 path.ClassName = classId;
263 path.VarName = varId;
267 public bool SearchDynVar(
string ns,
string classId,
string methodId,
string varId) {
269 path.NamespaceName = ns;
270 path.ClassName = classId;
271 path.MethodName = methodId;
272 path.VarName = varId;
276 public bool SearchDynVar(
string ns,
string classId,
string methodId, List<int> blockList,
string varId) {
291 public bool SearchDynVar(
string ns,
string classOrInterfaceId,
string methodId,
bool isClassId) {
293 path.NamespaceName = ns;
295 path.ClassName = classOrInterfaceId;
297 path.InterfaceName = classOrInterfaceId;
298 path.MethodName = methodId;
306 #region class VarPath
311 private string namespaceName;
312 private string className;
313 private string interfaceName;
314 private string methodName;
317 private string varName;
323 get {
return namespaceName; }
324 set { namespaceName = value; }
327 get {
return className; }
328 set { className = value; }
331 get {
return interfaceName; }
332 set { interfaceName = value; }
335 get {
return methodName; }
336 set { methodName = value; }
346 get {
return varName; }
347 set { varName = value; }
static readonly string ClassTag
DynVarManager()
Constructor of DynVarManager
static readonly string NamespaceTag
bool LoadOrCreate(string fileName)
Attemps to load the specified ".dyn" file. If the file does not exist or an exception is thrown...
bool SearchDynVar(string ns, string classId, string methodId, string varId)
bool IsDynamic(VarPath path)
static readonly string DynVarFileExt
File extension
static readonly string MethodTag
New implementation of DynVarManagement: -Ignores "block" elements: not used anymore. -Provides wider interface: -Dynamic method return (dynreturn attribute in method elements) -Interface elements Includes set of old fields, properties and methods for retro-compatibility reasons.
bool Ready
Gets true if the xml document is loaded. Otherwise false.
static readonly string ApplicationTag
bool SearchDynVar(string ns, string classId, string varId)
static readonly string InterfaceTag
static readonly string DynVarTag
The parent class for all exceptions related to DynVars
void SetDynamic(VarPath path)
bool SearchDynVar(string ns, string classOrInterfaceId, string methodId, bool isClassId)
void SetStatic(VarPath path)
bool SearchDynVar(string ns, string classId, string methodId, List< int > blockList, string varId)
void Load(string name)
Loads the xml file associated to the source code file
static readonly string DynReturnAtt
static readonly string NameAtt