public virtual void WriteComponentProperty(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ComponentPropertyAttribute attrib, BaseAttribute parentAttribute) { System.Type componentType = attrib.ComponentType; if(componentType == null) if(member is System.Reflection.FieldInfo) componentType = (member as System.Reflection.FieldInfo).FieldType; else // It MUST be a PropertyInfo componentType = (member as System.Reflection.PropertyInfo).PropertyType; object[] componentAttributes = componentType.GetCustomAttributes(typeof(ComponentAttribute), false); if(componentAttributes.Length == 0) throw new MappingException(componentType.FullName + " doesn't have the attribute [Component]!"); ComponentAttribute componentAttribute = componentAttributes[0] as ComponentAttribute; string componentName = attrib.PropertyName; if(componentName == null) componentName = member.Name; // Default value if(componentAttribute.Name != null && componentAttribute.Name != componentName) // Because, it will be used by the default implementation of "WriteComponent()" throw new MappingException(componentType.FullName + " must have a [Component] with a 'null' Name (or the name '" + componentName + "')"); // Get the helper to set the componentName HbmWriterHelperEx helper = this.DefaultHelper as HbmWriterHelperEx; if(helper == null) throw new MappingException("DefaultHelper must be a HbmWriterHelperEx (or a subType) to use [ComponentProperty]"); // Set the value that will be returned when WriteComponent() will call Get_Component_Name_DefaultValue() string savedValue = helper.DefaultValue; helper.DefaultValue = componentName; try { WriteComponent(writer, componentType); } finally { helper.DefaultValue = savedValue; } }
public virtual void WriteComponentProperty(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ComponentPropertyAttribute attrib, BaseAttribute parentAttribute) { System.Type componentType = attrib.ComponentType; if (componentType == null) { if (member is System.Reflection.FieldInfo) { componentType = (member as System.Reflection.FieldInfo).FieldType; } else // It MUST be a PropertyInfo { componentType = (member as System.Reflection.PropertyInfo).PropertyType; } } object[] componentAttributes = componentType.GetCustomAttributes(typeof(ComponentAttribute), false); if (componentAttributes.Length == 0) { throw new MappingException(componentType.FullName + " doesn't have the attribute [Component]!"); } ComponentAttribute componentAttribute = componentAttributes[0] as ComponentAttribute; string componentName = attrib.PropertyName; if (componentName == null) { componentName = member.Name; // Default value } if (componentAttribute.Name != null && componentAttribute.Name != componentName) { // Because, it will be used by the default implementation of "WriteComponent()" throw new MappingException(componentType.FullName + " must have a [Component] with a 'null' Name (or the name '" + componentName + "')"); } // Get the helper to set the componentName HbmWriterHelperEx helper = this.DefaultHelper as HbmWriterHelperEx; if (helper == null) { throw new MappingException("DefaultHelper must be a HbmWriterHelperEx (or a subType) to use [ComponentProperty]"); } // Set the value that will be returned when WriteComponent() will call Get_Component_Name_DefaultValue() string savedValue = helper.DefaultValue; helper.DefaultValue = componentName; try { WriteComponent(writer, componentType); } finally { helper.DefaultValue = savedValue; } }