bool InitializeNodeType(ExtensionNodeType ntype)
{
RuntimeAddin p = addinEngine.GetAddin (ntype.AddinId);
if (p == null) {
if (!addinEngine.IsAddinLoaded (ntype.AddinId)) {
if (!addinEngine.LoadAddin (null, ntype.AddinId, false))
return false;
p = addinEngine.GetAddin (ntype.AddinId);
if (p == null) {
addinEngine.ReportError ("Add-in not found", ntype.AddinId, null, false);
return false;
}
}
}
// If no type name is provided, use TypeExtensionNode by default
if (ntype.TypeName == null || ntype.TypeName.Length == 0 || ntype.TypeName == typeof(TypeExtensionNode).FullName) {
// If it has a custom attribute, use the generic version of TypeExtensionNode
if (ntype.ExtensionAttributeTypeName.Length > 0) {
Type attType = p.GetType (ntype.ExtensionAttributeTypeName, false);
if (attType == null) {
addinEngine.ReportError ("Custom attribute type '" + ntype.ExtensionAttributeTypeName + "' not found.", ntype.AddinId, null, false);
return false;
}
if (ntype.ObjectTypeName.Length > 0 || ntype.TypeName == typeof(TypeExtensionNode).FullName)
ntype.Type = typeof(TypeExtensionNode<>).MakeGenericType (attType);
else
ntype.Type = typeof(ExtensionNode<>).MakeGenericType (attType);
} else {
ntype.Type = typeof(TypeExtensionNode);
return true;
}
}
else {
ntype.Type = p.GetType (ntype.TypeName, false);
if (ntype.Type == null) {
addinEngine.ReportError ("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false);
return false;
}
}
// Check if the type has NodeAttribute attributes applied to fields.
ExtensionNodeType.FieldData boundAttributeType = null;
Dictionary<string,ExtensionNodeType.FieldData> fields = GetMembersMap (ntype.Type, out boundAttributeType);
ntype.CustomAttributeMember = boundAttributeType;
if (fields.Count > 0)
ntype.Fields = fields;
// If the node type is bound to a custom attribute and there is a member bound to that attribute,
// get the member map for the attribute.
if (boundAttributeType != null) {
if (ntype.ExtensionAttributeTypeName.Length == 0)
throw new InvalidOperationException ("Extension node not bound to a custom attribute.");
if (ntype.ExtensionAttributeTypeName != boundAttributeType.MemberType.FullName)
throw new InvalidOperationException ("Incorrect custom attribute type declaration in " + ntype.Type + ". Expected '" + ntype.ExtensionAttributeTypeName + "' found '" + boundAttributeType.MemberType.FullName + "'");
fields = GetMembersMap (boundAttributeType.MemberType, out boundAttributeType);
if (fields.Count > 0)
ntype.CustomAttributeFields = fields;
}
return true;
}