/// <summary> /// Returns the list of namespaces needed in class that derives from IPropBag /// to make calls to GetIt, SetIt and Add/RemovePropChanged. /// </summary> /// <param name="?"></param> /// <returns></returns> public static IList <string> GetRequiredNamespaces(this XMLPropModel pm) { return(new List <string> { REFLECTION_NAME_SPACE, PROP_BAG_NAME_SPACE, INPWV_NAME_SPACE }); }
public static DRM.PropBag.XMLModel.PropComparerField PrepareComparerField(this XMLPropModel pm, DRM.PropBag.XMLModel.PropComparerField cf) { if (cf == null) { return(new DRM.PropBag.XMLModel.PropComparerField("null", false)); } if (cf.UseRefEquality && cf.Comparer != null) { throw new ArgumentException("cf value of comparer must be null, if UseRefEquality is specified."); } return(new DRM.PropBag.XMLModel.PropComparerField(cf.Comparer ?? "null", cf.UseRefEquality)); }
static public string GetBaseClassName(XMLPropModel propModel) { switch (propModel.DeriveFromClassMode) { case DeriveFromClassModeEnum.PropBag: return("PropBag"); case DeriveFromClassModeEnum.PubPropBag: return("PubPropBag"); case DeriveFromClassModeEnum.Custom: return(propModel.NameOfClassToWrap); default: throw new InvalidOperationException($"The {propModel.DeriveFromClassMode} is not recognized or is not supported."); } //return propModel.DeriveFromClassMode == DeriveFromClassModeEnum. .DeriveFromPubPropBag ? "PubPropBag" : "PropBag"; }
static public string GetNamespaces(XMLPropModel propModel) { StringBuilder r = new StringBuilder(); IList <string> requiredNamespaces = propModel.GetRequiredNamespaces(); foreach (string s in requiredNamespaces) { r.AppendLine(string.Format("using {0};", s)); } foreach (string s in propModel.Namespaces) { r.AppendLine(string.Format("using {0};", s)); } return(r.AppendLine().ToString()); }
static public PropDefRaw GetPropDef(XMLPropModel propModel, XMLPropItemModel pi, bool typeIsSolid = true) { PropDoWhenChanged doWhenPrepped = propModel.PrepareDoWhenChangedField(pi); DRM.PropBag.XMLModel.PropComparerField comparerPrepped = propModel.PrepareComparerField(pi.ComparerField); PropCreateMethodEnum creationStyle; string initVal = null; if (pi.StorageStrategy == PropStorageStrategyEnum.Internal) { DRM.PropBag.XMLModel.PropInitialValueField initialValPrepped = propModel.PrepareInitialField(pi); if (!initialValPrepped.SetToUndefined) { if (initialValPrepped.SetToDefault) // (pi.InitalValueField.SetToDefault) { // Use default value for "we provide storage" implementation. creationStyle = PropCreateMethodEnum.useDefault; } else { // Use the value indicated for "we provide storage" implentation. creationStyle = PropCreateMethodEnum.value; initVal = pi.InitialValueField.InitialValue; } } else { // No value for "we provide storage" implementation: value will be undefined. creationStyle = PropCreateMethodEnum.noValue; } } else { // No value, for no store implementation. creationStyle = PropCreateMethodEnum.noValue; } return(new PropDefRaw(creationStyle, pi.StorageStrategy, typeIsSolid, comparerPrepped.UseRefEquality, pi.Type, pi.Name, doWhenPrepped.DoWhenChanged, doWhenPrepped.DoAfterNotify, comparerPrepped.Comparer, pi.ExtraInfo, initVal)); }
public void ReadInput() { string PropDefsFilename = "Sample_PropDefs.xml"; string excPath = System.AppDomain.CurrentDomain.BaseDirectory; string projectFolderPath = FileUtils.GetProjectFolder(excPath); string propDefsPath = System.IO.Path.Combine(projectFolderPath, "T4", PropDefsFilename); XMLPropModel pm = PropModelReader.ReadXml(propDefsPath); Assert.That(pm, Is.Not.EqualTo(null), "PropModelReader returned null"); string nameSpaceText = T4Support.GetNamespaces(pm); List <XMLPropItemModel> test = pm.Props; Assert.That(pm.Props.Count(), Is.EqualTo(11)); }
static public string GetSubscribeMethodCallText(XMLPropModel propModel, XMLPropItemModel pi) { PropDoWhenChanged doWhenPrepped = propModel.PrepareDoWhenChangedField(pi); //SubscribeToPropChanged<string>(GetDelegate<string>("DoWhenStringChanged"), "PropString"); //string result = $"SubscribeToPropChanged<{pi.Type}>(GetDelegate<{pi.Type}>(\"{doWhenPrepped.DoWhenChanged}\"), \"{pi.Name}\")"; string result; if (doWhenPrepped.DoWhenChanged != "null") { result = $"SubscribeToPropChanged<{pi.Type}>({doWhenPrepped.DoWhenChanged}, \"{pi.Name}\");"; } else { result = string.Empty; } return(result); }
public void WriteXml() { XMLPropModel pm = new XMLPropModel { ClassName = "TestOu", DeriveFromPubPropBag = false, DeferMethodRefResolution = false, Namespace = "PropBagLib.Tests", Props = new List <XMLPropItemModel>() }; XMLPropItemModel p = new XMLPropItemModel { Name = "one", Type = "int", InitialValueField = new PropInitialValueField("1"), StorageStrategy = PropStorageStrategyEnum.Internal }; pm.Props.Add(p); p = new XMLPropItemModel { Name = "two", Type = "string", InitialValueField = new PropInitialValueField("1"), StorageStrategy = PropStorageStrategyEnum.Internal }; pm.Props.Add(p); string outFileName = "TestSerialization.xml"; string excPath = System.AppDomain.CurrentDomain.BaseDirectory; string projectFolderPath = FileUtils.GetProjectFolder(excPath); string outPath = System.IO.Path.Combine(projectFolderPath, "T4", outFileName); PropModelWriter.WriteXml(outPath, pm); }
public static DRM.PropBag.XMLModel.PropInitialValueField PrepareInitialField(this XMLPropModel pm, XMLPropItemModel pi) { DRM.PropBag.XMLModel.PropInitialValueField pivf = pi.InitialValueField; if (pivf == null) { if (pm.RequireExplicitInitialValue) { string msg = "For property {0}: Property definitions that have false for the value of 'caller-provides-storage' " + "must include an initial-value element."; throw new ArgumentException(string.Format(msg, pi.Name)); } // This will result in the default value being used. return(new DRM.PropBag.XMLModel.PropInitialValueField(null, setToDefault: true, setToUndefined: false, setToNull: false, setToEmptyString: false)); } if (pivf.InitialValue == null && !pivf.SetToDefault && !pivf.SetToUndefined && !pivf.SetToNull && !pivf.SetToEmptyString) { string msg = "For property {0}: The initial-value must be specified if use-undefined, use-default, use-null and use-empty-string are all false."; throw new ArgumentException(string.Format(msg, pi.Name)); } if (pivf.SetToDefault && pivf.InitialValue != null) { string msg = "For property {0}: The initial-value has been specified, but use-default has also been set to true; " + "this is ambiguous."; throw new ArgumentException(string.Format(msg, pi.Name)); } if (pivf.SetToUndefined && pivf.InitialValue != null) { string msg = "For property {0}: he initial-value has been specified, but use-undefined has also been set to true; " + "this is ambiguous."; throw new ArgumentException(string.Format(msg, pi.Name)); } if (pivf.SetToNull && pivf.InitialValue != null) { string msg = "For property {0}: he initial-value has been specified, but use-null has also been set to true; " + "this is ambiguous."; throw new ArgumentException(string.Format(msg, pi.Name)); } if (pivf.SetToEmptyString && pivf.InitialValue != null) { string msg = "For property {0}: he initial-value has been specified, but use-empty-string has also been set to true; " + "this is ambiguous."; throw new ArgumentException(string.Format(msg, pi.Name)); } //if (pivf.SetToDefault) //{ // return new PropIniialValueField("null", setToDefault: true, setToUndefined: false, setToNull: false, setToEmptyString: false); //} //if (pivf.SetToUndefined) //{ // return new PropIniialValueField(null, setToDefault: false, setToUndefined: true, setToNull: false, setToEmptyString: false); //} if (pivf.SetToNull) { return(new DRM.PropBag.XMLModel.PropInitialValueField("null", setToDefault: false, setToUndefined: false, setToNull: true, setToEmptyString: false)); } if (pivf.SetToEmptyString) { if (pi.Type == typeof(Guid).Name) { const string EMPTY_GUID = "00000000-0000-0000-0000-000000000000"; return(new DRM.PropBag.XMLModel.PropInitialValueField(EMPTY_GUID, setToDefault: false, setToUndefined: false, setToNull: false, setToEmptyString: true)); } else { return(new DRM.PropBag.XMLModel.PropInitialValueField("\"\"", setToDefault: false, setToUndefined: false, setToNull: false, setToEmptyString: true)); } } return(pivf); }
public static DRM.PropBag.XMLModel.PropDoWhenChanged PrepareDoWhenChangedField(this XMLPropModel pm, XMLPropItemModel pi) { DRM.PropBag.XMLModel.PropDoWhenChanged dwcf = pi.DoWhenChangedField; if (dwcf == null) { return(new DRM.PropBag.XMLModel.PropDoWhenChanged("null")); } string doWhenChanged; if (pm.DeferMethodRefResolution) { // Wrap in a call to GetDelegate if non-null, otherwise return the string: "null" doWhenChanged = dwcf.DoWhenChanged == null ? "null" : WrapWithGetDelegate(dwcf.DoWhenChanged, pi.Type); } else { // Return the string: "null", if there is no doWhenChanged action provided. doWhenChanged = dwcf.DoWhenChanged ?? "null"; } return(new PropDoWhenChanged(doWhenChanged, dwcf.DoAfterNotify)); }
static public string GetAddPropMethodCallText(XMLPropModel propModel, XMLPropItemModel pi) { PropDoWhenChanged doWhenPrepped = propModel.PrepareDoWhenChangedField(pi); DRM.PropBag.XMLModel.PropComparerField comparerPrepped = propModel.PrepareComparerField(pi.ComparerField); // Prepare the AddProp method call string formatString; object[] vals = new object[] { comparerPrepped.UseRefEquality ? "ObjComp" : null, null, // will eventually be null, "NoValue" or "NoStore" pi.Type, pi.Name, comparerPrepped.Comparer, "null", "null", // Extra Info -- if we ever use it. null // Initial Value }; if (pi.StorageStrategy == PropStorageStrategyEnum.Internal) { DRM.PropBag.XMLModel.PropInitialValueField initialValPrepped = propModel.PrepareInitialField(pi); if (!initialValPrepped.SetToUndefined) { // AddProp or AddPropObjComp // public IProp<T> AddProp<T>(string propertyName, // Func<T,T,bool> comparer = null, // object extraInfo = null, // T initalValue = default(T)) if (initialValPrepped.SetToDefault) // (pi.InitalValueField.SetToDefault) { if (comparerPrepped.UseRefEquality || comparerPrepped.Comparer == null) { formatString = "AddProp{0}{1}<{2}>(\"{3}\")"; } else { formatString = "AddProp{0}{1}<{2}>(\"{3}\", comparer:{4})"; } } else { vals[6] = PropModelExtensions.GetStringRepForValue(initialValPrepped.InitialValue, pi.Type); if (comparerPrepped.UseRefEquality) { formatString = "AddProp{0}{1}<{2}>(\"{3}\", {4}, initialValue: {5})"; } else { formatString = "AddProp{0}{1}<{2}>(\"{3}\", {4}, {5}, initialValue:{6})"; } } } else { //AddPropNoValue or AddPropObjCompNoValue // public IProp<T> AddProp<T>(string propertyName, // Action<T, T> doIfChanged = null, // bool doAfterNotify = false, // Func<T,T,bool> comparer = null, // object extraInfo = null, vals[1] = "NoValue"; if (comparerPrepped.UseRefEquality || comparerPrepped.Comparer == null) { formatString = "AddProp{0}{1}<{2}>(\"{3}\")"; } else { formatString = "AddProp{0}{1}<{2}>(\"{3}\", comparer:{4})"; } } } else { // AddPropNoStore or AddPropNoStoreObjComp // public void AddPropNoStore<T>(string propertyName, // Action<T, T> doIfChanged, // bool doAfterNotify = false, // Func<T,T,bool> comparer = null) vals[1] = "NoStore"; if (comparerPrepped.UseRefEquality || comparerPrepped.Comparer == null) { formatString = "AddProp{0}{1}<{2}>(\"{3}\")"; } else { formatString = "AddProp{0}{1}<{2}>(\"{3}\", comparer:{4})"; } } return(string.Format(formatString, vals)); }
static public string GetSafetyModeString(XMLPropModel propModel) { return(propModel.TypeSafetyMode.ToString()); }