Exemplo n.º 1
0
        public TypeLoadData(Type typeIn)
        {
            Type = typeIn;

            ObsoleteMessage = string.Join(
                "\n",
                Type.GetCustomAttributes <ObsoleteAttribute>(true)
                .Select(x => string.IsNullOrEmpty(x.Message) ? "Obsolete" : x.Message));

            IsDeprecated   = Type.GetCustomAttributes <NodeDeprecatedAttribute>(true).Any();
            IsMetaNode     = Type.GetCustomAttributes <IsMetaNodeAttribute>(false).Any();
            IsDSCompatible = Type.GetCustomAttributes <IsDesignScriptCompatibleAttribute>(false).Any();
            IsHidden       = Type.GetCustomAttributes <IsVisibleInDynamoLibraryAttribute>(true)
                             .Any(attr => !attr.Visible);

            var attribs = Type.GetCustomAttributes <NodeNameAttribute>(false);

            if (attribs.Any() && !IsDeprecated && !IsMetaNode && IsDSCompatible && !IsHidden)
            {
                Name = attribs.First().Name;
            }
            else
            {
                Name = Type.Name;
            }

            AlsoKnownAs =
                Type.GetCustomAttributes <AlsoKnownAsAttribute>(false)
                .SelectMany(aka => aka.Values)
                .Concat(Name.AsSingleton());

            SearchKeys = Type.GetCustomAttributes <NodeSearchTagsAttribute>(false).SelectMany(x => x.Tags);
            Category   =
                Type.GetCustomAttributes <NodeCategoryAttribute>(false)
                .Select(x => x.ElementCategory)
                .FirstOrDefault();
            Description =
                Type.GetCustomAttributes <NodeDescriptionAttribute>(false)
                .Select(x => x.ElementDescription)
                .FirstOrDefault() ?? "";

            var inputNames = Type.GetCustomAttributes <InPortNamesAttribute>(false)
                             .SelectMany(x => x.PortNames).ToList();
            var inputTypes = Type.GetCustomAttributes <InPortTypesAttribute>(false)
                             .SelectMany(x => x.PortTypes).ToList();

            if (inputNames.Any() && (inputNames.Count == inputTypes.Count))
            {
                InputParameters = inputNames.Zip(inputTypes, (name, type) => new Tuple <string, string>(name, type));
            }
            else
            {
                InputParameters = new List <Tuple <string, string> >();
            }


            OutputParameters = Type.GetCustomAttributes <OutPortTypesAttribute>(false)
                               .SelectMany(x => x.PortTypes);
        }