コード例 #1
0
        /// <summary>
        /// Check if Metaproperty contains JsonName or VariantName
        /// </summary>
        public bool CanBeAssignedAsName(string nameToCheck)
        {
            if (!string.IsNullOrEmpty(nameToCheck))
            {
                if (nameToCheck == JsonName || (FallbackNames != null && FallbackNames.Contains(nameToCheck)))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Loads the fields.
        /// </summary>
        /// <param name="postedData">Posted data.</param>
        /// <param name="fieldDefaults">Field defaults.</param>
        public void LoadFields(Map <string> fieldDefaults)
        {
            FaultyFields = new List <string> ();

            // if you squint your eyes you can already see the bugs in this
            // code.
            foreach (string fieldName in FieldExpressions.Keys)
            {
                string fieldValue;
                if (PostedData.TryGetString(fieldName, out fieldValue))
                {
                    if (FieldExpressions [fieldName].IsMatch(fieldValue))
                    {
                        ParseLoad(fieldName, fieldValue);
                    }
                    else
                    {
                        if (fieldDefaults.TryGetString(fieldName, out fieldValue))
                        {
                            this [fieldName] = fieldValue;
                        }

                        FaultyFields.Add(fieldName);
                    }
                }
                else
                {
                    object fallbackObject;
                    if (FallbackNames.Contains(fieldName) && this.TryGetFallback(fieldName, out fallbackObject))
                    {
                        this [fieldName] = fallbackObject;
                    }
                    else
                    {
                        if (fieldDefaults.TryGetString(fieldName, out fieldValue))
                        {
                            this [fieldName] = fieldValue;
                        }
                        else
                        {
                            FaultyFields.Add(fieldName);
                        }
                    }
                }
            }
        }