Пример #1
0
        private void AddContractFor(string namespaceToLoad, Type type)
        {
            if (AlreadyLoaded(type))
            {
                return;
            }

            if (HasBaseType(type))
            {
                AddContractForBaseType(namespaceToLoad, type);
            }

            var fieldsAndProperties = new List <string>();

            fieldsAndProperties.AddRange(GetProperties(type));
            fieldsAndProperties.AddRange(GetFields(type));

            foreach (string field in fieldsAndProperties)
            {
                var typeWithNamespace = namespaceToLoad + "." + type.Name + "." + field;
                var id = _mapper.Map(typeWithNamespace);

                if (type.GetGenericArguments().Count() > 1)
                {
                    continue;
                }

                _model[type].Add(id, field);

                var sb = new StringBuilder();
                sb.Append("model[typeof(");
                sb.Append(type.Name);
                sb.Append(")].Add(");
                sb.Append(id);
                sb.Append(@", """);
                sb.Append(field);
                sb.Append(@""");");

                Debug.WriteLine(sb.ToString());
            }
        }
        public void GivenElementNameWhenMapThenIdIsCorrect()
        {
            var result = _mapper.Map("NumericRepresentation");

            Assert.AreEqual(108, result);
        }