Exemplo n.º 1
0
        private void SetupSyncElements <T>(IList <string> fieldNames, Dictionary <string, FieldInfo> cacheInfos, List <T> elementList) where T : LiteNetLibElement
        {
            if (fieldNames == null || fieldNames.Count == 0)
            {
                return;
            }

            foreach (string fieldName in fieldNames)
            {
                // Get field info
                tempFieldKey = TypeName + "_" + fieldName;
                if (!cacheInfos.TryGetValue(tempFieldKey, out tempField))
                {
                    tempField = ClassType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                    cacheInfos[tempFieldKey] = tempField;
                }
                if (tempField == null)
                {
                    Debug.LogWarning("Element named " + fieldName + " was not found");
                    continue;
                }
                try
                {
                    T    element   = (T)tempField.GetValue(this);
                    byte elementId = Convert.ToByte(elementList.Count);
                    element.Setup(this, elementId);
                    elementList.Add(element);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }
        }
Exemplo n.º 2
0
 private void SetupSyncElements <T>(List <string> fieldNames, Dictionary <string, FieldInfo> cache, List <T> elementList) where T : LiteNetLibElement
 {
     elementList.Clear();
     foreach (var fieldName in fieldNames)
     {
         var       key = TypeName + "_" + fieldName;
         FieldInfo field;
         if (!cache.TryGetValue(key, out field))
         {
             field      = ClassType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
             cache[key] = field;
         }
         if (field == null)
         {
             Debug.LogWarning("Element named " + fieldName + " was not found");
             continue;
         }
         try
         {
             var element   = (T)field.GetValue(this);
             var elementId = Convert.ToByte(elementList.Count);
             element.Setup(this, elementId);
             elementList.Add(element);
         }
         catch (Exception ex)
         {
             Debug.LogException(ex);
         }
     }
 }
Exemplo n.º 3
0
        private void CompileNextFieldDefinition(LexList theLexList, Type varType)
        {
            string varId = theLexList.GetIdentifier("Expected the name of the field here.");

            MostRecentNameAdded = varId;
            theLexList.CheckStr(";", "Expected a ; here");
            if (MadeFieldsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field already defined.");
            }
            if (CompileMethodsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field name already used as a method name.");
            }
            MadeFieldsDict.Add(varId, new MadeField()
            {
                VarName = varId, VarType = varType, Index = MadeFieldsDict.Count
            });
            FieldInfo fi = ClassType.GetField("Fields", BindingFlags.Public | BindingFlags.Instance);

            if (fi == null)
            {
                theLexList.ThrowException("Can only add fields to a class that has a 'List<Object> Fields' field.");
            }
            if (fi.FieldType != typeof(List <object>))
            {
                theLexList.ThrowException("Can only add fields to a class where its Fields field is of type List<object>.");
            }
            theLexList.Next();
        }
Exemplo n.º 4
0
        private void InitFieldsFromConstructor(ClassType where, List <MethodVarInfo> args)
        {
            foreach (var item in args)
            {
                LoadThis();
                LoadToStack(item);

                //var field = new VarInfo(item.Name, item.Type, VarLocation.Global);

                Assign(where.GetField(item.Name));
            }
        }
Exemplo n.º 5
0
        /// <summary> 表示一个可以获取或者设置其内容的对象属性
        /// </summary>
        /// <param name="property">属性信息</param>
        private ObjectProperty(PropertyInfo property)
        {
            Field        = false;
            MemberInfo   = property;               //属性信息
            OriginalType = property.PropertyType;
            var get = property.GetGetMethod(true); //获取属性get方法,不论是否公开
            var set = property.GetSetMethod(true); //获取属性set方法,不论是否公开

            if (set != null && //set方法不为空
                property.GetIndexParameters().Length == 0)
            {
                CanWrite = true;         //属性可写
                Static   = set.IsStatic; //属性是否为静态属性
                IsPublic = set.IsPublic;
            }
            else if (property.DeclaringType.Name.StartsWith("<>f__AnonymousType")) //匿名类
            {
                CanWrite = true;
                IsPublic = false;
            }
            if (get != null)             //get方法不为空
            {
                CanRead  = true;         //属性可读
                Static   = get.IsStatic; //get.set只要有一个静态就是静态
                IsPublic = IsPublic || get.IsPublic;
            }
            ID  = System.Threading.Interlocked.Increment(ref Literacy.Sequence);
            UID = Guid.NewGuid();
            Init();
            if (set == null && CanWrite) //匿名类的属性设置特殊处理
            {
                Setter = (o, v) =>
                {
                    var field = ClassType.GetField("<" + Name + ">i__Field", (BindingFlags)(-1));
                    Setter = Literacy.CreateSetter(field, ClassType);
                    Setter(o, v);
                };
            }
            Attributes = new AttributeCollection(MemberInfo);
            var mapping = Attributes.First <IMemberMappingAttribute>();

            if (mapping != null)
            {
                MappingName = mapping.Name;
            }
        }
 private void SetupSyncElements <T>(List <string> fieldNames, Dictionary <string, FieldInfo> cache, List <T> elementList) where T : LiteNetLibElement
 {
     elementList.Clear();
     foreach (var fieldName in fieldNames)
     {
         var       key = TypeName + "_" + fieldName;
         FieldInfo field;
         if (!cache.TryGetValue(key, out field))
         {
             field      = ClassType.GetField(fieldName);
             cache[key] = field;
         }
         if (field == null)
         {
             Debug.LogWarning("Element named " + fieldName + " was not found");
             continue;
         }
         var syncList  = (T)field.GetValue(this);
         var elementId = Convert.ToUInt16(elementList.Count);
         syncList.Setup(this, elementId);
         elementList.Add(syncList);
     }
 }