Example #1
0
 /// <summary>
 /// Gets a generic type class instance given a certain MTA element
 /// </summary>
 public T GetElement <T>(MtaElement element) where T : Element
 {
     if (element == null)
     {
         return(null);
     }
     if (!MtaShared.IsElement(element))
     {
         return(null);
     }
     if (!elements.ContainsKey(element))
     {
         string mtaElementType = MtaShared.GetElementType(element);
         Type   elementType;
         try
         {
             elementType = defaultElementTypes[mtaElementType];
         } catch (KeyNotFoundException)
         {
             elementType = typeof(Element);
         }
         try
         {
             object instance = Activator.CreateInstance(elementType, element);
             return((T)instance);
         } catch (Exception)
         {
             return(null);
         }
     }
     return((T)elements[element]);
 }
Example #2
0
 /// <summary>
 /// Gets an element class instance given a certain MTA element
 /// </summary>
 public Element GetElement(MtaElement element)
 {
     if (element == null)
     {
         return(null);
     }
     if (!MtaShared.IsElement(element))
     {
         return(null);
     }
     if (!elements.ContainsKey(element))
     {
         try
         {
             string  mtaElementType = MtaShared.GetElementType(element);
             Element wrapperElement = elementHelper.InstantiateElement(mtaElementType, element);
             return(wrapperElement);
         }
         catch (Exception)
         {
             return(null);
         }
     }
     return(elements[element]);
 }