Exemple #1
0
        private string GetTypeFullName(Type t)
        {
            NDOAssemblyName ndoAssName = new NDOAssemblyName(t.Assembly.FullName);
            string          type       = t.FullName.Replace("+", "/");

            return("[" + ndoAssName.Name + "]" + type);
        }
Exemple #2
0
        public RelationNode(FieldInfo relationFieldInfo, NDORelationAttribute attr, ClassNode parent)
        {
            this.parent    = parent;
            this.fieldType = relationFieldInfo.FieldType;
            Type            parentType   = relationFieldInfo.ReflectedType;
            NDOAssemblyName an           = new NDOAssemblyName(parentType.Assembly.FullName);
            string          assShortName = an.Name;

            this.isElement = !(relationFieldInfo.FieldType == typeof(IList) ||
                               relationFieldInfo.FieldType.GetInterface("IList") != null ||
                               GenericIListReflector.IsGenericIList(relationFieldInfo.FieldType));

            // dataType & declaringType always have
            // - a class/valutype prefix
            // - an [AssName] prefix
            this.dataType = new ReflectedType(relationFieldInfo.FieldType).ILName;
            if (relationFieldInfo.DeclaringType != relationFieldInfo.ReflectedType)
            {
                this.declaringType = new ReflectedType(relationFieldInfo.DeclaringType).ILName;
            }
            else
            {
                this.declaringType = null;
            }
            this.name = relationFieldInfo.Name;

            Type attrType = attr.GetType();

            this.relationName = attr.RelationName;
            this.relationInfo = attr.Info;
            Type relType;

            if (isElement)
            {
                relType = relationFieldInfo.FieldType;
            }
            else
            {
                if (attr.RelationType == null && relationFieldInfo.FieldType.IsGenericType)
                {
                    relType = relationFieldInfo.FieldType.GetGenericArguments()[0];
                }
                else
                {
                    relType = attr.RelationType;
                }

                if (relType == null)
                {
                    throw new Exception("Can't determine referenced type in relation " + parent.Name + "." + this.name + ". Provide a type parameter for the [NDORelation] attribute.");
                }
            }

            if (relType.IsGenericType && !relType.IsGenericTypeDefinition)
            {
                relType = relType.GetGenericTypeDefinition();
            }

            // Related Type hat kein "class " Prefix, hat [assName] nur bei fremden Assemblies.
            this.relatedType = new ReflectedType(relType, assShortName).ILNameWithoutPrefix;
            if (relType.IsGenericType)
            {
                this.relatedType = this.relatedType.Substring(0, this.relatedType.IndexOf('<'));
            }

            object[] attrs = relationFieldInfo.GetCustomAttributes(typeof(ForeignKeyColumnAttribute), true);
            if (attrs.Length > 0)
            {
                this.foreignKeyColumnAttributes = new ForeignKeyColumnAttribute[attrs.Length];
                attrs.CopyTo(this.foreignKeyColumnAttributes, 0);
            }
            attrs = relationFieldInfo.GetCustomAttributes(typeof(ChildForeignKeyColumnAttribute), true);
            if (attrs.Length > 0)
            {
                this.childForeignKeyColumnAttributes = new ChildForeignKeyColumnAttribute[attrs.Length];
                attrs.CopyTo(this.childForeignKeyColumnAttributes, 0);
            }
            attrs = relationFieldInfo.GetCustomAttributes(typeof(MappingTableAttribute), true);
            if (attrs.Length > 0)
            {
                MappingTableAttribute = (MappingTableAttribute)attrs[0];
            }
        }