Пример #1
0
        private Instance createMetaDataInstance(AnalyzingContext analyzingContext, TypeDescriptor metaDataType, MetaExport metaExport)
        {
            var instance = analyzingContext.Machine.CreateInstance(metaDataType);

            //register call handler for instance, that
            //will handle all method calls
            _context.RegisterCallHandler(instance, (c) =>
            {
                var method = Naming.GetMethodName(c.CurrentCall.Name);
                var key    = method.Substring(Naming.GetterPrefix.Length);
                var item   = metaExport.GetItem(key);

                var metaDataInstance = createMetaItemInstance(analyzingContext, item);
                c.Return(metaDataInstance);
            });

            return(instance);
        }
Пример #2
0
        /// <summary>
        /// Test if metadataType can be satisfied from metadata
        /// </summary>
        /// <param name="metadataType"></param>
        /// <param name="meta"></param>
        /// <returns></returns>
        private bool testMetaData(InstanceInfo metadataType, MetaExport meta)
        {
            foreach (var getter in _context.GetOverloads(metadataType))
            {
                if (meta == null)
                {
                    //cannot satisfy metaDataType
                    return(false);
                }

                if (getter.Parameters.Length != 0)
                {
                    //is not valid getter method
                    continue;
                }

                var name = getter.MethodName;
                if (!name.StartsWith(Naming.GetterPrefix))
                {
                    //is not valid getter name
                    continue;
                }

                name = name.Substring(Naming.GetterPrefix.Length);

                var getterType = getter.ReturnType;
                var item       = meta.GetItem(name);

                if (item == null)
                {
                    return(false);
                }

                var metaToSet = findMetaData(getterType, item.Data, item.IsMultiple);
                if (metaToSet == null)
                {
                    //not matching types
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Sets the meta information to properties with given prefix.
        /// </summary>
        /// <param name="connector">The connector where meta properties will be available.</param>
        /// <param name="propertyPrefix">The property prefix.</param>
        /// <param name="meta">The meta information.</param>
        private static void setMetaProperties(ConnectorDefinition connector, string propertyPrefix, MetaExport meta)
        {
            foreach (var key in meta.ExportedKeys)
            {
                var item  = meta.GetItem(key);
                var index = 1;
                foreach (var value in item.Data)
                {
                    var propertyName        = propertyPrefix + index + "-" + item.Key;
                    var valueRepresentation = "'" + value + "'";
                    if (item.IsMultiple)
                    {
                        valueRepresentation += " | IsMultiple";
                    }

                    setProperty(connector, propertyName, valueRepresentation);

                    ++index;
                }
            }
        }