コード例 #1
0
            internal object CreateInstanceCore(object[] ctorArgs)
            {
                Contracts.Assert(Utils.Size(ctorArgs) == CtorTypes.Length + ((RequireEnvironment) ? 1 : 0));

                if (InstanceGetter != null)
                {
                    Contracts.Assert(Utils.Size(ctorArgs) == 0);
                    return(InstanceGetter.Invoke(null, null));
                }
                if (Constructor != null)
                {
                    return(Constructor.Invoke(ctorArgs));
                }
                if (CreateMethod != null)
                {
                    return(CreateMethod.Invoke(null, ctorArgs));
                }
                throw Contracts.Except("Can't instantiate class '{0}'", Type.Name);
            }
コード例 #2
0
            internal ComponentInfo(Type interfaceType, string kind, Type argumentType, TlcModule.ComponentAttribute attribute)
            {
                Contracts.AssertValue(interfaceType);
                Contracts.AssertNonEmpty(kind);
                Contracts.AssertValue(argumentType);
                Contracts.AssertValue(attribute);

                Name        = attribute.Name;
                Description = attribute.Desc;
                if (string.IsNullOrWhiteSpace(attribute.FriendlyName))
                {
                    FriendlyName = Name;
                }
                else
                {
                    FriendlyName = attribute.FriendlyName;
                }

                Kind = kind;
                if (!IsValidName(Kind))
                {
                    throw Contracts.Except("Invalid component kind: '{0}'", Kind);
                }

                Aliases = attribute.Aliases;
                if (!IsValidName(Name))
                {
                    throw Contracts.Except("Component name '{0}' is not valid.", Name);
                }

                if (Aliases != null && Aliases.Any(x => !IsValidName(x)))
                {
                    throw Contracts.Except("Component '{0}' has an invalid alias '{1}'", Name, Aliases.First(x => !IsValidName(x)));
                }

                if (!typeof(IComponentFactory).IsAssignableFrom(argumentType))
                {
                    throw Contracts.Except("Component '{0}' must inherit from IComponentFactory", argumentType);
                }

                ArgumentType  = argumentType;
                InterfaceType = interfaceType;
            }
コード例 #3
0
        private void AddClass(LoadableClassInfo info, string[] loadNames, bool throwOnError)
        {
            _classes.Add(info);
            bool isEntryPoint = false;

            foreach (var sigType in info.SignatureTypes)
            {
                _signatures[sigType] = true;

                foreach (var name in loadNames)
                {
                    string nameCi = name.ToLowerInvariant();

                    var key = new LoadableClassInfo.Key(nameCi, sigType);
                    if (_classesByKey.TryGetValue(key, out var infoCur))
                    {
                        if (throwOnError)
                        {
                            throw Contracts.Except($"ComponentCatalog cannot map name '{name}' and SignatureType '{sigType}' to {info.Type.Name}, already mapped to {infoCur.Type.Name}.");
                        }
                    }
                    else
                    {
                        _classesByKey.Add(key, info);
                    }
                }

                if (sigType == typeof(SignatureEntryPointModule))
                {
                    isEntryPoint = true;
                }
            }

            if (isEntryPoint)
            {
                ScanForEntryPoints(info);
            }
        }
コード例 #4
0
            internal EntryPointInfo(MethodInfo method,
                                    TlcModule.EntryPointAttribute attribute, ObsoleteAttribute obsoleteAttribute)
            {
                Contracts.AssertValue(method);
                Contracts.AssertValue(attribute);

                Name              = attribute.Name ?? string.Join(".", method.DeclaringType.Name, method.Name);
                Description       = attribute.Desc;
                Method            = method;
                ShortName         = attribute.ShortName;
                FriendlyName      = attribute.UserName;
                XmlInclude        = attribute.XmlInclude;
                ObsoleteAttribute = obsoleteAttribute;

                // There are supposed to be 2 parameters, env and input for non-macro nodes.
                // Macro nodes have a 3rd parameter, the entry point node.
                var parameters = method.GetParameters();

                if (parameters.Length != 2 && parameters.Length != 3)
                {
                    throw Contracts.Except("Method '{0}' has {1} parameters, but must have 2 or 3", method.Name, parameters.Length);
                }
                if (parameters[0].ParameterType != typeof(IHostEnvironment))
                {
                    throw Contracts.Except("Method '{0}', 1st parameter is {1}, but must be IHostEnvironment", method.Name, parameters[0].ParameterType);
                }
                InputType = parameters[1].ParameterType;
                var outputType = method.ReturnType;

                if (!outputType.IsClass)
                {
                    throw Contracts.Except("Method '{0}' returns {1}, but must return a class", method.Name, outputType);
                }
                OutputType = outputType;

                InputKinds  = FindEntryPointKinds(InputType);
                OutputKinds = FindEntryPointKinds(OutputType);
            }
