Exemplo n.º 1
0
 protected override void CheckInherits(TypeUsageInfo info)
 {
     if (info.IsClass)
     {
         throw new ArgumentOutOfRangeException("info", "Trying inherits from class");
     }
 }
Exemplo n.º 2
0
 protected override void CheckInherits(TypeUsageInfo info)
 {
     if (info.IsClass && Inherits.Any(t => t.IsClass))
     {
         throw new ArgumentOutOfRangeException("info", "Trying inherits from multiply classes");
     }
 }
Exemplo n.º 3
0
 protected override void CheckInherits(TypeUsageInfo info)
 {
     if (info.IsClass)
     {
         throw new ArgumentOutOfRangeException("info", "Trying inherits from class");
     }
 }
Exemplo n.º 4
0
 public static TypeUsageInfo CreateArray(TypeUsageInfo elementType, int arrayRank)
 {
     return(new TypeUsageInfo(elementType.Name, elementType.Namespace, elementType.ShortName,
                              elementType._configuration, new[] { elementType })
     {
         ArrayRank = arrayRank
     });
 }
Exemplo n.º 5
0
 public static TypeUsageInfo CreateNullable(TypeUsageInfo elementType)
 {
     if (!elementType.IsValueType)
     {
         return(elementType);
     }
     return(new TypeUsageInfo(elementType.Name, elementType.Namespace, elementType.ShortName,
                              elementType._configuration | TypeUsageInfoConfiguration.Nullable,
                              new[] { elementType }));
 }
Exemplo n.º 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public PropertyInfo(string name, TypeUsageInfo type, PropertyInvokerInfo getter, PropertyInvokerInfo setter = null)
        {
            Contract.Requires(type != null);
            Contract.Requires(getter != null || setter != null);

            Name = name;
            Type = type;
            Getter = getter;
            Setter = setter;
        }
Exemplo n.º 7
0
 public static TypeUsageInfo CreateNullable(TypeUsageInfo elementType)
 {
     if (!elementType.IsValueType)
     {
         return elementType;
     }
     return new TypeUsageInfo(elementType.Name, elementType.Namespace, elementType.ShortName,
         elementType._configuration | TypeUsageInfoConfiguration.Nullable,
         new[] {elementType});
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public PropertyInfo(string name, TypeUsageInfo type, PropertyInvokerInfo getter, PropertyInvokerInfo setter = null)
        {
            Contract.Requires(type != null);
            Contract.Requires(getter != null || setter != null);

            Name   = name;
            Type   = type;
            Getter = getter;
            Setter = setter;
        }
Exemplo n.º 9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 private TypeUsageInfo(string name, string typeNamespace, string shortName,
     TypeUsageInfoConfiguration configuration = TypeUsageInfoConfiguration.Class,
     TypeUsageInfo[] typeParameters = null,
     TypeArgumentConfiguration typeArgumentConfiguration = null)
     : base(name, typeNamespace)
 {
     _configuration = configuration;
     Namespace = typeNamespace;
     ShortName = shortName;
     TypeArgumentConfiguration = typeArgumentConfiguration;
     TypeArguments = typeParameters ?? new TypeUsageInfo[0];
 }
Exemplo n.º 10
0
        internal MSSQLTypeDesc(short typeIndex, NativeTypes baseType, string name, TypeOptions options,
            TypeUsageInfo typeInfo)
        {
            Contract.Requires(typeIndex > 256);
            Contract.Requires(typeInfo != null);
            
            Id = typeIndex;
            BaseType = baseType;
            IsDerived = Id != (short) BaseType;

            Name = name;
            Options = options;
            TypeInfo = typeInfo;
        }
Exemplo n.º 11
0
 public virtual void InheritsFrom(TypeUsageInfo info)
 {
     if (Inherits.Any(t => t.Equals(info)))
     {
         throw new ArgumentOutOfRangeException("info", string.Format("Type already inherits from this type {0}", info));
     }
     if (IsGeneric && info.IsGeneric)
     {
         if (info.TypeArguments.Where(t => t.IsTypeArgument).Any(t => !TypeArguments.Contains(t)))
         {
             throw new ArgumentOutOfRangeException("info", string.Format("Trying inherit from type {0} with unknown type argument", info));
         }
     }
     CheckInherits(info);
     _inherits.Add(info);
 }
Exemplo n.º 12
0
        private static TypeUsageInfo CreateTypeUsageInfo(Type type, TypeUsageInfo[] typeArguments = null, string shortName = null)
        {
            var name = type.Name;

            if (type.IsGenericTypeDefinition)
            {
                var index = name.IndexOf('`');
                if (index != -1)
                {
                    name = name.Substring(0, index);
                }
            }
            var typeNamespace = type.Namespace;

            if (type.IsEnum)
            {
                return(TypeUsageInfo.CreateEnum(name, typeNamespace));
            }

            if (type.IsGenericTypeDefinition && (typeArguments == null ||
                                                 type.GetGenericArguments().Length != typeArguments.Length))
            {
                throw new ArgumentOutOfRangeException("typeArguments");
            }

            if (type.IsClass)
            {
                return(TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.Class, shortName, typeArguments));
            }
            if (type.IsInterface)
            {
                return(TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.Interface, shortName, typeArguments));
            }
            if (type.IsValueType)
            {
                return(TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.ValueType, shortName, typeArguments));
            }
            throw new NotSupportedException(string.Format("Can't convert type '{0}' to TypeUsageInfo", type.FullName));
        }
