示例#1
0
        public void DefineProperties(ObjectInstance jsObject, Type type)
        {
            var bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;

            //register properties
            foreach (var property in type.GetProperties(bindingFlags)
                     .Where(p => p.GetCustomAttribute <JsHiddenAttribute>() == null))
            {
                var name = property.GetName();

                var jsProperty = new ClrProperty(jsObject.Engine, this, property);

                jsObject.DefineOwnProperty(name, jsProperty, false);
            }

            //register methods
            foreach (var methods in type
                     .GetMethods(bindingFlags)
                     .Where(p => p.GetCustomAttribute <JsHiddenAttribute>() == null)
                     .GroupBy(p => p.GetName()))
            {
                var methodsArray = methods.ToArray();
                var name         = methods.Key;
                if (name == "toString")
                {
                    continue;
                }

                var jsProperty = ClrMethodInfoFunc.Create(jsObject.Engine, this, name, methodsArray, jsObject);

                jsObject.DefineOwnProperty(name, jsProperty, false);
            }

            //register events
            foreach (var evt in type.GetEvents(bindingFlags)
                     .Where(p => p.GetCustomAttribute <JsHiddenAttribute>() == null))
            {
                var name       = evt.GetName().ToLowerInvariant();
                var jsProperty = new ClrEvent(jsObject.Engine, this, evt);
                jsObject.DefineOwnProperty(name, jsProperty, false);
            }


            DefineStatic(jsObject, type);
        }
示例#2
0
        private static ClrProperty[] GetProperties(DbTable table, DbTable[] tables)
        {
            var columns            = table.Columns;
            var collectionProperty = FindCollectionProperty(table, tables);

            ClrProperty[] properties;
            if (collectionProperty == null)
            {
                properties = new ClrProperty[columns.Length];
            }
            else
            {
                properties = new ClrProperty[columns.Length + 1];
                properties[properties.Length - 1] = collectionProperty;
            }

            // Table properties
            for (var i = 0; i < columns.Length; i++)
            {
                var column     = columns[i];
                var foreignKey = column.DbForeignKey;

                var type = Types[column.Type.Sequence];
                var name = NameProvider.GetPropertyName(column.Name, foreignKey != null);

                if (foreignKey != null)
                {
                    var classType = string.Empty;
                    var tableName = foreignKey.Table;
                    foreach (var t in tables)
                    {
                        if (t.Name == tableName)
                        {
                            classType = t.ClassName;
                            break;
                        }
                    }
                    type = ClrType.UserType(classType, !column.AllowNull);
                }

                properties[i] = new ClrProperty(type, name);
            }

            return(properties);
        }
示例#3
0
        /// <summary>
        /// 初始化属性信息
        /// </summary>
        private void InitPropertys()
        {
            List <ClrProperty> lstProperty = GetAllMember <ClrProperty>(_classType, false);

            _properties = new Dictionary <string, CodeElementPosition>();
            for (int j = 0; j < lstProperty.Count; j++)
            {
                object tm = lstProperty[j];

                ClrProperty property = tm as ClrProperty;
                if (property == null)
                {
                    continue;
                }
                foreach (CodeElementPosition cp in property.SourceCodePositions)
                {
                    _properties[property.Name] = cp;
                }
            }
        }
示例#4
0
        private static ClrProperty FindCollectionProperty(DbTable table, DbTable[] tables)
        {
            // Collection property for Normal table
            if (!table.IsReadOnly)
            {
                foreach (var current in tables)
                {
                    // Exclude self
                    if (table.Name == current.Name)
                    {
                        continue;
                    }
                    if (IsCollectionTable(current, table.Name))
                    {
                        return(ClrProperty.UserCollection(current.Name, current.ClassName));
                    }
                }
            }

            return(null);
        }
 public override int GetHashCode()
 {
     return(ClrProperty != null ? ClrProperty.GetHashCode() : 0);
 }
示例#6
0
 /// <summary>
 /// UI信息
 /// </summary>
 /// <param name="dicCheckItem">选中项</param>
 /// <param name="belongProperty">所属属性</param>
 public UIModelItem(ClrProperty belongProperty)
 {
     _belongProperty = belongProperty;
 }
示例#7
0
 public RecordField(ClrProperty Member, int Index)
 {
     this.Member   = Member;
     this.Position = Index;
 }