private void buildMetaExport(AttributeInfo info, ComponentInfoBuilder builder) { var isMultiple = info.GetArgument("IsMultiple") == "true"; var name = parseObject(info.GetArgument("Name", 0), builder, info.Element) as string; var value = parseObject(info.GetArgument("Value", 1), builder, info.Element); builder.AddMeta(name, value, isMultiple); }
/// <summary> /// Add export according to given <see cref="CodeAttribute"/> /// </summary> /// <param name="exportAttribute">Attribute defining export</param> private void addExport(AttributeInfo exportAttribute) { var builder = getOrCreateCurrentBuilder(exportAttribute.Element as CodeElement); TypeDescriptor exportTypeDescriptor; MethodID exportMethodID; if (!getExportTarget(exportAttribute.Element, builder.ComponentType, out exportMethodID, out exportTypeDescriptor)) { _assembly.VS.Log.Warning("Cannot parse export attribute on: " + exportAttribute.Element.Name); return; } var explicitContract = parseContract(exportAttribute.GetArgument(0), builder, exportAttribute.Element); var contract = explicitContract == null ? exportTypeDescriptor.TypeName : explicitContract; var isSelfExport = exportMethodID == null; var isInherited = exportAttribute.Element.FullName == Naming.InheritedExportAttribute; exploreMetaData(exportAttribute, builder); if (isSelfExport) { builder.AddSelfExport(isInherited, contract); } else { builder.AddExport(exportTypeDescriptor, exportMethodID, isInherited, contract); } }
protected override void generate(EmitterBase emitter) { var namespaces = _declaringAssembly.GetNamespaces(_compositionAttribute.Element as CodeElement); var initializerMethodInfo = new TypeMethodInfo(_compositionPoint.DeclaringType, ParsingActivation.InlineMethodName, TypeDescriptor.Void, ParameterTypeInfo.NoParams, false, TypeDescriptor.NoDescriptors); var code = new StringBuilder(); code.AppendLine("{"); for (var i = 0; i < _compositionPoint.Parameters.Length; ++i) { var parameter = _compositionPoint.Parameters[i]; var argument = _compositionAttribute.GetArgument(i); if (argument == null) { argument = "null"; } code.AppendLine(" var arg" + i + " = " + argument + ";"); } code.AppendLine("}"); var activation = new ParsingActivation(code.ToString(), initializerMethodInfo, new string[0], namespaces); _declaringAssembly.ParsingProvider(activation, emitter); }
/// <summary> /// Add import according to given <see cref="CodeAttribute"/> /// </summary> /// <param name="importAttribute">Attribute defining import</param> /// <param name="forceMany">Determine that explicit <c>AllowMany</c> is used</param> private void addImport(AttributeInfo importAttribute, bool forceMany = false) { var builder = getOrCreateCurrentBuilder(importAttribute.Element as CodeElement); MethodID importMethodID; TypeDescriptor importType; if (!getImportTarget(importAttribute.Element, builder.ComponentType, out importMethodID, out importType)) { _assembly.VS.Log.Warning("Cannot parse import attribute on: " + importAttribute.Element.Name); return; } var explicitContract = parseContract(importAttribute.GetArgument(0), builder, importAttribute.Element); var allowMany = forceMany || importAttribute.IsTrue("AllowMany"); var allowDefault = forceMany || importAttribute.IsTrue("AllowDefault"); var importTypeInfo = ImportTypeInfo.ParseFromMany(importType, allowMany, _services); var contract = explicitContract == null ? importTypeInfo.ItemType.TypeName : explicitContract; builder.AddImport(importTypeInfo, importMethodID, contract, allowMany, allowDefault); }