Hi all,
I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line. Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
.. in it. I think the line should read 'text1 = property.Name....'.
The code is from the ProfileBuilder class in the System.Web.Compilation
class.
private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);
}
if (!assemblyBuilder.CodeDomProvider.IsValidIdentifie r(text1))
{
throw new
ConfigurationErrorsException(SR.GetString("Profile _bad_name"),
property.FileName, property.LineNumber);
}
CodeMemberProperty property1 = new CodeMemberProperty();
property1.Name = text1;
property1.Attributes = MemberAttributes.Public;
property1.HasGet = true;
property1.Type = property.PropertyCodeRefType;
CodeMethodInvokeExpression expression1 = new
CodeMethodInvokeExpression();
expression1.Method.TargetObject = new
CodeThisReferenceExpression();
expression1.Method.MethodName = "GetPropertyValue";
expression1.Parameters.Add(new CodePrimitiveExpression(text1));
CodeMethodReturnStatement statement1 = new
CodeMethodReturnStatement(new CodeCastExpression(property1.Type,
expression1));
property1.GetStatements.Add(statement1);
if (!property.IsReadOnly)
{
CodeMethodInvokeExpression expression2 = new
CodeMethodInvokeExpression();
expression2.Method.TargetObject = new
CodeThisReferenceExpression();
expression2.Method.MethodName = "SetPropertyValue";
expression2.Parameters.Add(new
CodePrimitiveExpression(text1));
expression2.Parameters.Add(new
CodePropertySetValueReferenceExpression());
property1.HasSet = true;
property1.SetStatements.Add(expression2);
}
type.Members.Add(property1);
}
Your thoughts would be welcome.
Ryan