Пример #1
0
		public ColumnInfo( ObjectMap objectMap, string[] columnNames )
		{
			this.columnNames = columnNames;
			columnComboHashCode = ObjectConstructor.GetFieldComboHashCode( columnNames );
			fields = new FieldList();
			for( int i = 0; i < columnNames.Length; i++ )
			{
				string columnName = columnNames[ i ];
				FieldMap fm = objectMap.GetFieldMapFromColumn( columnName );
				if( fm == null )
				{
					// check for column names with table name prefixes
					int pos = columnName.IndexOf( '.' );
					if( pos > 0 )
					{
						columnName = columnName.Substring( pos + 1, columnName.Length - pos - 1 );
						fm = objectMap.GetFieldMapFromColumn( columnName );
						if( fm != null )
						{
							columnNames[ i ] = columnName;
						}
					}
					if( fm == null ) // no corresponding member could be found - assume column is calculated
					{
						columnCalculatedMask |= 1 << i;
					}
				}
				fields.Add( fm ); // intentionally add null entries to preserve column order 
			}
		}
Пример #2
0
        public void ObjectMap_ReadDataOfT_WithNullIndexCache()
        {
            var fieldDefinitions = PersistenceMap.Factories.TypeDefinitionFactory.GetFieldDefinitions<OneTwoThree>();

            var map = new ObjectMap(new Settings());
            var item = map.ReadData<OneTwoThree>(_dataReader.Object, fieldDefinitions.ToArray(), null);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.One, "Value one");
            Assert.AreEqual(item.Two, "Value two");
            Assert.AreEqual(item.Three, "Value three");
        }
Пример #3
0
        public void ObjectMap_ReadDataOfT()
        {
            var fieldDefinitions = PersistenceMap.Factories.TypeDefinitionFactory.GetFieldDefinitions<OneTwoThree>();

            var indexCache = new Dictionary<string, int>
            {
                {"One", 0 },
                {"Two", 1 },
                {"Three", 2 }
            };

            var map = new ObjectMap(new Settings());
            var item = map.ReadData<OneTwoThree>(_dataReader.Object, fieldDefinitions.ToArray(), indexCache);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.One, "Value one");
            Assert.AreEqual(item.Two, "Value two");
            Assert.AreEqual(item.Three, "Value three");
        }
Пример #4
0
        public void ObjectMap_ReadData()
        {
            var objectDefinitions = new List<ObjectDefinition>
            {
                new ObjectDefinition { Name = "One", ObjectType = typeof(string) },
                new ObjectDefinition { Name = "Two", ObjectType = typeof(string) },
                new ObjectDefinition { Name = "Three", ObjectType = typeof(string) }
            };

            var indexCache = new Dictionary<string, int>
            {
                {"One", 0 },
                {"Two", 1 },
                {"Three", 2 }
            };

            var map = new ObjectMap(new Settings());
            var items = map.ReadData(_dataReader.Object, objectDefinitions, indexCache);

            Assert.IsNotNull(items);
            Assert.AreEqual(items["One"], "Value one");
            Assert.AreEqual(items["Two"], "Value two");
            Assert.AreEqual(items["Three"], "Value three");
        }
Пример #5
0
        public void ObjectMap_ReadData_WithNullIndexCache()
        {
            var objectDefinitions = new List<ObjectDefinition>
            {
                new ObjectDefinition { Name = "One", ObjectType = typeof(string) },
                new ObjectDefinition { Name = "Two", ObjectType = typeof(string) },
                new ObjectDefinition { Name = "Three", ObjectType = typeof(string) }
            };

            var map = new ObjectMap(new Settings());
            var items = map.ReadData(_dataReader.Object, objectDefinitions, null);

            Assert.IsNotNull(items);
            Assert.AreEqual(items["One"], "Value one");
            Assert.AreEqual(items["Two"], "Value two");
            Assert.AreEqual(items["Three"], "Value three");
        }
