示例#1
0
 private static void SetProperties(XElement rootElement, Space space)
 {
     var properties = space.GetType().GetProperties();
     foreach (var prop in properties)
     {
         var attribute = prop.CustomAttributes.First(x => x.AttributeType == typeof (XmlElementAttribute));
         if (attribute != null)
         {
             var elementName = attribute.ConstructorArguments.First().Value as string;
             var element = rootElement.Element(elementName);
             if (element != null)
             {
                 if (element.Value.GetType() == prop.PropertyType)
                 {
                     prop.SetValue(space, element.Value);
                 }
                 else
                 {
                     throw new StrongTypingException();
                 }
             }
         }
     }
 }
示例#2
0
 public static Space FromElement(XElement element)
 {
     var space = new Space();
     SetProperties(element, space);
     return space;
 }