private WebBaseElement GetElementInstance(FieldInfo field, string driverName) { var type = field.GetType(); var fieldName = field.Name; var newLocator = GetNewLocator(field); try { WebBaseElement instance = null; if (type == typeof(IList)) { var elementClass = type.GetGenericArguments()[0]; /*if (elementClass.IsInterfaceOf) * elementClass = MapInterfaceToElement.ClassFromInterface(type);*/ if (elementClass != null) { instance = (WebBaseElement)Activator.CreateInstance(typeof(Elements <>).MakeGenericType(elementClass)); } } else { if (type.IsInterface) { type = MapInterfaceToElement.ClassFromInterface(type); } if (type != null) { instance = (WebBaseElement)Activator.CreateInstance(type); instance.WebAvatar.ByLocator = newLocator; } } if (instance == null) { throw Exception("Unknown interface: " + type + ". Add relation interface -> class in VIElement.InterfaceTypeMap"); } instance.Avatar.DriverName = driverName; return(instance); } catch (Exception ex) { throw Exception("Error in getElementInstance for field '%s' with type '%s'", fieldName, type.Name + ex.Message.FromNewLine()); } }
private WebBaseElement GetElementInstance(FieldInfo field, string driverName) { var type = field.FieldType; var fieldName = field.Name; var newLocator = GetNewLocator(field); return(ActionWithException(() => { WebBaseElement instance = null; if (type == typeof(List)) { throw Exception($"Can't init element {fieldName} with type 'List<>'. Please use 'IList<>' or 'Elements<>' instead"); } if (typeof(IList).IsAssignableFrom(type)) { var elementClass = type.GetGenericArguments()[0]; if (elementClass != null) { instance = (WebBaseElement)Activator.CreateInstance(typeof(Elements <>) .MakeGenericType(elementClass)); } } else { if (type.IsInterface) { type = MapInterfaceToElement.ClassFromInterface(type); } if (type != null) { instance = (WebBaseElement)Activator.CreateInstance(type); instance.WebAvatar.ByLocator = newLocator; } } if (instance == null) { throw Exception("Unknown interface: " + type + ". Add relation interface -> class in VIElement.InterfaceTypeMap"); } instance.Avatar.DriverName = driverName; return instance; }, ex => $"Error in getElementInstance for field {fieldName}' with type '{type.Name + ex.FromNewLine()}'")); }