Пример #6
0
        public void ObjectMap_ReadData_RestrictiveMode_Success()
        {
            var objectDefinitions = new List<ObjectDefinition>
            {
                new ObjectDefinition { Name = "Three", ObjectType = typeof(string) }
            };

            var map = new ObjectMap(new Settings { RestrictiveMappingMode = RestrictiveMode.ThrowException });
            var items = map.ReadData(_dataReader.Object, objectDefinitions, new Dictionary<string, int>());

            Assert.IsNotNull(items["Three"]);
        }
Пример #7
0
        public void ObjectMap_ReadData_RestrictiveMode_Fail()
        {
            var objectDefinitions = new List<ObjectDefinition>
            {
                new ObjectDefinition { Name = "Four", ObjectType = typeof(string) }
            };

            var map = new ObjectMap(new Settings { RestrictiveMappingMode = RestrictiveMode.ThrowException });
            Assert.Throws<InvalidMapException>(() => map.ReadData(_dataReader.Object, objectDefinitions, new Dictionary<string, int>()));
        }
Пример #8
0
        public void ObjectMap_ReadData_FalseField()
        {
            var objectDefinitions = new List<ObjectDefinition>
            {
                new ObjectDefinition { Name = "Four", ObjectType = typeof(string) }
            };

            var map = new ObjectMap(new Settings());
            var items = map.ReadData(_dataReader.Object, objectDefinitions, new Dictionary<string, int>());

            Assert.IsNull(items["Four"]);
        }
Пример #9
0
        public void ObjectMap_ReadDataOfT_WithUnequalFieldsMembers_EmptyIndexCache()
        {
            _dataReader.Setup(o => o.GetName(It.Is<int>(i => i == 0))).Returns("FieldOne");
            _dataReader.Setup(o => o.GetName(It.Is<int>(i => i == 1))).Returns("FieldTwo");
            _dataReader.Setup(o => o.GetName(It.Is<int>(i => i == 2))).Returns("FieldThree");

            var fieldDefinitions = PersistenceMap.Factories.TypeDefinitionFactory.GetFieldDefinitions<OneTwoThree>().ToList();
            fieldDefinitions[0].FieldName = "FieldOne";
            fieldDefinitions[1].FieldName = "FieldTwo";
            fieldDefinitions[2].FieldName = "FieldThree";

            var indexCache = new Dictionary<string, int>();

            var map = new ObjectMap(new Settings());
            var item = map.ReadData<OneTwoThree>(_dataReader.Object, fieldDefinitions.ToArray(), indexCache);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.One, "Value one");
            Assert.AreEqual(item.Two, "Value two");
            Assert.AreEqual(item.Three, "Value three");

            Assert.IsTrue(indexCache.Count == 3);
        }
Пример #10
0
 /// <summary>
 /// Creates a new instance of the <c>DfaState</c> class.
 /// </summary>
 /// <param name="index">Index in the DFA state table.</param>
 /// <param name="acceptSymbol">Symbol to accept.</param>
 /// <param name="transitionVector">Transition vector.</param>
 public DfaState(int index, Symbol acceptSymbol, ObjectMap transitionVector)
 {
     m_index = index;
     m_acceptSymbol = acceptSymbol;
     m_transitionVector = transitionVector;
 }
Пример #11
0
 private static T GetReference <T>(ObjectMap map, object key)
 {
     return((key == null) ? default(T) : map.Get <T>(key));
 }
 public DataReaderPropertySetters(DbDataReader dr, ObjectMap <T> map)
 {
     objectMap = map;
     setters   = new List <PropertySetter <T> >();
     getPropertySetters(dr);
 }
Пример #13
0
 public LiveReportFactory(ObjectMap objectMap)
 {
     this.objectMap = objectMap;
 }
