public bool ValidateValue(MegaloScriptModel model) { return(model.IndexTargetIsValid(ValueType.IndexTarget, ValueType.IndexTraits, Value)); }
internal static void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, MegaloScriptValueType valueType, ref int value, IO.TagElementNodeType nodeType = IO.TagElementNodeType.Text, string nodeName = null) where TDoc : class where TCursor : class { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Index); var target = valueType.IndexTarget; if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0 && target == MegaloScriptValueIndexTarget.Trigger) { SerializeTriggerReferenceValue(model, s, valueType, ref value); } #region UseIndexNames else if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseIndexNames) != 0 && target.HasIndexName()) { var id_resolving_ctxt = new MegaloScriptModel.IndexNameResolvingContext(model, target); var id_resolver = MegaloScriptModel.IndexNameResolvingContext.IdResolver; var name_resolver = MegaloScriptModel.IndexNameResolvingContext.NameResolver; switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElementIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Attribute: s.StreamAttributeIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver); break; case IO.TagElementNodeType.Text: s.StreamCursorIdAsString(ref value, id_resolving_ctxt, id_resolver, name_resolver); break; } } #endregion else { switch (nodeType) { case IO.TagElementNodeType.Element: s.StreamElement(nodeName, ref value); break; case IO.TagElementNodeType.Attribute: s.StreamAttribute(nodeName, ref value); break; case IO.TagElementNodeType.Text: s.StreamCursor(ref value); break; } } // #REVIEW_BLAM: this will fail when embedding and the target is a Trigger since we don't preload triggers or such if (s.IsReading && ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) == 0 || target != MegaloScriptValueIndexTarget.Trigger) ) { if (!model.IndexTargetIsValid(target, valueType.IndexTraits, value)) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo, "A {0} reference has an invalid value {1}", target, value))); } } }