private string GetResourceString(string resourceString) { if (!string.IsNullOrEmpty(resourceString)) { var strResource = resourceString.Trim(); if (strResource.StartsWith("@", StringComparison.InvariantCultureIgnoreCase) && strResource.Contains(",")) { var lastIndex = strResource.LastIndexOf(','); try { var resFile = strResource.Substring(1, lastIndex - 1).Trim(); var strIndex = strResource.Substring(lastIndex + 1, strResource.Length - lastIndex - 1).Trim(); var resIndex = 0; if (Int32.TryParse(strIndex, out resIndex) && File.Exists(resFile)) { using (var resource = new StringLoader(resFile)) { var result = resource.Load(resIndex); return(result ?? resourceString); } } } catch (Exception) { //throw; } } } return(resourceString); }
public static string LoadStringFromDLLByPath(string StringPath) { if (StringPath.StartsWith(@"@")) { string[] aPathDetails = StringPath.Split(','); string DllString = string.Empty; if (aPathDetails.Length == 2) { string sDLLPath = aPathDetails[0].Replace(@"@", ""); if (!File.Exists(Environment.ExpandEnvironmentVariables(sDLLPath))) { return(string.Empty); } StringLoader sl = new StringLoader(sDLLPath); try { DllString = sl.Load(Convert.ToInt32(aPathDetails[1].Replace("-", ""))); } catch (Exception e) { Debug.WriteLine("Could not extract String from DLL Path " + StringPath + ". Error:" + e.Message); DllString = string.Empty; } sl.Dispose(); return(DllString); } return(string.Empty); } return(StringPath); }
public void StringLoader_Should_Just_Pass_Through() { var loader = new StringLoader(); const string template = "{{foo}}"; var loadedTemplate = loader.Load("{{foo}}"); Assert.Equal(template, loadedTemplate); }