Exemple #1
0
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
 private static void AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName)
 {
     foreach (ProfilePropertySettings pps in propertyCollection)
     {
         ProfileNameTypeStruct prop = new ProfileNameTypeStruct();
         if (groupName != null)
         {
             prop.Name = groupName + "." + pps.Name;
         }
         else
         {
             prop.Name = pps.Name;
         }
         Type t = pps.TypeInternal;
         if (t == null)
         {
             t = ResolvePropertyTypeForCommonTypes(pps.Type.ToLower(System.Globalization.CultureInfo.InvariantCulture));
         }
         if (t == null)
         {
             t = BuildManager.GetType(pps.Type, false);
         }
         if (t == null)
         {
             prop.PropertyCodeRefType = new CodeTypeReference(pps.Type);
         }
         else
         {
             prop.PropertyCodeRefType = new CodeTypeReference(t);
         }
         prop.PropertyType = t;
         pps.TypeInternal  = t;
         prop.IsReadOnly   = pps.ReadOnly;
         prop.LineNumber   = pps.ElementInformation.Properties["name"].LineNumber;
         prop.FileName     = pps.ElementInformation.Properties["name"].Source;
         ht.Add(prop.Name, prop);
     }
 }
 private static void AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName)
 {
     foreach (ProfilePropertySettings settings in propertyCollection)
     {
         ProfileNameTypeStruct struct2 = new ProfileNameTypeStruct();
         if (groupName != null)
         {
             struct2.Name = groupName + "." + settings.Name;
         }
         else
         {
             struct2.Name = settings.Name;
         }
         Type typeInternal = settings.TypeInternal;
         if (typeInternal == null)
         {
             typeInternal = ResolvePropertyTypeForCommonTypes(settings.Type.ToLower(CultureInfo.InvariantCulture));
         }
         if (typeInternal == null)
         {
             typeInternal = BuildManager.GetType(settings.Type, false);
         }
         if (typeInternal == null)
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(settings.Type);
         }
         else
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(typeInternal);
         }
         struct2.PropertyType = typeInternal;
         settings.TypeInternal = typeInternal;
         struct2.IsReadOnly = settings.ReadOnly;
         struct2.LineNumber = settings.ElementInformation.Properties["name"].LineNumber;
         struct2.FileName = settings.ElementInformation.Properties["name"].Source;
         ht.Add(struct2.Name, struct2);
     }
 }
