PDA

View Full Version : سوال: استفاده از مقادیر ذخیره شد ه در فایل resource.resx دروب



article
جمعه 07 تیر 1392, 22:23 عصر
سلام به همه دوستان
امیدوارم حالتون خوب باشه .
من یه مشکل با فایلای ریسورس دارم.اونم اینکه که ،من میخوام مقادیر نگهداری شده در فایل ریسورس مثلا بنام add.ascx.resx رو بخونم اما هر کاری میکنم نمیتونم از متد زیر استفاده کردم که نمیتونه فایل اسمبلی رو پیدا کنه
public static ResourceManager CreateLocalResourceManager(string virtualPath)
{
var virtualPathType = typeof(BuildManager).Assembly.GetType("System.Web.VirtualPath", true);
var virtualPathInstance = Activator.CreateInstance(virtualPathType, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { virtualPath }, CultureInfo.InvariantCulture);
var buildResultCompiledAssemblyType = typeof(BuildManager).Assembly.GetType("System.Web.Compilation.BuildResultCompiledAssembly", true);
var propertyResultAssembly = buildResultCompiledAssemblyType.GetProperty("ResultAssembly", BindingFlags.NonPublic | BindingFlags.Instance);
var methodGetLocalResourcesAssemblyName = typeof(BuildManager).GetMethod("GetLocalResourcesAssemblyName", BindingFlags.NonPublic | BindingFlags.Static);
var methodGetBuildResultFromCache = typeof(BuildManager).GetMethod("GetBuildResultFromCache", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(string) }, null);

var fileNameProperty = virtualPathType.GetProperty("FileName");
var virtualPathFileName = (string)fileNameProperty.GetValue(virtualPathInsta nce, null);

var parentProperty = virtualPathType.GetProperty("Parent");
var virtualPathParent = parentProperty.GetValue(virtualPathInstance, null);

var localResourceAssemblyName = (string)methodGetLocalResourcesAssemblyName.Invoke (null, new object[] { virtualPathParent });
var buildResultFromCache = methodGetBuildResultFromCache.Invoke(null, new object[] { localResourceAssemblyName });
Assembly localResourceAssembly = null;
if (buildResultFromCache != null)
localResourceAssembly = (Assembly)propertyResultAssembly.GetValue(buildRes ultFromCache, null);

if (localResourceAssembly == null)
throw new InvalidOperationException("Unable to find the matching resource file.");

return new ResourceManager(virtualPathFileName, AppResourcesAssembly) { IgnoreCase = true };
}
#endregion

public static Assembly AppResourcesAssembly
{
get
{
Type buildManagerType = typeof(BuildManager);
PropertyInfo property = buildManagerType.GetProperty("AppResourcesAssembly",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField);
return (Assembly)property.GetValue(null, null);
}
}
برای فراخوانیم از متد زیر استفاده میکنم:
var manager = Localization.CreateLocalResourceManager("~/Handball Database/RefereeUCController/AddArea.ascx"); ;
Label1.Text = manager.GetString("Title.Text");
اگه کسی هست که میتونه منو راهنمایی کنه ممنون میشم.
خیلی فوری

saeed_sho
شنبه 08 تیر 1392, 17:58 عصر
من میخوام در فایل ریسورس هم بخونم هم بنویسم و هم حذف کنم اگه به نتیجه رسیدم توی این تاپیک میذارم

article
سه شنبه 11 تیر 1392, 22:03 عصر
ممنون خیلی احتیاج دارم