Inheritance: Zetbox.Generator.MemberTemplate
Example #1
0
        public override void Generate()
        {
#line 37 "P:\zetbox\Zetbox.Generator\Templates\Properties\CompoundObjectPropertyTemplate.cst"
            this.WriteObjects("        // BEGIN ", this.GetType(), "\r\n");
            this.WriteObjects("        // implement the user-visible interface\r\n");
#line 39 "P:\zetbox\Zetbox.Generator\Templates\Properties\CompoundObjectPropertyTemplate.cst"
            DelegatingProperty.Call(Host, ctx, propName, coType, backingPropertyName, coImplementationType);
#line 40 "P:\zetbox\Zetbox.Generator\Templates\Properties\CompoundObjectPropertyTemplate.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("        /// <summary>backing store for ", UglyXmlEncode(propName), "</summary>\r\n");
            this.WriteObjects("        private ", coImplementationType, " ", backingStoreName, ";\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("        /// <summary>backing property for ", UglyXmlEncode(propName), ", takes care of attaching/detaching the values</summary>\r\n");
            this.WriteObjects("        ", GetModifiers(), " ", coImplementationType, " ", backingPropertyName, "\r\n");
            this.WriteObjects("        {\r\n");
            this.WriteObjects("            get \r\n");
            this.WriteObjects("			{ \r\n");
            this.WriteObjects("				return ", backingStoreName, "; \r\n");
            this.WriteObjects("			}\r\n");
            this.WriteObjects("            set\r\n");
            this.WriteObjects("            {\r\n");
            this.WriteObjects("                if (((IPersistenceObject)this).IsReadonly) throw new ReadOnlyObjectException();\r\n");
            this.WriteObjects("                if (value == null)\r\n");
            this.WriteObjects("                    throw new ArgumentNullException(\"value\");\r\n");
            this.WriteObjects("                if (!object.Equals(", backingStoreName, ", value))\r\n");
            this.WriteObjects("                {\r\n");
            this.WriteObjects("					var __oldValue = ", backingStoreName, ";\r\n");
            this.WriteObjects("					var __newValue = value;\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("					NotifyPropertyChanging(\"", propName, "\", __oldValue, __newValue);\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("					if (", backingStoreName, " != null)\r\n");
            this.WriteObjects("					{ \r\n");
            this.WriteObjects("						", backingStoreName, ".DetachFromObject(this, \"", propName, "\");\r\n");
            this.WriteObjects("					}\r\n");
            this.WriteObjects("					__newValue = (", coImplementationType, ")__newValue.Clone();\r\n");
            this.WriteObjects("					", backingStoreName, " = __newValue;\r\n");
            this.WriteObjects("					", backingStoreName, ".AttachToObject(this, \"", propName, "\");\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("					NotifyPropertyChanged(\"", propName, "\", __oldValue, __newValue);\r\n");
            this.WriteObjects("				}\r\n");
            this.WriteObjects("				else\r\n");
            this.WriteObjects("				{\r\n");
            this.WriteObjects("					SetInitializedProperty(\"", propName, "\");\r\n");
            this.WriteObjects("				}\r\n");
            this.WriteObjects("            }\r\n");
            this.WriteObjects("        }\r\n");
#line 80 "P:\zetbox\Zetbox.Generator\Templates\Properties\CompoundObjectPropertyTemplate.cst"
            AddSerialization(serializationList, coType, propName, coImplementationType, backingPropertyName);

#line 82 "P:\zetbox\Zetbox.Generator\Templates\Properties\CompoundObjectPropertyTemplate.cst"
            this.WriteObjects("        // END ", this.GetType(), "");
        }
Example #2
0
        public override void Generate()
        {
#line 17 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("	");
#line 49 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("        // BEGIN ", this.GetType(), " for ", name, "\r\n");
            this.WriteObjects("        // fkBackingName=", fkBackingName, "; fkGuidBackingName=", fkGuidBackingName, ";\r\n");
            this.WriteObjects("        // referencedInterface=", referencedInterface, "; moduleNamespace=", moduleNamespace, ";\r\n");
            this.WriteObjects("        // inverse Navigator=", String.IsNullOrEmpty(inverseNavigatorName) ? "none" : inverseNavigatorName, "; ", inverseNavigatorIsList ? "is list" : "is reference", ";\r\n");
            this.WriteObjects("        // PositionStorage=", String.IsNullOrEmpty(positionPropertyName) ? "none" : positionPropertyName, ";\r\n");
            this.WriteObjects("        // Target ", relDataTypeExportable ? String.Empty : "not ", "exportable; does ", callGetterSetterEvents ? String.Empty : "not ", "call events\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("        // implement the user-visible interface\r\n");
            this.WriteObjects("        [XmlIgnore()]\r\n");
            this.WriteObjects("        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]\r\n");
#line 59 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            DelegatingProperty.Call(Host, ctx, name, referencedInterface, implName, referencedImplementation);
#line 60 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("        private int? ", fkBackingName, ";\r\n");
            this.WriteObjects("\r\n");
#line 63 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            if (relDataTypeExportable)
            {
#line 64 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("        private Guid? ", fkGuidBackingName, " = null;\r\n");
#line 65 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            }
#line 66 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("        // internal implementation\r\n");
            this.WriteObjects("        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]\r\n");
            this.WriteObjects("        ", GetModifiers(), " ", referencedImplementation, " ", implName, "\r\n");
            this.WriteObjects("        {\r\n");
            this.WriteObjects("            get\r\n");
            this.WriteObjects("            {\r\n");
            this.WriteObjects("                ", referencedImplementation, " __value;\r\n");
            this.WriteObjects("                if (", fkBackingName, ".HasValue)\r\n");
            this.WriteObjects("                    __value = (", referencedImplementation, ")Context.Find<", referencedInterface, ">(", fkBackingName, ".Value);\r\n");
            this.WriteObjects("                else\r\n");
            this.WriteObjects("                    __value = null;\r\n");
            this.WriteObjects("\r\n");
#line 80 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            if (callGetterSetterEvents)
            {
#line 83 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                if (", eventName, "_Getter != null)\r\n");
                this.WriteObjects("                {\r\n");
                this.WriteObjects("                    var e = new PropertyGetterEventArgs<", referencedInterface, ">(__value);\r\n");
                this.WriteObjects("                    ", eventName, "_Getter(this, e);\r\n");
                this.WriteObjects("                    __value = (", referencedImplementation, ")e.Result;\r\n");
                this.WriteObjects("                }\r\n");
#line 90 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            }

#line 92 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("                return __value;\r\n");
            this.WriteObjects("            }\r\n");
            this.WriteObjects("            set\r\n");
            this.WriteObjects("            {\r\n");
            this.WriteObjects("                if (((IPersistenceObject)this).IsReadonly) throw new ReadOnlyObjectException();\r\n");
            this.WriteObjects("                if (value != null && value.Context != this.Context) throw new WrongZetboxContextException();\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("                // shortcut noops\r\n");
            this.WriteObjects("                if ((value == null && ", fkBackingName, " == null) || (value != null && value.ID == ", fkBackingName, "))\r\n");
            this.WriteObjects("				{\r\n");
            this.WriteObjects("					SetInitializedProperty(\"", name, "\");\r\n");
            this.WriteObjects("                    return;\r\n");
            this.WriteObjects("				}\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("                // cache old value to remove inverse references later\r\n");
            this.WriteObjects("                var __oldValue = ", implName, ";\r\n");
            this.WriteObjects("                var __newValue = value;\r\n");
            this.WriteObjects("\r\n");
            this.WriteObjects("                // Changing Event fires before anything is touched\r\n");
            this.WriteObjects("                NotifyPropertyChanging(\"", name, "\", __oldValue, __newValue);\r\n");
            this.WriteObjects("\r\n");
#line 115 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            if (callGetterSetterEvents)
            {
#line 118 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                if (", eventName, "_PreSetter != null && IsAttached)\r\n");
                this.WriteObjects("                {\r\n");
                this.WriteObjects("                    var e = new PropertyPreSetterEventArgs<", referencedInterface, ">(__oldValue, __newValue);\r\n");
                this.WriteObjects("                    ", eventName, "_PreSetter(this, e);\r\n");
                this.WriteObjects("                    __newValue = (", referencedImplementation, ")e.Result;\r\n");
                this.WriteObjects("                }\r\n");
#line 125 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            }

#line 127 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("\r\n");
            this.WriteObjects("                // next, set the local reference\r\n");
            this.WriteObjects("                ", fkBackingName, " = __newValue == null ? (int?)null : __newValue.ID;\r\n");
            this.WriteObjects("\r\n");
#line 132 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            if (!String.IsNullOrEmpty(inverseNavigatorName))
            {
#line 136 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                // now fixup redundant, inverse references\r\n");
                this.WriteObjects("                // The inverse navigator will also fire events when changed, so should\r\n");
                this.WriteObjects("                // only be touched after setting the local value above.\r\n");
                this.WriteObjects("                // TODO: for complete correctness, the \"other\" Changing event should also fire\r\n");
                this.WriteObjects("                //       before the local value is changed\r\n");
                this.WriteObjects("                if (__oldValue != null)\r\n");
                this.WriteObjects("                {\r\n");
#line 144 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                if (inverseNavigatorIsList)
                {
                    // TODO: check whether __oldValue is loaded before potentially triggering a DB Call

#line 148 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                    this.WriteObjects("                    // remove from old list\r\n");
                    this.WriteObjects("                    (__oldValue.", inverseNavigatorName, " as IRelationListSync<", ownInterface, ">).RemoveWithoutClearParent(this);\r\n");
#line 151 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                }
                else
                {
#line 155 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                    this.WriteObjects("                    // unset old reference\r\n");
                    this.WriteObjects("                    __oldValue.", inverseNavigatorName, " = null;\r\n");
#line 158 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                }

#line 160 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                }\r\n");
                this.WriteObjects("\r\n");
                this.WriteObjects("                if (__newValue != null)\r\n");
                this.WriteObjects("                {\r\n");
#line 165 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                if (inverseNavigatorIsList)
                {
#line 168 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                    this.WriteObjects("                    // add to new list\r\n");
                    this.WriteObjects("                    (__newValue.", inverseNavigatorName, " as IRelationListSync<", ownInterface, ">).AddWithoutSetParent(this);\r\n");
#line 171 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                }
                else
                {
#line 175 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                    this.WriteObjects("                    // set new reference\r\n");
                    this.WriteObjects("                    __newValue.", inverseNavigatorName, " = this;\r\n");
#line 178 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                }

#line 180 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                }\r\n");
#line 182 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            }

#line 184 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("                // everything is done. fire the Changed event\r\n");
            this.WriteObjects("                NotifyPropertyChanged(\"", name, "\", __oldValue, __newValue);\r\n");
            this.WriteObjects("\r\n");
#line 188 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            if (callGetterSetterEvents)
            {
#line 191 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
                this.WriteObjects("                if (", eventName, "_PostSetter != null && IsAttached)\r\n");
                this.WriteObjects("                {\r\n");
                this.WriteObjects("                    var e = new PropertyPostSetterEventArgs<", referencedInterface, ">(__oldValue, __newValue);\r\n");
                this.WriteObjects("                    ", eventName, "_PostSetter(this, e);\r\n");
                this.WriteObjects("                }\r\n");
#line 197 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            }

#line 199 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("            }\r\n");
            this.WriteObjects("        }\r\n");
#line 202 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            AddSerialization(serializationList, name, fkBackingName, fkGuidBackingName);

            if (!String.IsNullOrEmpty(positionPropertyName))
            {
                Properties.NotifyingValueProperty.Call(
                    Host, ctx, serializationList,
                    "int?", positionPropertyName, moduleNamespace, false, disableExport);
            }

#line 211 "P:\zetbox\Zetbox.Generator\Templates\Properties\ObjectReferencePropertyTemplate.cst"
            this.WriteObjects("        // END ", this.GetType(), " for ", name, "\r\n");
        }