private bool GetElementInfo(IntermediateSerializer serializer, MemberInfo member, out ElementInfo info) { info = new ElementInfo(); // Are we ignoring this property? if (ReflectionHelpers.GetCustomAttribute(member, typeof(ContentSerializerIgnoreAttribute)) != null) return false; var prop = member as PropertyInfo; var field = member as FieldInfo; // If we can write or read from it we can skip it. if (prop != null && (!prop.CanWrite || !prop.CanRead)) return false; // Default the to member name as the element name. info.Name = member.Name; var attrib = ReflectionHelpers.GetCustomAttribute(member, typeof(ContentSerializerAttribute)) as ContentSerializerAttribute; if (attrib != null) { if (!string.IsNullOrEmpty(attrib.ElementName)) info.Name = attrib.ElementName; } else if (prop != null) { if (!ReflectionHelpers.PropertyIsPublic(prop)) return false; } else if (field != null) { if (!field.IsPublic) return false; } if (prop != null) { info.Serializer = serializer.GetTypeSerializer(prop.PropertyType); info.Setter = (o, v) => prop.SetValue(o, v, null); info.Getter = (o) => prop.GetValue(o, null); } else if (field != null) { info.Serializer = serializer.GetTypeSerializer(field.FieldType); info.Setter = field.SetValue; info.Getter = field.GetValue; } return true; }
public ElementInfo GetElementInfo(int[] int_array_tag, int n) { ElementInfo elementInfo = new ElementInfo(); XmlNode node = null; if(n == 1) { node = _activeXmlFile.GetGroup(int_array_tag[0]); } else if (n == 2) { node = _activeXmlFile.GetParam(int_array_tag[0], int_array_tag[1]); } if (node != null) { elementInfo = new ElementInfo() { Hint = _reader.GetAttributeValue(node, "HINT"), Level = _reader.GetAttributeValue(node, "LEVEL"), Name = _reader.GetAttributeValue(node, "NAME"), Type = _reader.GetAttributeValue(node, "TYPE"), Value = _reader.GetAttributeValue(node, "VALUE") }; } return elementInfo; }
public void WriteStartElement(string name) { // If we were writing the parent element, then we have to add a closing >. if (this.elementStack.Count > 0 && !this.CurrentElement.HasContent) { if (this.CurrentElement.HasAttributes) { this.writer.WriteLine(); // Pop the top element long enough to write the closing > with the correct indentation. object top = this.elementStack.Pop(); this.writer.Write(this.IndentSpaces); this.elementStack.Push(top); } this.writer.WriteLine(">"); this.CurrentElement.HasContent = true; } // Write the starting <elementName this.writer.Write("{0}<{1}", this.IndentSpaces, name); // Push the new element onto the stack. ElementInfo element = new ElementInfo(name); this.elementStack.Push(element); }
void ReadStartObject() { ElementInfo ei = new ElementInfo (next_element, "object"); elements.Push (ei); SkipWhitespaces (); if (PeekChar () == '"') { // it isn't premise: the object might be empty ReadChar (); string s = ReadStringLiteral (); if (s == "__type") { SkipWhitespaces (); Expect (':'); SkipWhitespaces (); Expect ('"'); current_runtime_type = ReadStringLiteral (); SkipWhitespaces (); ei.HasContent = true; } else next_object_content_name = s; } }
internal ElementInfo Pop() { ElementInfo ei = (ElementInfo)_ElementStack.Pop(); if (ei == null) { goto cleanup; } _NsMgr.PopScope(); _LastElementInfo = (ElementInfo) _ElementStack.Peek(); if (_LastElementInfo != null) { _XmlLang = _LastElementInfo._XmlLang; _XmlSpace = _LastElementInfo._XmlSpace; } else { _XmlSpace = XmlSpace.None; _XmlLang = String.Empty; } cleanup: return ei; }
internal void Push(String nameWPrefix, String localName, String prefix, String ns, int nameColonPos) { ElementInfo ei = (ElementInfo)_ElementStack.Push(); if (ei == null) { ei = new ElementInfo(); _ElementStack[_ElementStack.Length-1] = ei; } ei._NameWPrefix = nameWPrefix; ei._LocalName = localName; ei._Prefix = prefix; ei._NS = ns; ei._NameColonPos = nameColonPos; ei._LineNumber = _Scanner.LineNum; ei._XmlSpace = _XmlSpace; ei._XmlLang = _XmlLang; ei._Scanner = _Scanner; _LastElementInfo = ei; }
// // Summary: // When overridden in a derived class, writes the specified start tag and associates // it with the given namespace and prefix. // // Parameters: // localName: // The local name of the element. // // prefix: // The namespace prefix of the element. // // ns: // The namespace URI to associate with the element. // // Exceptions: // System.InvalidOperationException: // The writer is closed. public string WriteStartElement(string prefix, string localName, string ns) { if (_WriteState == WriteState.Attribute) throw new InvalidOperationException("writer is closed"); if (prefix == "xmlns") throw new ArgumentException("Prefix \"xmlns\" is reserved for use by XML."); if (localName == null || localName.Length == 0) throw new ArgumentException("The empty string '' is not a valid local name."); // Check to see if a started attribute need finished if (_WriteState == WriteState.Attribute) this.WriteEndAttribute(); string localPrefix = ""; string localNS = ""; string childPrefix = ""; if (prefix != null && prefix.Length == 0) prefix = null; // if prefix == null and ns == null, only localName will write // if prefix == null and ns != null, prefix is set to xmlns and ns will be writen // if prefix != null && ns == null, use prefix if (prefix != null && ns != null) { localPrefix = prefix + ":"; localNS = " xmlns:" + prefix + "=" + "\"" + ns + "\""; childPrefix = prefix; } else if (prefix != null && ns == null) localPrefix = prefix + ":"; else if (prefix == null && ns != null) { if (_ElementStack.Count > 0) { if (((ElementInfo)_ElementStack.Peek()).NameSpaceName != ns) { childPrefix = "b" + _autoPrefixIndex++; localNS = " xmlns:" + childPrefix + "=" + "\"" + ns + "\""; } else { prefix = ((ElementInfo)_ElementStack.Peek()).ChildNSPrefix; if (prefix != null && prefix != "") { localPrefix = prefix + ":"; childPrefix = prefix; } } } else { localNS = " xmlns" + "=" + "\"" + ns + "\""; } } else if (_ElementStack.Count > 0) { prefix = ((ElementInfo)_ElementStack.Peek()).ChildNSPrefix; if (prefix != null && prefix != "") { localPrefix = prefix + ":"; } else { prefix = null; } } // Check to see if we need to close a previous start tag if (_ElementStack.Count > 0) if (((ElementInfo)_ElementStack.Peek()).State == WriteState.Element) this.WriteRaw(">"); // Write the element this.WriteRaw("<" + localPrefix + localName + localNS); // Create a new Element and Push the element onto the ElementStack ElementInfo currentElement = new ElementInfo(); currentElement.Name = localName; currentElement.NSPrefix = prefix; currentElement.ChildNSPrefix = childPrefix; currentElement.NameSpaceName = ns; currentElement.IsEmpty = true; // Anytime a new Element is added the previous must have its last known state and IsEmpty // state updated to reflect we are adding Content and the element is no longer Empty if (_ElementStack.Count > 0) { ElementInfo ei = (ElementInfo)_ElementStack.Pop(); ei.State = _WriteState = WriteState.Content; // Signal that this element has content ei.IsEmpty = false; _ElementStack.Push(ei); } // Update the local WriteState and new Element State currentElement.State = _WriteState = WriteState.Element; // Push the new element onto the stack _ElementStack.Push(currentElement); return prefix; }