コード例 #1
0
ファイル: GenerateConverter.cs プロジェクト: Corillian/corefx
        private void AddRule(ConversionRule ruleAdd) {
            for (int i = 0; i < this.rules.Count; i++) {
                ConversionRule rule = this.rules[i];

                if (rule.XmlType == ruleAdd.XmlType) {
                    if (rule.SourceType == ruleAdd.SourceType) {
                        if (rule.DestinationType == ruleAdd.DestinationType) {
                            // Override previous rule with new rule
                            this.rules[i] = ruleAdd;
                            return;
                        }
                    }
                }
            }

            this.rules.Add(ruleAdd);
        }
コード例 #2
0
ファイル: GenerateConverter.cs プロジェクト: Corillian/corefx
        private void GenerateConversions(ConversionRule defaultRule, IList<ConversionRule> rulesSwitch) {
            int cnt = rulesSwitch.Count;

            // Don't need to test TypeCode for default rule
            if (defaultRule != null)
                cnt--;

            if (cnt > 0) {
                if (cnt > 1) {
                    this.w.WriteLine("switch (TypeCode) {");
                }

                foreach (ConversionRule ruleSwitch in rulesSwitch) {
                    if (ruleSwitch != defaultRule) {
                        if (cnt > 1) {
                            this.w.Indent++;
                            this.w.WriteLine("case XmlTypeCode." + ruleSwitch.XmlType + ": return " + ruleSwitch.ConversionExpression + ";");
                            this.w.Indent--;
                        }
                        else {
                            this.w.WriteLine("if (TypeCode == XmlTypeCode." + ruleSwitch.XmlType + ") return " + ruleSwitch.ConversionExpression + ";");
                        }
                    }
                }

                if (cnt > 1) {
                    this.w.WriteLine("}");
                }
            }

            if (defaultRule != null)
                this.w.WriteLine("return " + defaultRule.ConversionExpression + ";");
        }