private void CollectInfoFromFields(IClassInfo classInfo, BindingFlags bindingFlags)
 {
     foreach (FieldInfo fieldInfo in classInfo.ClassType.GetFields(bindingFlags))
     {
         Collect(classInfo, fieldInfo.FieldType);
     }
 }
Exemple #2
0
        private ISyntaxInfo GetClassByName(ISyntaxInfos Infos, string s)
        {
            ISyntaxInfo info1 = Infos.FindByName(s, this.CaseSensitive);

            if (info1 == null)
            {
                foreach (IInterfaceInfo info2 in Infos)
                {
                    if (info2 is IClassInfo)
                    {
                        IClassInfo info3 = (IClassInfo)info2;
                        info1 = this.GetClassByName(info3.Classes, s);
                        if (info1 == null)
                        {
                            info1 = this.GetClassByName(info3.Interfaces, s);
                        }
                        if (info1 == null)
                        {
                            info1 = this.GetClassByName(info3.Structures, s);
                        }
                    }
                    if (info1 != null)
                    {
                        return(info1);
                    }
                }
            }
            return(info1);
        }
 private void CollectInfoFromMethods(IClassInfo classInfo)
 {
     CollectInfoFromMethods(classInfo, BindingFlags.Instance | BindingFlags.Public);
     CollectInfoFromMethods(classInfo, BindingFlags.Static | BindingFlags.Public);
     CollectInfoFromMethods(classInfo, BindingFlags.Instance | BindingFlags.NonPublic);
     CollectInfoFromMethods(classInfo, BindingFlags.Static | BindingFlags.NonPublic);
 }
        public void Get_Should_ExamineAllClassesFromAssemblies()
        {
            var assemblyFilter  = new Mock <IFilteredAssemblies>().Object;
            var classReaderMock = new Mock <IClassReader>();
            var c1      = new Mock <IClassInfo>().Object;
            var c2      = new Mock <IClassInfo>().Object;
            var classes = new IClassInfo[] { c1, c2 };

            classReaderMock.Setup(c => c.LoadFromAssemblies(assemblyFilter)).Returns(classes);
            var classInfoCollectorMock = new Mock <IClassInfoCollector>();
            var examinedClasses        = new List <IClassInfo>();

            classInfoCollectorMock.Setup(c => c.Examine(It.IsAny <IClassInfo>())).Callback <IClassInfo>(c => examinedClasses.Add(c));


            var sut = new ClassCollector(classReaderMock.Object, classInfoCollectorMock.Object);

            sut.Assemblies = assemblyFilter;

            var actualClasses = sut.Get().ToArray();

            Assert.IsTrue(examinedClasses.Count == 2);
            Assert.IsTrue(examinedClasses.Contains(c1));
            Assert.IsTrue(examinedClasses.Contains(c2));

            Assert.IsTrue(actualClasses.Length == 2);
            Assert.IsTrue(actualClasses.Contains(c1));
            Assert.IsTrue(actualClasses.Contains(c2));
        }
Exemple #5
0
 protected virtual void ProcessSection(ISyntaxInfo Info)
 {
     if (Info is IRangeInfo)
     {
         IRangeInfo info1 = (IRangeInfo)Info;
         if (info1.StartPoint.Y >= 0)
         {
             this.sections.Add(info1);
         }
         this.ProcessSections(info1.Regions);
         this.ProcessSections(info1.Comments);
     }
     if (Info is IInterfaceInfo)
     {
         IInterfaceInfo info2 = (InterfaceInfo)Info;
         this.ProcessSections(info2.Methods);
         this.ProcessSections(info2.Properties);
         this.ProcessSections(info2.Events);
     }
     if (Info is IClassInfo)
     {
         IClassInfo info3 = (IClassInfo)Info;
         this.ProcessSections(info3.Classes);
         this.ProcessSections(info3.Interfaces);
         this.ProcessSections(info3.Structures);
         this.ProcessSections(info3.Enums);
     }
     if (Info is IMethodInfo)
     {
         this.ProcessSections(((IMethodInfo)Info).Statements);
     }
     else if (Info is IPropInfo)
     {
         IPropInfo info4 = (ICsPropInfo)Info;
         if (info4.PropertyGet != null)
         {
             this.ProcessSection(info4.PropertyGet);
         }
         if (info4.PropertySet != null)
         {
             this.ProcessSection(info4.PropertySet);
         }
     }
     else if (Info is IEventInfo)
     {
         IEventInfo info5 = (ICsEventInfo)Info;
         if (info5.EventAdd != null)
         {
             this.ProcessSection(info5.EventAdd);
         }
         if (info5.EventRemove != null)
         {
             this.ProcessSection(info5.EventRemove);
         }
     }
     else if (Info is IAccessorInfo)
     {
         this.ProcessSections(((IAccessorInfo)Info).Statements);
     }
 }