Пример #14
0
        public override BaseResponse GenerateResponse()
        {
            GetGameObjectResponse getGOResponse = new GetGameObjectResponse();

            Transform foundTransform = TransformHelper.GetFromPath(gameObjectPath);

            getGOResponse.GameObjectName = foundTransform.name;

            List <Object> components = new List <Object>(foundTransform.GetComponents <Component>());

            // Not technically a component, but include the GameObject
            components.Insert(0, foundTransform.gameObject);
            getGOResponse.Components = new List <ComponentDescription>(components.Count);
            foreach (Object component in components)
            {
                //Guid guid = ObjectMap.AddOrGetObject(component);
                ObjectMap.AddOrGetObject(component);

                ComponentDescription description = new ComponentDescription(component);
                Type componentType = component.GetType();

                if ((flags & InfoFlags.Fields) == InfoFlags.Fields)
                {
                    FieldInfo[] fieldInfos = componentType.GetFields(BINDING_FLAGS);
                    foreach (FieldInfo fieldInfo in fieldInfos)
                    {
                        if (TypeUtility.IsBackingField(fieldInfo, componentType))
                        {
                            // Skip backing fields for auto-implemented properties
                            continue;
                        }

                        object objectValue = fieldInfo.GetValue(component);

                        WrappedVariable wrappedVariable = new WrappedVariable(fieldInfo, objectValue);
                        description.Fields.Add(wrappedVariable);
                    }
                }

                if (component is GameObject) // Special handling for GameObject.name to always be included
                {
                    PropertyInfo    nameProperty = componentType.GetProperty("name", BindingFlags.Public | BindingFlags.Instance);
                    WrappedVariable wrappedName  = new WrappedVariable(nameProperty, nameProperty.GetValue(component, null));
                    description.Properties.Add(wrappedName);
                }

                if ((flags & InfoFlags.Properties) == InfoFlags.Properties)
                {
                    PropertyInfo[] properties = componentType.GetProperties(BINDING_FLAGS);
                    foreach (PropertyInfo property in properties)
                    {
                        Type declaringType = property.DeclaringType;
                        if (declaringType == typeof(Component) ||
                            declaringType == typeof(UnityEngine.Object))
                        {
                            continue;
                        }

                        object[] attributes          = property.GetCustomAttributes(false);
                        bool     isObsoleteWithError = AttributeHelper.IsObsoleteWithError(attributes);
                        if (isObsoleteWithError)
                        {
                            continue;
                        }

                        // Skip properties that cause exceptions at edit time
                        if (Application.isPlaying == false)
                        {
                            if (typeof(MeshFilter).IsAssignableFrom(declaringType))
                            {
                                if (property.Name == "mesh")
                                {
                                    continue;
                                }
                            }

                            if (typeof(Renderer).IsAssignableFrom(declaringType))
                            {
                                if (property.Name == "material" || property.Name == "materials")
                                {
                                    continue;
                                }
                            }
                        }



                        string propertyName = property.Name;

                        MethodInfo getMethod = property.GetGetMethod(true);
                        if (getMethod != null)
                        {
                            MethodImplAttributes methodImplAttributes = getMethod.GetMethodImplementationFlags();
#pragma warning disable RECS0016 // Bitwise operation on enum which has no [Flags] attribute
                            if ((methodImplAttributes & MethodImplAttributes.InternalCall) != 0)
#pragma warning restore RECS0016 // Bitwise operation on enum which has no [Flags] attribute
                            {
                                continue;
                            }


                            object objectValue = getMethod.Invoke(component, null);

                            WrappedVariable wrappedVariable = new WrappedVariable(property, objectValue);
                            description.Properties.Add(wrappedVariable);
                        }
                    }
                }

                if ((flags & InfoFlags.Methods) == InfoFlags.Methods)
                {
                    MethodInfo[] methodInfos = componentType.GetMethods(BINDING_FLAGS);
                    foreach (var methodInfo in methodInfos)
                    {
                        if (TypeUtility.IsPropertyMethod(methodInfo, componentType))
                        {
                            // Skip automatically generated getter/setter methods
                            continue;
                        }

                        MethodImplAttributes methodImplAttributes = methodInfo.GetMethodImplementationFlags();
#pragma warning disable RECS0016 // Bitwise operation on enum which has no [Flags] attribute
                        if ((methodImplAttributes & MethodImplAttributes.InternalCall) != 0)
#pragma warning restore RECS0016 // Bitwise operation on enum which has no [Flags] attribute
                        {
                            continue;
                        }
                        WrappedMethod wrappedMethod = new WrappedMethod(methodInfo);
                        description.Methods.Add(wrappedMethod);
                    }
                }

                getGOResponse.Components.Add(description);
            }
            return(getGOResponse);
        }