コード例 #1
0
        private static void EnureKnownTypes(ModelNode model)
        {
            var allModelNodes = model.FindNodes(n => true);

            foreach (var node in allModelNodes)
            {
                RegisterKnownType(node.GetType());
                RegisterKnownType(node.Value.GetType());
            }
        }
コード例 #2
0
        public void ComposeModelWithAdditionalDefinitions(ModelNode definitionSandbox,
                                                          IEnumerable <DefinitionBase> additionalDefinitions,
                                                          SPObjectModelType objectModelType)
        {
            if (additionalDefinitions == null)
            {
                return;
            }

            foreach (var definition in additionalDefinitions)
            {
                var parentHostType = GetParentHostType(definition.GetType(), objectModelType);

                var targetNode = definitionSandbox
                                 .FindNodes(model =>
                {
                    var featureDefinition = definition as FeatureDefinition;

                    if (featureDefinition != null)
                    {
                        if (featureDefinition.Scope == FeatureDefinitionScope.Web)
                        {
                            return(model.Value.GetType() == typeof(WebDefinition) || model.Value.GetType() == typeof(RootWebDefinition));
                        }

                        if (featureDefinition.Scope == FeatureDefinitionScope.Site)
                        {
                            return(model.Value.GetType() == typeof(SiteDefinition));
                        }
                    }

                    return(model.Value.GetType() == parentHostType);
                })
                                 .FirstOrDefault();

                // additional definitions should be 'first'
                // no NULL ref check, as it means that the model was constructed in the wrong way
                targetNode
                .ChildModels.Insert(0, new ModelNode {
                    Value = definition
                });
            }
        }