Ejemplo n.º 1
0
        public CodegenField AddSubstitutionParameter(
            string name,
            Type type)
        {
            var mixed = false;
            if (name == null) {
                if (!_substitutionParamsByName.IsEmpty()) {
                    mixed = true;
                }
            }
            else if (!SubstitutionParamsByNumber.IsEmpty()) {
                mixed = true;
            }

            if (mixed) {
                throw new ArgumentException("Mixing named and unnamed substitution parameters is not allowed");
            }

            if (name != null) {
                var entry = _substitutionParamsByName.Get(name);
                if (entry != null && !TypeHelper.IsSubclassOrImplementsInterface(type, entry.Type)) {
                    throw new ArgumentException(
                        "Substitution parameter '" +
                        name +
                        "' of type '" +
                        entry.Type +
                        "' cannot be assigned type '" +
                        type +
                        "'");
                }
            }

            CodegenField member;
            if (name == null) {
                var assigned = ++_currentSubstitutionParamNumber;
                var fieldName = CodegenNamespaceScopeNames.AnySubstitutionParam(assigned);
                member = new CodegenField(FieldsClassName, fieldName, type, null, false);
                SubstitutionParamsByNumber.Add(new CodegenSubstitutionParamEntry(member, name, type));
            }
            else {
                var existing = _substitutionParamsByName.Get(name);
                if (existing == null) {
                    var assigned = ++_currentSubstitutionParamNumber;
                    var fieldName = CodegenNamespaceScopeNames.AnySubstitutionParam(assigned);
                    member = new CodegenField(FieldsClassName, fieldName, type, null, false);
                    _substitutionParamsByName.Put(name, new CodegenSubstitutionParamEntry(member, name, type));
                }
                else {
                    member = existing.Field;
                }
            }

            return member;
        }
Ejemplo n.º 2
0
        // --------------------------------------------------------------------------------

        private CodegenField AddFieldUnsharedInternal(
            bool isFinal,
            Type type,
            CodegenExpression initCtorScoped)
        {
            var memberNumber = _currentMemberNumber++;
            var name = CodegenNamespaceScopeNames.AnyField(memberNumber);
            var member = new CodegenField(FieldsClassName, name, type, null, isFinal);
            _fieldsUnshared.Put(member, initCtorScoped);
            return member;
        }