Exemplo n.º 13
0
 private static TypeUsageInfo GenerateTypeUsageInfo(this Type type, string shortName)
 {
     Contract.Requires(type != null);
     Contract.Requires(!type.IsGenericTypeDefinition);
     #region Array
     if (type.IsArray)
     {
         var arrayRank = type.GetArrayRank();
         type = type.GetElementType();
         return(TypeUsageInfo.CreateArray(type.ToUsageInfo(), arrayRank));
     }
     #endregion
     #region Nullable
     if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
     {
         type = type.GetGenericArguments()[0];
         return(TypeUsageInfo.CreateNullable(type.ToUsageInfo()));
     }
     #endregion
     var typeParameters = type.IsGenericType ? type.GetGenericArguments().Select(ToUsageInfo).ToArray() : null;
     return(CreateTypeUsageInfo(type.IsGenericType ? type.GetGenericTypeDefinition() : type, typeParameters, shortName));
 }
Exemplo n.º 14
0
        private static TypeUsageInfo CreateTypeUsageInfo(Type type, TypeUsageInfo[] typeArguments = null, string shortName = null)
        {
            var name = type.Name;
            if (type.IsGenericTypeDefinition)
            {
                var index= name.IndexOf('`');
                if (index != -1)
                {
                    name = name.Substring(0, index);
                }
            }
            var typeNamespace = type.Namespace;

            if (type.IsEnum)
            {
                return TypeUsageInfo.CreateEnum(name, typeNamespace);
            }

            if (type.IsGenericTypeDefinition && (typeArguments == null ||
                                                 type.GetGenericArguments().Length != typeArguments.Length))
            {
                throw new ArgumentOutOfRangeException("typeArguments");
            }

            if (type.IsClass)
            {
                return TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.Class, shortName, typeArguments);
            }
            if (type.IsInterface)
            {
                return TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.Interface, shortName, typeArguments);
            }
            if (type.IsValueType)
            {
                return TypeUsageInfo.Create(name, typeNamespace, TypeUsageInfoConfiguration.ValueType, shortName, typeArguments);
            }
            throw new NotSupportedException(string.Format("Can't convert type '{0}' to TypeUsageInfo", type.FullName));
        }
Exemplo n.º 15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 public PropertyInfo(string name, TypeUsageInfo type, bool isReadOnly = false)
     : this(name, type, new PropertyInvokerInfo(), new PropertyInvokerInfo {Accessibility = isReadOnly ? AccessibilityLevels.Private : AccessibilityLevels.Public})
 {
 }
Exemplo n.º 16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 public PropertyInfo(string name, TypeUsageInfo type, bool isReadOnly = false)
     : this(name, type, new PropertyInvokerInfo(), new PropertyInvokerInfo {
     Accessibility = isReadOnly ? AccessibilityLevels.Private : AccessibilityLevels.Public
 })
 {
 }
