Esempio n. 1
0
 /// <summary>
 /// 特性声明
 /// <para>eg. [Serializable]</para>
 /// </summary>
 /// <param name="inName">特性名</param>
 /// <param name="inValue">特性值</param>
 public void SetField(string inName, string inValue)
 {
     if (Assist.IsNumber(inValue))
     {
         property.CustomAttributes.Add(new CodeAttributeDeclaration(inName, new CodeAttributeArgument(new CodePrimitiveExpression(int.Parse(inValue)))));
     }
 }
Esempio n. 2
0
        public void SetNodeValue(XmlNode n)
        {
            for (int i = 0; i < n.Attributes.Count; i++)
            {
                string value = n.Attributes[i].Value;

                //AddField(n.Attributes[i].Name, value, MemberAttributes.Private);
                fieldList.Add(new FieldItem(n.Attributes[i].Name, value, MemberAttributes.Private));

                PropertyItem item = new PropertyItem(n.Attributes[i].Name);
                item.SetGetName();
                item.SetValueType(value);
                item.SetModifier(MemberAttributes.Public | MemberAttributes.Final);
                propertyList.Add(item);

                CodeConditionStatement condition = new CodeConditionStatement();
                condition.Condition = new CodeVariableReferenceExpression("inArg0.ContainsKey(\"" + n.Attributes[i].Name + "\")");

                string parseLeft  = "";
                string parseRight = "";
                if (Assist.IsNumber(value))
                {
                    parseLeft  = value.Contains(".") ? "float.Parse(" : "uint.Parse(";
                    parseRight = ")";
                }
                CodeVariableReferenceExpression right = new CodeVariableReferenceExpression(parseLeft + "inArg0[\"" + n.Attributes[i].Name + "\"]" + parseRight);
                CodePropertyReferenceExpression left  = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_" + Assist.FirstLetterLower(n.Attributes[i].Name));

                if (Assist.IsNumber(value))
                {
                    CodeConditionStatement numCondition = new CodeConditionStatement();
                    numCondition.Condition = new CodeVariableReferenceExpression("inArg0[\"" + n.Attributes[i].Name + "\"] == \"\"");

                    numCondition.TrueStatements.Add(new CodeAssignStatement(left, new CodeVariableReferenceExpression("0")));
                    numCondition.FalseStatements.Add(new CodeAssignStatement(left, right));

                    condition.TrueStatements.Add(numCondition);
                }
                else
                {
                    condition.TrueStatements.Add(new CodeAssignStatement(left, right));
                }

                AddConditionStatement(condition);
            }
            Create();
        }