Esempio n. 1
0
        public static void ApplyBackingStoreDefinition(CodeTemplate template, string type, string backingName, string efName)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }
            if (string.IsNullOrEmpty(type))
            {
                throw new ArgumentNullException("type");
            }
            if (string.IsNullOrEmpty(backingName))
            {
                throw new ArgumentNullException("backingName");
            }

            template.WriteObjects("        private ", type, " ", backingName, "_store;");
            template.WriteLine();
            template.WriteObjects("        private ", type, " ", backingName, " {");
            template.WriteLine();
            template.WriteObjects("            get { return ", backingName, "_store; }");
            template.WriteLine();
            template.WriteObjects("            set {");
            template.WriteLine();
            template.WriteObjects("                ReportEfPropertyChanging(\"", efName, "\");");
            template.WriteLine();
            if (type == "DateTime")
            {
                template.WriteObjects("                ", backingName, "_store = value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(value, DateTimeKind.Local) : value;");
                template.WriteLine();
            }
            else if (type == "DateTime?")
            {
                template.WriteObjects("                ", backingName, "_store = value != null && value.Value.Kind == DateTimeKind.Unspecified ? (DateTime?)DateTime.SpecifyKind(value.Value, DateTimeKind.Local) : value;");
                template.WriteLine();
            }
            else
            {
                template.WriteObjects("                ", backingName, "_store = value;");
                template.WriteLine();
            }
            template.WriteObjects("                ReportEfPropertyChanged(\"", efName, "\");");
            template.WriteLine();
            template.WriteObjects("            }");
            template.WriteLine();
            template.WriteObjects("        }");
            template.WriteLine();
        }