SenseNet.ContentRepository.Storage.Schema.NodeType.CreateInstance C# (CSharp) Method

CreateInstance() public method

public CreateInstance ( Node parent ) : Node
parent Node
return Node
		public Node CreateInstance(Node parent)
		{
			if (parent == null)
				throw new ArgumentNullException("parent");

			if (_type == null)
				_type = TypeHandler.GetType(_className);

			if (_type == null)
			{
				string exceptionMessage = String.Concat("Type not found, therefore the node can't be created.",
					"\nClass name: ", _className, 
					"\nNode type path: ", _nodeTypePath, 
					"\nParent class name: ", (_parent != null ? _parent._className : "Parent is null"), "\n");
				throw new ApplicationException(exceptionMessage);
			}

			//---- only public ctor is valid: public NodeDescendant(Node parent, string nodeTypeName)
			ConstructorInfo ctor = _type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, _newArgTypes, null);
			if (ctor == null) 
				throw new TypeInitializationException(String.Concat("Constructor not found. Valid signature: ctor(Node, string).\nClassName: ", _className), null);

			Node node;
			try
			{
				node = (Node)ctor.Invoke(new object[] { parent, this.Name });
			}
			catch (Exception ex) //rethrow
			{
				throw new ApplicationException(String.Concat("Couldn't create an instance of type '", _className, 
					"'. The invoked constructor threw an exception of type ", ex.GetType().Name, " (it said '", ex.Message, "')."), ex);
			}

			return node;

		}
		internal Node CreateInstance(NodeToken token)

Same methods

NodeType::CreateInstance ( NodeToken token ) : Node
NodeType::CreateInstance ( string nodeTypeName, Node parent ) : Node

Usage Example

Example #1
0
        // -------------------------------------------------------------------------------- Node Factory

        public static Node CreateInstance(string nodeTypeName, Node parent)
        {
            if (nodeTypeName == null)
            {
                throw new ArgumentNullException("nodeTypeName");
            }
            if (nodeTypeName.Length == 0)
            {
                throw new ArgumentOutOfRangeException("nodeTypeName", "Argument cannot be empty");
            }

            NodeType nodeType = NodeTypeManager.Current.NodeTypes[nodeTypeName];

            if (nodeType == null)
            {
                throw new ApplicationException(String.Concat("NodeType not found: ", nodeTypeName));
            }

            return(nodeType.CreateInstance(parent));
        }