/// <summary> /// Creates the <see cref="DataTypeBase"/> instance. /// </summary> /// <param name="elementNode">The element XML node.</param> /// <param name="proj">The current project.</param> /// <param name="targetCallStack">The current target call stack. Needed for accessing thread and target properties.</param> /// <returns>The created instance.</returns> /// <exception cref="System.ArgumentNullException">If elementNode or proj is <c>null</c>. /// </exception> /// <exception cref="BuildException">If no builder for the elment can be found. /// </exception> public static DataTypeBase CreateDataType(XmlNode elementNode, Project proj, TargetCallStack targetCallStack) { if (elementNode == null) { throw new ArgumentNullException("elementNode"); } if (proj == null) { throw new ArgumentNullException("proj"); } string dataTypeName = elementNode.Name; DataTypeBaseBuilder builder = DataTypeBuilders[dataTypeName]; if (builder == null) { Location location = proj.LocationMap.GetLocation(elementNode); throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1081"), dataTypeName), location); } DataTypeBase element = (DataTypeBase)builder.CreateDataTypeBase(); element.Project = proj; element.CallStack = targetCallStack; element.NamespaceManager = proj.NamespaceManager; // check whether the type (or its base class) is deprecated ObsoleteAttribute obsoleteAttribute = (ObsoleteAttribute) Attribute.GetCustomAttribute(element.GetType(), typeof(ObsoleteAttribute), true); if (obsoleteAttribute != null) { Location location = proj.LocationMap.GetLocation(elementNode); string obsoleteMessage = string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1085"), dataTypeName, obsoleteAttribute.Message); if (obsoleteAttribute.IsError) { throw new BuildException(obsoleteMessage, location); } else { if (targetCallStack.CurrentFrame != null && targetCallStack.CurrentFrame.TaskCallStack.CurrentFrame != null) { targetCallStack.CurrentFrame.TaskCallStack.CurrentFrame.Task.Log(Level.Warning, "{0} {1}", location, obsoleteMessage); } else { (proj as ITargetLogger).Log(Level.Warning, "{0} {1}", location, obsoleteMessage); } } } return(element); }