Exemple #3
0
 private static void AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName)
 {
     foreach (ProfilePropertySettings settings in propertyCollection)
     {
         ProfileNameTypeStruct struct2 = new ProfileNameTypeStruct();
         if (groupName != null)
         {
             struct2.Name = groupName + "." + settings.Name;
         }
         else
         {
             struct2.Name = settings.Name;
         }
         Type typeInternal = settings.TypeInternal;
         if (typeInternal == null)
         {
             typeInternal = ResolvePropertyTypeForCommonTypes(settings.Type.ToLower(CultureInfo.InvariantCulture));
         }
         if (typeInternal == null)
         {
             typeInternal = BuildManager.GetType(settings.Type, false);
         }
         if (typeInternal == null)
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(settings.Type);
         }
         else
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(typeInternal);
         }
         struct2.PropertyType  = typeInternal;
         settings.TypeInternal = typeInternal;
         struct2.IsReadOnly    = settings.ReadOnly;
         struct2.LineNumber    = settings.ElementInformation.Properties["name"].LineNumber;
         struct2.FileName      = settings.ElementInformation.Properties["name"].Source;
         ht.Add(struct2.Name, struct2);
     }
 }
 private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder, CodeTypeDeclaration type, ProfileNameTypeStruct property)
 {
     string name = property.Name;
     int index = name.IndexOf('.');
     if (index > 0)
     {
         name = name.Substring(index + 1);
     }
     if (!assemblyBuilder.CodeDomProvider.IsValidIdentifier(name))
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_bad_name"), property.FileName, property.LineNumber);
     }
     CodeMemberProperty property2 = new CodeMemberProperty {
         Name = name,
         Attributes = MemberAttributes.Public,
         HasGet = true,
         Type = property.PropertyCodeRefType
     };
     CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
         Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "GetPropertyValue" }
     };
     expression.Parameters.Add(new CodePrimitiveExpression(name));
     CodeMethodReturnStatement statement = new CodeMethodReturnStatement(new CodeCastExpression(property2.Type, expression));
     property2.GetStatements.Add(statement);
     if (!property.IsReadOnly)
     {
         CodeMethodInvokeExpression expression2 = new CodeMethodInvokeExpression {
             Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "SetPropertyValue" }
         };
         expression2.Parameters.Add(new CodePrimitiveExpression(name));
         expression2.Parameters.Add(new CodePropertySetValueReferenceExpression());
         property2.HasSet = true;
         property2.SetStatements.Add(expression2);
     }
     type.Members.Add(property2);
 }
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
 private static void AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName) {
     foreach (ProfilePropertySettings pps in propertyCollection) {
         ProfileNameTypeStruct prop = new ProfileNameTypeStruct();
         if (groupName != null) {
             prop.Name = groupName + "." + pps.Name;
         }
         else {
             prop.Name = pps.Name;
         }
         Type t = pps.TypeInternal;
         if (t == null)
             t = ResolvePropertyTypeForCommonTypes(pps.Type.ToLower(System.Globalization.CultureInfo.InvariantCulture));
         if (t == null)
             t = BuildManager.GetType(pps.Type, false);
         if (t == null) {
             prop.PropertyCodeRefType = new CodeTypeReference(pps.Type);
         }
         else {
             prop.PropertyCodeRefType = new CodeTypeReference(t);
         }
         prop.PropertyType = t;
         pps.TypeInternal = t;
         prop.IsReadOnly = pps.ReadOnly;
         prop.LineNumber = pps.ElementInformation.Properties["name"].LineNumber;
         prop.FileName = pps.ElementInformation.Properties["name"].Source;
         ht.Add(prop.Name, prop);
     }
 }
        // End of BuildProvider implementation

        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder, CodeTypeDeclaration type, ProfileNameTypeStruct property)
        {
            string name = property.Name;
            int    pos = name.IndexOf('.');
            if (pos > 0)
                name = name.Substring(pos+1);
            if (!assemblyBuilder.CodeDomProvider.IsValidIdentifier(name))
                throw new ConfigurationErrorsException(SR.GetString(SR.Profile_bad_name), property.FileName, property.LineNumber);
            // e.g.: public string Color {
            //                       get { return (string) GetProperty("Color"); }
            //                       set { SetProperty("Color", value); } }


            // public  property.Type property.name {
            CodeMemberProperty prop = new CodeMemberProperty();
            prop.Name       = name;
            prop.Attributes = MemberAttributes.Public;
            prop.HasGet     = true;
            prop.Type       = property.PropertyCodeRefType;

            ////////////////////////////////////////////////////////////
            // Get statements
            // get { return (property.type) GetProperty(property.name); }
            CodeMethodInvokeExpression  cmie;
            CodeMethodReturnStatement   getLine;

            cmie = new CodeMethodInvokeExpression();
            cmie.Method.TargetObject = new CodeThisReferenceExpression();
            cmie.Method.MethodName = "GetPropertyValue";
            cmie.Parameters.Add(new CodePrimitiveExpression(name));
            getLine = new CodeMethodReturnStatement(new CodeCastExpression(prop.Type, cmie));

            prop.GetStatements.Add(getLine);

            if (!property.IsReadOnly)
            {

                ////////////////////////////////////////////////////////////
                // Set statements
                // set { SetProperty(property.name, value); }
                CodeMethodInvokeExpression   setLine;

                setLine = new CodeMethodInvokeExpression();
                setLine.Method.TargetObject = new CodeThisReferenceExpression();
                setLine.Method.MethodName = "SetPropertyValue";
                setLine.Parameters.Add(new CodePrimitiveExpression(name));
                setLine.Parameters.Add(new CodePropertySetValueReferenceExpression());
                prop.HasSet = true;
                prop.SetStatements.Add(setLine);
            }
            //prop.LinePragma = new CodeLinePragma(HttpRuntime.GetSafePath(property.FileName), property.LineNumber);
            type.Members.Add(prop);
        }