Exemple #1
0
        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));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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));
        }