コード例 #1
0
ファイル: AttributeSet.cs プロジェクト: Theodus2009/WinSSC
        private static void applyHardAttribute(AttributeSet attrSet, string attrName)
        {
            AttributeDef existingDef = attrSet.AttributeDefinitions.FirstOrDefault(x => x.Name == attrName);

            if (existingDef != null)
            {
                attrSet.AttributeDefinitions.Remove(existingDef);
            }
            attrSet.AttributeDefinitions.Add(new AttributeDef()
            {
                Name = attrName, DataType = EAttributeType.String
            });
        }
コード例 #2
0
ファイル: AttributeSet.cs プロジェクト: Theodus2009/WinSSC
        /// <summary>
        /// Parses attribute definitions loaded from a file.
        /// </summary>
        /// <param name="configText"></param>
        /// <returns></returns>
        public static IList <AttributeDef> ParseAttributeDefs(string configText)
        {
            List <AttributeDef> defs = new List <AttributeDef>();

            string[] configLines = configText.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (string l in configLines)
            {
                string str = l.Trim();
                if (str.StartsWith("#"))
                {
                    continue;
                }
                string[] parts = str.Split(':');
                if (parts.Length != 2 || parts[0].Trim().Length == 0)
                {
                    Logger.LogWarning("Could not parse " + str + " in " + ATTRIBUTE_FILE);
                    continue;
                }
                EAttributeType attrType;
                try
                {
                    attrType = (EAttributeType)Enum.Parse(typeof(EAttributeType), parts[1]);
                }
                catch (ArgumentException)
                {
                    Logger.LogWarning("Attribute " + parts[0] + " in " + ATTRIBUTE_FILE + " was not a valid type.");
                    continue;
                }

                AttributeDef def = new AttributeDef()
                {
                    Name = parts[0], DataType = attrType
                };
                defs.Add(def);
            }
            return(defs);
        }
コード例 #3
0
ファイル: AttributeSet.cs プロジェクト: Theodus2009/WinSSC
        /// <summary>
        /// Parses attribute definitions loaded from a file.
        /// </summary>
        /// <param name="configText"></param>
        /// <returns></returns>
        public static IList<AttributeDef> ParseAttributeDefs(string configText)
        {
            List<AttributeDef> defs = new List<AttributeDef>();
            string[] configLines = configText.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (string l in configLines)
            {
                string str = l.Trim();
                if (str.StartsWith("#")) continue;
                string[] parts = str.Split(':');
                if (parts.Length != 2 || parts[0].Trim().Length == 0)
                {
                    Logger.LogWarning("Could not parse " + str + " in " + ATTRIBUTE_FILE);
                    continue;
                }
                EAttributeType attrType;
                try
                {
                    attrType = (EAttributeType)Enum.Parse(typeof(EAttributeType), parts[1]);
                }
                catch (ArgumentException)
                {
                    Logger.LogWarning("Attribute " + parts[0] + " in " + ATTRIBUTE_FILE + " was not a valid type.");
                    continue;
                }

                AttributeDef def = new AttributeDef() { Name = parts[0], DataType = attrType };
                defs.Add(def);
            }
            return defs;
        }