Пример #1
0
        public void AddProperty(PropertyInfo propertyInfo, ToffeeModifiers modifiers = ToffeeModifiers.None)
        {
            ToffeeProperty property = new ToffeeProperty(this, propertyInfo, modifiers);

            if (HasField(property.Identifier))
            {
                throw new ToffeeException("Struct '{0}' already has field with name: '{1}'.", Name, property.Identifier);
            }
            if (HasField(property.FieldId))
            {
                throw new ToffeeException("Struct '{0}' already has field with id: '{1}'.", Name, property.FieldId);
            }

            TypeCode type = Type.GetTypeCode(propertyInfo.PropertyType);

            switch (type)
            {
            case TypeCode.Boolean:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Char:
                MinimumSize++;
                break;

            case TypeCode.UInt16:
            case TypeCode.Int16:
                MinimumSize += 2;
                break;

            case TypeCode.String:
            case TypeCode.UInt32:
            case TypeCode.Int32:
            case TypeCode.Single:
                MinimumSize += 4;
                break;

            case TypeCode.UInt64:
            case TypeCode.Int64:
            case TypeCode.Double:
                MinimumSize += 8;
                break;

            case TypeCode.Object:
                if (propertyInfo.PropertyType.IsArray)
                {
                    MinimumSize += 4;
                }
                break;
            }

            AddField(property);
            _Properties.Add(property);
            PropertyIdentifierLookup.Add(property.Identifier, property);
            PropertyLookup.Add(property.FieldId, property);
        }
Пример #2
0
        public void AddProperty(string identifier, TdlType type, ToffeeModifiers modifiers = ToffeeModifiers.None)
        {
            if (PropertyIdentifierLookup.ContainsKey(identifier))
            {
                return;
            }

            TdlProperty property = new TdlProperty(identifier, this, type, modifiers);

            _Properties.Add(property);
            PropertyLookup.Add(property.FieldId, property);
            PropertyIdentifierLookup.Add(identifier, property);
            AddField(property);
            MinimumSize += type.MinimumSize;

            if (type.Type == ToffeeValueType.Struct)
            {
                AddRequiredNamespace(type.StructType.Namespace.FullName);
            }
        }
Пример #3
0
 public bool HasProperty(string identifier)
 {
     return(PropertyIdentifierLookup.ContainsKey(identifier));
 }