Exemple #6
0
        public static string GenerateSqlSelect(Type type, int totalRows)
        {
            SetRandomSeed();
            SetFirstRowData();

            IClassInfo info = IQ.ClassInfo(type);

            string sql = "";

            for (int row = 0; row < totalRows; row++)
            {
                string rowSelect = "";
                foreach (var item in info.Fields)
                {
                    object value;
                    if (row == 0)
                    {
                        value = GetAsSqlSelect(SampleData[item.ReturnType]);
                    }
                    else
                    {
                        value = GetRandomSQLData(item.ReturnType);
                    }
                    rowSelect += (rowSelect == "" ? "" : ",") + value + " as " + item.SqlName;
                }
                rowSelect += "," + row.ToString() + " as rowOrder";
                sql       += (sql == ""?"":" union ") + "select " + rowSelect;
            }
            return(sql + " order by rowOrder");
        }
 private void Add(IClassInfo classInfo, Type type)
 {
     if (!_classes.ContainsKey(type))
     {
         _classes.Add(type, classInfo);
     }
 }
Exemple #8
0
        public bool Delete(object obj, IQueryOptions options = null)
        {
            IQueryBuilder <object> query     = FromPrimaryKey(obj, options);
            IClassInfo             classInfo = query.ClassInfo;

            if (ClassInfo.IsNew(obj))
            {
                throw new InvalidOperationException("The object in question has a default-valued primary key, you can't delete it.");
            }
            if (!classInfo.DoEvent(obj, IQEventType.BeforeDelete, this))
            {
                return(false);
            }

            bool success = query.Delete() > 0;

            if (success)
            {
                classInfo.PrimaryKeyField.SetValue(obj, classInfo.PrimaryKeyDefaultValue);
            }

            if (!classInfo.DoEvent(obj, IQEventType.OnDelete, this))
            {
                throw new InvalidOperationException("The operation was cancelled after the database query was executed.");
            }

            return(success);
        }
 private void CollectFromParameters(IClassInfo classInfo, ParameterInfo[] parameters)
 {
     foreach (ParameterInfo parameterInfo in parameters)
     {
         Collect(classInfo, parameterInfo.ParameterType);
     }
 }
Exemple #10
0
 public ObjectInfo(IQEventType eventType, IDbContext queryController, IObjectData data, IClassInfo info, object obj)
 {
     EventType       = eventType;
     QueryController = queryController;
     ObjectData      = data;
     ClassInfo       = info;
     Source          = obj;
 }
Exemple #11
0
 public ObjectInfo(IQEventType eventType,IDbContext queryController, IObjectData data, IClassInfo info, object obj)
 {
     EventType = eventType;
     QueryController = queryController;
     ObjectData = data;
     ClassInfo = info;
     Source = obj;
 }
 private void CollectClassInfoFromConstructors(IClassInfo classInfo, BindingFlags bindingFlags)
 {
     foreach (ConstructorInfo constructorInfo in classInfo.ClassType.GetConstructors(bindingFlags))
     {
         CollectFromParameters(classInfo, constructorInfo.GetParameters());
         CollectFromMethodBody(classInfo, constructorInfo.GetMethodBody());
     }
 }
Exemple #13
0
		/// <summary>
		/// Creates instance of class
		/// </summary>
		/// <remarks>
		/// Putting null by stateComponents means work with current object state
		/// </remarks>
		internal SClass( IClassInfo objectInstance, ClassNode classNode, string[] stateComponents )
		{
			m_object = objectInstance;
			m_Class = classNode;

			defineStateMask( stateComponents );
			defineStateName();
		}
 private void CollectInfoFromMethods(IClassInfo classInfo, BindingFlags bindingFlags)
 {
     foreach (MethodInfo methodInfo in classInfo.ClassType.GetMethods(bindingFlags))
     {
         Collect(classInfo, methodInfo.ReturnType);
         CollectFromParameters(classInfo, methodInfo.GetParameters());
         CollectFromMethodBody(classInfo, methodInfo.GetMethodBody());
     }
 }
Exemple #15
0
 public IdProperty(IClassInfo classInfo, string name, string generatorClass) : base(classInfo, name)
 {
     TagName = "Id";
     Add("generator", generatorClass);
     GeneratorParams = new Property(classInfo, generatorClass)
     {
         TagName = "generator"
     };
 }
Exemple #16
0
        protected IClassInfo GetClassInfo(object obj)
        {
            IClassInfo classInfo = IQ.ClassInfo(obj.GetType());

            if (!classInfo.IsBound)
            {
                throw new KeyNotFoundException(String.Format("The type '{0}' is not bound.", obj.GetType()));
            }
            return(classInfo);
        }
