System.Web.Compilation.TemplateControlCompiler.AssignPropertyFromResources C# (CSharp) Method

AssignPropertyFromResources() static private method

static private AssignPropertyFromResources ( ControlBuilder builder, MemberInfo mi, string attvalue ) : void
builder System.Web.UI.ControlBuilder
mi System.Reflection.MemberInfo
attvalue string
return void
		void AssignPropertyFromResources (ControlBuilder builder, MemberInfo mi, string attvalue)
		{
			bool isProperty = mi.MemberType == MemberTypes.Property;
			bool isField = !isProperty && (mi.MemberType == MemberTypes.Field);

			if (!isProperty && !isField || !IsWritablePropertyOrField (mi))
				return;			

			object[] attrs = mi.GetCustomAttributes (typeof (LocalizableAttribute), true);
			if (attrs != null && attrs.Length > 0 && !((LocalizableAttribute)attrs [0]).IsLocalizable)
				return;
			
			string memberName = mi.Name;
			string resname = String.Concat (attvalue, ".", memberName);

			if (!ResourceProviderHasObject (resname))
				return;
			
			// __ctrl.Text = System.Convert.ToString(HttpContext.GetLocalResourceObject("ButtonResource1.Text"));
			string inputFile = parser.InputFile;
			string physPath = HttpContext.Current.Request.PhysicalApplicationPath;
	
			if (StrUtils.StartsWith (inputFile, physPath))
				inputFile = parser.InputFile.Substring (physPath.Length - 1);
			else
				return;

			char dsc = System.IO.Path.DirectorySeparatorChar;
			if (dsc != '/')
				inputFile = inputFile.Replace (dsc, '/');

			object obj = HttpContext.GetLocalResourceObject (inputFile, resname);
			if (obj == null)
				return;

			if (!isProperty && !isField)
				return; // an "impossible" case
			
			CodeAssignStatement assign = new CodeAssignStatement ();
			
			assign.Left = new CodePropertyReferenceExpression (ctrlVar, memberName);
			assign.Right = ResourceExpressionBuilder.CreateGetLocalResourceObject (mi, resname);
			
			builder.Method.Statements.Add (AddLinePragma (assign, builder));
		}
TemplateControlCompiler