Exemplo n.º 17
0
 internal static void AddHasTitleProperty(TypeUsageInfo ihastitle, EntityInfo entity, TableContent tableContent)
 {
     var prop = new PropertyInfo("EntityTitle", new FieldInfo("EntityTitle", (typeof(string)).ToUsageInfo()),
         new PropertyInvokerInfo(string.Format("return {0}.ToString();", tableContent.TitleFieldName)),
         null);
     prop.ExplicitInterface = ihastitle;
     entity.AddProperty(prop);
 }
Exemplo n.º 18
0
        internal static void AddChangeDateProperty(PropertyInfo createDateProperty, PropertyInfo changeDateProperty,
            TypeUsageInfo iintervalfields, EntityInfo entity)
        {
            var getter = string.Format("return {0};", changeDateProperty.Name);
            if(changeDateProperty.Type.IsNullable)
            {
                var createPropertyGetter = createDateProperty.Name;
                if (createDateProperty.Type.IsNullable)
                {
                    createPropertyGetter = createDateProperty.Name + " ?? DateTime.Now";
                }

                getter = string.Format("if({0}.HasValue) return {0}.Value; else return {1};",
                    changeDateProperty.Name, createPropertyGetter);
            }
            var prop = new PropertyInfo(changeDateProperty.Name, (typeof(DateTime)).ToUsageInfo(),
                new PropertyInvokerInfo(getter),
                new PropertyInvokerInfo(string.Format("{0} = value;",
                    changeDateProperty.Name)));
            prop.ExplicitInterface = iintervalfields;
            entity.AddProperty(prop);
        }
Exemplo n.º 19
0
 internal static TypeUsageInfo Create(string name, string typeNamespace, TypeUsageInfoConfiguration configuration, string shortName = null, TypeUsageInfo[] typeArguments = null)
 {
     return new TypeUsageInfo(name, typeNamespace, shortName, configuration, typeArguments);
 }
Exemplo n.º 20
0
 public static TypeUsageInfo CreateValueType(string name, string typeNamespace, TypeUsageInfo[] typeArguments = null)
 {
     return new TypeUsageInfo(name, typeNamespace, null, TypeUsageInfoConfiguration.ValueType, typeArguments);
 }
Exemplo n.º 21
0
 internal static void AddExplicitProperty(PropertyInfo property, TypeUsageInfo iintervalfields, EntityInfo entity)
 {
     if (property.Type.IsNullable)
     {
         return;
     }
     var prop = new PropertyInfo(property.Name, TypeUsageInfo.CreateNullable(property.Type),
         new PropertyInvokerInfo(string.Format("return {0};", property.Name)),
         new PropertyInvokerInfo(string.Format("if(value.HasValue){0} = value.Value; else throw new ArgumentNullException(\"value\");", property.Name)));
     prop.ExplicitInterface = iintervalfields;
     entity.AddProperty(prop);
 }
Exemplo n.º 22
0
 public static TypeUsageInfo CreateArray(TypeUsageInfo elementType, int arrayRank)
 {
     return new TypeUsageInfo(elementType.Name, elementType.Namespace, elementType.ShortName,
         elementType._configuration, new[] {elementType}) {ArrayRank = arrayRank};
 }
Exemplo n.º 23
0
 public static TypeUsageInfo CreateInterface(string name, string typeNamespace, TypeUsageInfo[] typeParameters = null)
 {
     return new TypeUsageInfo(name, typeNamespace, null, TypeUsageInfoConfiguration.Interface, typeParameters);
 }
Exemplo n.º 24
0
 public SimplePropertyEntityInfo(string name, TypeUsageInfo type)
     : base(name, type)
 {
     IncludeToShallowCopy = true;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 private NavigationPropertyEntityInfo(string name, TypeUsageInfo type, TypeUsageInfo initializeType)
     : base(name, type, false)
 {
     IsVirtual = true;
     InitializeType = initializeType;
 }
Exemplo n.º 26
0
 protected abstract void CheckInherits(TypeUsageInfo info);