Exemple #17
0
        public static bool IsNew(object obj)
        {
            IClassInfo cinfo = IQ.MapperCache.GetClassInfo(obj.GetType());

            if (!cinfo.IsBound)
            {
                throw new InvalidOperationException("The object is not a bound IQClass");
            }
            return(cinfo.PrimaryKeyField.GetValue(obj).Equals(cinfo.PrimaryKeyDefaultValue));
        }
        private void Collect(IClassInfo classType, Type type)
        {
            if (type.IsGenericParameter || type == typeof(void))
            {
                return;
            }
            var referencedClass = Get(type);

            classType.AddReferencedClass(referencedClass);
        }
 private void CollectFromMethodBody(IClassInfo classInfo, MethodBody methodBody)
 {
     if (methodBody != null)
     {
         foreach (LocalVariableInfo localVariable in methodBody.LocalVariables)
         {
             Collect(classInfo, localVariable.LocalType);
         }
     }
 }
 public void Examine(IClassInfo classInfo)
 {
     if (_classes.ContainsKey(classInfo.ClassType))
     {
         return;
     }
     CollectInfoFromConstructors(classInfo);
     CollectInfoFromFields(classInfo);
     CollectInfoFromMethods(classInfo);
     Add(classInfo, classInfo.ClassType);
 }
Exemple #21
0
 private void AddCodeMembers(IListMembers Provider, IInterfaceInfo Info, bool IsStatic)
 {
     this.AddCodeMembers(Info.Properties, Provider);
     this.AddCodeMembers(Info.Methods, Provider);
     this.AddCodeMembers(Info.Events, Provider);
     if (Info is IClassInfo)
     {
         IClassInfo info1 = (IClassInfo)Info;
         this.AddCodeMembers(info1.Fields, Provider);
         this.AddCodeMembers(info1.Enums, Provider);
         this.AddCodeMembers(info1.Delegates, Provider);
     }
 }
Exemple #22
0
        public static bool IsTracked(object obj)
        {
            IClassInfo cinfo = IQ.MapperCache.GetClassInfo(obj.GetType());

            if (cinfo.Track)
            {
                return(true);
            }
            else
            {
                IObjectData dbData;
                return(IQ.MapperCache.TryGetObjectData(obj, out dbData));
            }
        }
Exemple #23
0
        public static IDataReader GenerateFakeDataReader(Type type, int rows)
        {
            SetRandomSeed();
            SetFirstRowData();

            IClassInfo info = IQ.ClassInfo(type);

            TestDataReader reader = new TestDataReader();

            foreach (var item in info.Fields)
            {
                reader.AddFieldToMock(item.SqlName, item.ReturnType);
            }
            reader.Generate(rows);
            return(reader);
        }
Exemple #24
0
 public Component(IClassInfo classInfo, string name) : base(classInfo, name)
 {
     TagName = "component";
 }
Exemple #25
0
 public void AddConductedClass(IClassInfo conductedClass)
 {
     this.conductedClasses.Add(conductedClass);
 }
 private void CollectInfoFromConstructors(IClassInfo classInfo)
 {
     CollectClassInfoFromConstructors(classInfo, BindingFlags.Instance | BindingFlags.Public);
     CollectClassInfoFromConstructors(classInfo, BindingFlags.Instance | BindingFlags.NonPublic);
 }
Exemple #27
0
 public void AddReferencedClass(IClassInfo referencedClass)
 {
     _classWrapper.AddReferencedClass(referencedClass);
 }
Exemple #28
0
 public Map(IClassInfo classInfo, string name) : base(classInfo, name)
 {
     TagName = "map";
 }
Exemple #29
0
 public Property(IClassInfo classInfo, string name)
 {
     ClassInfo = classInfo;
     Name      = name;
 }
Exemple #30
0
 public MarkUnitInterface(IClassInfo classWrapper)
 {
     _classWrapper = classWrapper;
 }
Exemple #31
0
 public void AddConductedClass(IClassInfo conductedClass)
 {
     this.conductedClasses.Add(conductedClass);
 }
Exemple #32
0
		/// <summary>
		/// Creates instance of class
		/// </summary>
		internal SClass( IClassInfo objectInstance, ClassNode classNode )
			: this( objectInstance, classNode, null )
		{
		}
Exemple #33
0
 private IClassInfo Examine(IClassInfo classInfo)
 {
     _classInfoCollector.Examine(classInfo);
     return(classInfo);
 }
Exemple #34
0
		public NoClassInformationException( IClassInfo obj )
			: base( "There's no information about specified object in the schema." )
		{
			m_Obj = obj;
		}
Exemple #35
0
		/// <summary>
		/// Gets description for object in specified state
		/// </summary>
		/// <remarks>
		/// Putting null by stateComponents means work with current object state
		/// </remarks>
		public SClass this[ IClassInfo instance, string[] stateComponents ]
		{
			get {
				if( instance == null )
					throw new ArgumentNullException( "instance" );

				if( m_Classes.Contains( instance.Type ) )
					return new SClass( instance, m_Classes[ instance.Type ], stateComponents );
				else
					throw new NoClassInformationException( instance );
			}
		}
Exemple #36
0
		/// <summary>
		/// Gets object description.
		/// </summary>
		public SClass this[ IClassInfo instance ]
		{
			get
			{
				return this[ instance, null ];
			}
		}
Exemple #37
0
 public ClassInfoVM(IClassInfo ci, TreeViewItemViewModel parent) : base(parent, true)
 {
     this.ci = ci;
 }