コード例 #1
0
        /// <summary>
        /// Parses the class defaults element.
        /// </summary>
        /// <param name="elements">The elements to parse.</param>
        public void ParseClassDefaults(IEnumerable <XElement> elements)
        {
            foreach (var child in elements)
            {
                var defaultClassRaw      = (String)child.Attribute("Class");
                var defaultClassResolved = ResolveClass(defaultClassRaw);
                if (String.IsNullOrEmpty(defaultClassResolved))
                {
                    throw new InvalidOperationException(NucleusStrings.DataObjectDefaultMissingClassName);
                }

                var defaultClass = Type.GetType(defaultClassResolved, false);
                if (defaultClass == null)
                {
                    throw new InvalidOperationException(NucleusStrings.DataObjectDefaultHasInvalidClass.Format(defaultClass));
                }

                var defaultValuesForClass = defaultValues[defaultClass] = new Dictionary <String, XElement>();
                foreach (var value in child.Elements())
                {
                    if (ObjectLoaderXmlSerializer.IsReservedKeyword(value.Name.LocalName))
                    {
                        throw new InvalidOperationException(NucleusStrings.DataObjectDefaultHasReservedKeyword.Format(value.Name));
                    }

                    defaultValuesForClass[value.Name.LocalName] = value;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets a set of index parameters from the specified data element.
        /// </summary>
        /// <param name="element">The data element from which to retrieve index parameters.</param>
        /// <returns>The index parameters that were retrieved.</returns>
        private Object[] GetIndexParameters(XElement element)
        {
            var indexParameterValues = new Object[indexParameters.Length];

            for (int i = 0; i < indexParameters.Length; i++)
            {
                var indexParameter = indexParameters[i];

                var attr = element.Attribute(indexParameter.Name);
                if (attr == null)
                {
                    throw new InvalidOperationException(NucleusStrings.DataObjectMissingIndexParam.Format(indexParameter.Name));
                }

                indexParameterValues[i] = ObjectResolver.FromString(attr.Value, indexParameter.ParameterType);
            }

            if (element.Attributes().Where(x => !ObjectLoaderXmlSerializer.IsReservedKeyword(x.Name.LocalName)).Count() > indexParameterValues.Length)
            {
                throw new InvalidOperationException(NucleusStrings.DataObjectHasTooManyIndexParams);
            }

            return(indexParameterValues);
        }