private void ScanForAttributeElements(XElement parent, List <CodeAnalyzer.CodeResourceRef> listCRR, string xmlFile) { foreach (var xeChild in parent.Descendants()) { foreach (var xa in xeChild.Attributes()) { if (ContainsResourceRef(xa.Value.ToString())) { System.Xml.IXmlLineInfo info = xa; CodeAnalyzer.CodeResourceRef crr = new CodeAnalyzer.CodeResourceRef(); crr.ClassFile = xmlFile; crr.CodeLineNumber = info.LineNumber.ToString(); CodeAnalyzer.ResourceRef rr = new CodeAnalyzer.ResourceRef(); rr.Category = "XML"; rr.RefId = xa.Value.Replace("@", "R.").Replace("/", "."); // @drawable/xxxx rr.RefName = "RefName"; crr.Ref = rr; listCRR.Add(crr); System.Diagnostics.Debug.WriteLine(xa.Name.LocalName + "=" + xa.Value.ToString() + " at " + info.LineNumber.ToString()); } } } }
private static string AddLineInfo(string message, System.Xml.IXmlLineInfo lineInfo) { if (lineInfo != null) { string[] lineArgs = new string[2]; lineArgs[0] = lineInfo.LineNumber.ToString(System.Globalization.CultureInfo.InvariantCulture); lineArgs[1] = lineInfo.LinePosition.ToString(System.Globalization.CultureInfo.InvariantCulture); message += " " + SR.Format(SR.Xml_ErrorPosition, lineArgs); } return(message); }
public void SetAndLoadSource(Uri value, string resourcePath, Assembly assembly, System.Xml.IXmlLineInfo lineInfo) { _source = value; if (_mergedWith != null) { throw new ArgumentException("Source can not be used with MergedWith"); } //this will return a type if the RD as an x:Class element, and codebehind var type = XamlResourceIdAttribute.GetTypeForPath(assembly, resourcePath); if (type != null) { _mergedInstance = s_instances.GetValue(type, (key) => (ResourceDictionary)Activator.CreateInstance(key)); } else { _mergedInstance = DependencyService.Get <IResourcesLoader>().CreateFromResource <ResourceDictionary>(resourcePath, assembly, lineInfo); } OnValuesChanged(_mergedInstance.ToArray()); }
public static Exception CreateReadElementContentAsException(this System.Xml.XmlReader reader, string methodName) { System.Xml.IXmlLineInfo lineInfo = reader as System.Xml.IXmlLineInfo; return(new InvalidOperationException(AddLineInfo(SR.Format(SR.Xml_InvalidReadElementContentAs, methodName, reader.NodeType), lineInfo))); }
private static bool ExamineFileForHCS(string strFile, CommandLine cmdLine) { var cultureInfo = new CultureInfo("en-US"); if (cmdLine.ExcludePaths.Any(exclude => cultureInfo.CompareInfo.IndexOf(strFile, exclude, CompareOptions.IgnoreCase) >= 0)) { return(false); } string strFilename = Path.GetFileName(strFile); bool bHardCodedStringsPresent = false; XDocument doc = XDocument.Load(strFile, LoadOptions.SetLineInfo); foreach (var node in doc.Descendants()) { string[] strAttributesLookingAt = { "Content", "Text", "Header", "ToolTip", "ContentString", "InputGestureText", "FalseText", "TrueText", "AccessText", "Tag", "Title", "FormattedInlineText", "StringFormat", "ErrorMessage", //CS special for ErrorMessageContainer "TitleString", //CS special for InformationPopup "TitleExtension" //CS special for QuizSectionHeaderControl }; foreach (string attributeName in strAttributesLookingAt) { var attContent = node.Attribute(attributeName); if (attContent == null) { continue; } string strValue = attContent.Value; if (!IsHardCodedValue(strValue)) { continue; } string strName = node.Name.LocalName; if (strName.EndsWith("KeyFrame")) { continue; } bHardCodedStringsPresent = true; _WarningCount++; string strFirstDirectory = FirstDirectory(strFile, cmdLine.ReposityPath); System.Xml.IXmlLineInfo info = attContent; Console.WriteLine(String.Format("{0}: [{1}|{2}:{3}] HCS \"{4}\"", _WarningCount, strFirstDirectory, strFilename, info.LineNumber, strValue)); } { string strName = node.Name.LocalName; string[] strTypesLookingAt = { "TextBlock", "TextBox", "Label", "RadioButton", "Button", "CheckBox", "ToolTip" }; if (!strTypesLookingAt.Any(s => strName == s)) { continue; } string strBody = node.Value; if (string.IsNullOrEmpty(strBody)) { continue; } if (strBody.StartsWith("<") || strBody.EndsWith(">")) { continue; } bHardCodedStringsPresent = true; _WarningCount++; string strFirstDirectory = FirstDirectory(strFile, cmdLine.ReposityPath); System.Xml.IXmlLineInfo info = node; info.HasLineInfo(); Console.WriteLine(String.Format("{0}: [{1}|{2}:{3}] HCS \"{4}\"", _WarningCount, strFirstDirectory, strFilename, info.LineNumber, strBody)); } } return(bHardCodedStringsPresent); }