private void BuildObjectPropertiesHelper(IDictionary objects, bool useApplicationState)
        {
            IDictionaryEnumerator enumerator = objects.GetEnumerator();

            while (enumerator.MoveNext())
            {
                HttpStaticObjectsEntry          entry        = (HttpStaticObjectsEntry)enumerator.Value;
                CodePropertyReferenceExpression targetObject = new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), useApplicationState ? "Application" : "Session"), "StaticObjects");
                CodeMethodInvokeExpression      expression   = new CodeMethodInvokeExpression(targetObject, "GetObject", new CodeExpression[0]);
                expression.Parameters.Add(new CodePrimitiveExpression(entry.Name));
                Type declaredType = entry.DeclaredType;
                if (useApplicationState)
                {
                    this.BuildInjectedGetPropertyMethod(entry.Name, declaredType, new CodeCastExpression(declaredType, expression), false);
                }
                else
                {
                    CodeMemberProperty property = new CodeMemberProperty {
                        Name = entry.Name,
                        Type = new CodeTypeReference(declaredType)
                    };
                    property.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(declaredType, expression)));
                    this._sourceDataClass.Members.Add(property);
                }
            }
        }
 private void AddStaticObjectAssemblyDependencies(HttpStaticObjectsCollection staticObjects)
 {
     if ((staticObjects != null) && (staticObjects.Objects != null))
     {
         IDictionaryEnumerator enumerator = staticObjects.Objects.GetEnumerator();
         while (enumerator.MoveNext())
         {
             HttpStaticObjectsEntry entry = (HttpStaticObjectsEntry)enumerator.Value;
             base.AddTypeDependency(entry.ObjectType);
         }
     }
 }
        /*
         * Add assembly dependencies for a collection of static objects
         */
        private void AddStaticObjectAssemblyDependencies(HttpStaticObjectsCollection staticObjects)
        {
            if (staticObjects == null || staticObjects.Objects == null)
            {
                return;
            }

            IDictionaryEnumerator en = staticObjects.Objects.GetEnumerator();

            while (en.MoveNext())
            {
                HttpStaticObjectsEntry entry = (HttpStaticObjectsEntry)en.Value;

                AddTypeDependency(entry.ObjectType);
            }
        }
Example #4
0
        /*
         * Helper method for building application and session scope injected
         * properties.  If useApplicationState, build application properties, otherwise
         * build session properties.
         */
        private void BuildObjectPropertiesHelper(IDictionary objects, bool useApplicationState)
        {
            IDictionaryEnumerator en = objects.GetEnumerator();

            while (en.MoveNext())
            {
                HttpStaticObjectsEntry entry = (HttpStaticObjectsEntry)en.Value;

                // e.g. (PropType)Session.StaticObjects["PropName"]

                // Use the appropriate collection
                CodePropertyReferenceExpression stateObj = new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(),
                                                                                                                                   useApplicationState ? "Application" : "Session"),
                                                                                               "StaticObjects");

                CodeMethodInvokeExpression getObject = new CodeMethodInvokeExpression(stateObj, "GetObject");
                getObject.Parameters.Add(new CodePrimitiveExpression(entry.Name));


                Type declaredType = entry.DeclaredType;
                Debug.Assert(!Util.IsLateBoundComClassicType(declaredType));

                if (useApplicationState)
                {
                    // for application state use property that does caching in a member
                    BuildInjectedGetPropertyMethod(entry.Name, declaredType,
                                                   new CodeCastExpression(declaredType, getObject),
                                                   false /*fPublicProp*/);
                }
                else
                {
                    // for session state use lookup every time, as one application instance deals with many sessions
                    CodeMemberProperty prop = new CodeMemberProperty();
                    prop.Name = entry.Name;
                    prop.Type = new CodeTypeReference(declaredType);
                    prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(declaredType, getObject)));
                    _sourceDataClass.Members.Add(prop);
                }
            }
        }