示例#1
0
 public XMLPropItemModel(string type, string name,
                         string extraInfo = null, PropStorageStrategyEnum storageStrategy = PropStorageStrategyEnum.Internal,
                         bool typeIsSolid = true,
                         PropDoWhenChanged doWhenChanged = null, PropComparerField comparer = null)
 {
     Type               = type;
     Name               = name;
     ExtraInfo          = extraInfo;
     StorageStrategy    = storageStrategy;
     TypeIsSolid        = typeIsSolid;
     ComparerField      = comparer;
     DoWhenChangedField = doWhenChanged;
 }
示例#2
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));
        }
示例#3
0
        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));
        }
示例#4
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));
        }