Пример #1
0
        TypeDef CreateTypeDef(Type type)
        {
            Console.WriteLine("Generating type {0}", type);

            var qualifiedClassName = GetQualifiedClassName(type);

            var builtInTypeUsageConfigurations = _configuration
                                                 .BuiltInTypeUsages
                                                 .Where(x => x.IsForType(type))
                                                 .ToList();

            if (builtInTypeUsageConfigurations.Any())
            {
                if (builtInTypeUsageConfigurations.Count > 1)
                {
                    throw new PrettyException(string.Format("Found multiple built-in-type configurations for type {0}", type));
                }

                var builtInTypeUsageConfiguration = _configuration.BuiltInTypeUsages.Single(x => x.IsForType(type));

                var existingTypes = _types.Values
                                    .OfType <BuiltInTypeDef>()
                                    .Where(x => x.FullyQualifiedTsTypeName == builtInTypeUsageConfiguration.TsType)
                                    .ToList();

                if (existingTypes.Any())
                {
                    return(existingTypes.First());
                }

                return(AddBuiltInType(type, "", builtInTypeUsageConfiguration.TsType));
            }

            var typeDef = IsCommand(type)
                ? new CommandTypeDef(qualifiedClassName, GetTypeFor(typeof(Command)), type)
                : IsView(type)
                    ? new TypeDef(qualifiedClassName, CirqusType.View)
                    : new TypeDef(qualifiedClassName, CirqusType.Other);

            if ((type.IsGenericType && !type.IsGenericTypeDefinition) || type.IsGenericParameter)
            {
                typeDef.NoEmit = true;
            }

            _types[type] = typeDef;

            var propertiesIgnoredInConfig = _configuration
                                            .IgnoredProperties
                                            .Where(x => x.IsForType(type))
                                            .Select(x => x.PropertyName)
                                            .ToList();

            var properties = GetAllProperties(type)
                             .Where(x => !propertiesIgnoredInConfig.Contains(x.Name))
                             .Where(x => x.GetCustomAttribute <TypeScriptIgnoreAttribute>() == null)
                             .Where(x => typeDef.CirqusType != CirqusType.Command || x.Name != "Meta");

            foreach (var property in properties)
            {
                Console.WriteLine("Generating property {0}", property.Name);

                var propertyDef =
                    new PropertyDef(
                        GetOrCreateTypeDef(property.PropertyType),
                        property.Name);

                typeDef.AddProperty(propertyDef);
            }

            return(typeDef);
        }
Пример #2
0
 public void AddProperty(PropertyDef propertyDef)
 {
     _properties.Add(propertyDef);
 }