コード例 #5
0
        public IEnumerable <TDst> RunPipe(bool reuseRowObject)
        {
            var curCounter = _counter;

            using (var cursor = _cursorablePipe.GetCursor())
            {
                TDst row = null;
                while (cursor.MoveNext())
                {
                    if (!reuseRowObject || row == null)
                    {
                        row = new TDst();
                    }

                    cursor.FillValues(row);
                    yield return(row);

                    if (curCounter != _counter)
                    {
                        throw Contracts.Except("An attempt was made to keep iterating after the pipe has been reset.");
                    }
                }
            }
        }
コード例 #6
0
        protected LoadableClassAttributeBase(string summary, Type instType, Type loaderType, Type argType, Type[] sigTypes, string userName, params string[] loadNames)
        {
            Contracts.CheckValueOrNull(summary);
            Contracts.CheckValue(instType, nameof(instType));
            Contracts.CheckValue(loaderType, nameof(loaderType));
            Contracts.CheckNonEmpty(sigTypes, nameof(sigTypes));

            if (Utils.Size(loadNames) == 0)
            {
                loadNames = new string[] { userName }
            }
            ;

            if (loadNames.Any(s => string.IsNullOrWhiteSpace(s)))
            {
                throw Contracts.ExceptEmpty(nameof(loadNames), "LoadableClass loadName parameter can't be empty");
            }

            var sigType = sigTypes[0];

            Contracts.CheckValue(sigType, nameof(sigTypes));
            Type[] types;
            Contracts.CheckParam(sigType.BaseType == typeof(System.MulticastDelegate), nameof(sigTypes), "LoadableClass signature type must be a delegate type");

            var meth = sigType.GetMethod("Invoke");

            Contracts.CheckParam(meth != null, nameof(sigTypes), "LoadableClass signature type must be a delegate type");
            Contracts.CheckParam(meth.ReturnType == typeof(void), nameof(sigTypes), "LoadableClass signature type must be a delegate type with void return");

            var parms     = meth.GetParameters();
            int itypeBase = 0;

            if (argType != null)
            {
                types = new Type[1 + parms.Length];
                types[itypeBase++] = argType;
            }
            else if (parms.Length > 0)
            {
                types = new Type[parms.Length];
            }
            else
            {
                types = Type.EmptyTypes;
            }

            for (int itype = 0; itype < parms.Length; itype++)
            {
                var parm = parms[itype];
                if ((parm.Attributes & (ParameterAttributes.Out | ParameterAttributes.Retval)) != 0)
                {
                    throw Contracts.Except("Invalid signature parameter attributes");
                }
                types[itypeBase + itype] = parm.ParameterType;
            }

            for (int i = 1; i < sigTypes.Length; i++)
            {
                sigType = sigTypes[i];
                Contracts.CheckValue(sigType, nameof(sigTypes));

                Contracts.Check(sigType.BaseType == typeof(System.MulticastDelegate), "LoadableClass signature type must be a delegate type");

                meth = sigType.GetMethod("Invoke");
                Contracts.CheckParam(meth != null, nameof(sigTypes), "LoadableClass signature type must be a delegate type");
                Contracts.CheckParam(meth.ReturnType == typeof(void), nameof(sigTypes), "LoadableClass signature type must be a delegate type with void return");
                parms = meth.GetParameters();
                Contracts.CheckParam(parms.Length + itypeBase == types.Length, nameof(sigTypes), "LoadableClass signatures must have the same number of parameters");
                for (int itype = 0; itype < parms.Length; itype++)
                {
                    var parm = parms[itype];
                    if ((parm.Attributes & (ParameterAttributes.Out | ParameterAttributes.Retval)) != 0)
                    {
                        throw Contracts.ExceptParam(nameof(sigTypes), "Invalid signature parameter attributes");
                    }
                    Contracts.CheckParam(types[itypeBase + itype] == parm.ParameterType, nameof(sigTypes),
                                         "LoadableClass signatures must have the same set of parameters");
                }
            }

            InstanceType = instType;
            LoaderType   = loaderType;
            ArgType      = argType;
            SigTypes     = sigTypes;
            CtorTypes    = types;
            Summary      = summary;
            UserName     = userName;
            LoadNames    = loadNames;
        }
    }