public TypeGraphNode GetNode(AssemblyQualifiedTypeName typeName) { TypeGraphNode node; if (dict.TryGetValue(typeName, out node)) return node; else return null; }
public void TryParseAssemblyQualifiedTypeName_FullyQualified() { var value = typeof(TypeNameResolverTests).AssemblyQualifiedName; var typeName = TypeParser.ParseTypeName(value); Assert.IsTrue(typeName is AssemblyQualifiedTypeName); AssemblyQualifiedTypeName assemblyQualifiedTypeName = (AssemblyQualifiedTypeName)typeName; Assert.AreEqual(assemblyQualifiedTypeName.AssemblyName.FullName, typeof(TypeNameResolverTests).Assembly.FullName); Assert.AreEqual(assemblyQualifiedTypeName.TypeName.ToString(), typeof(TypeNameResolverTests).FullName); }
public void TryParseAssemblyQualifiedTypeName_GenericType_NameAndAssemblyOnly() { var value = $"{typeof (GenericType<,>).FullName}, {typeof (TypeNameResolverTests).Assembly.GetName ().Name}"; var typeName = TypeParser.ParseTypeName(value); Assert.IsTrue(typeName is AssemblyQualifiedTypeName); AssemblyQualifiedTypeName assemblyQualifiedTypeName = (AssemblyQualifiedTypeName)typeName; Assert.AreEqual(assemblyQualifiedTypeName.AssemblyName.Name, typeof(TypeNameResolverTests).Assembly.GetName().Name); Assert.AreEqual(assemblyQualifiedTypeName.TypeName.ToString(), $"{typeof (TypeNameResolverTests).FullName}/GenericType`2"); }
public LanguageContext GetLanguageByTypeName(string providerAssemblyQualifiedTypeName) { ContractUtils.RequiresNotNull(providerAssemblyQualifiedTypeName, nameof(providerAssemblyQualifiedTypeName)); var aqtn = AssemblyQualifiedTypeName.ParseArgument(providerAssemblyQualifiedTypeName, nameof(providerAssemblyQualifiedTypeName)); if (!Configuration.TryLoadLanguage(this, aqtn, out LanguageContext language)) { throw Error.UnknownLanguageProviderType(); } return(language); }
internal void AddLanguage(string languageTypeName, string displayName, IList <string> names, IList <string> fileExtensions, IDictionary <string, object> options, string paramName) { ContractUtils.Requires(!_frozen, "Configuration cannot be modified once the runtime is initialized"); ContractUtils.Requires( names.TrueForAll((id) => !String.IsNullOrEmpty(id) && !_languageNames.ContainsKey(id)), paramName ?? "names", "Language name should not be null, empty or duplicated between languages" ); ContractUtils.Requires( fileExtensions.TrueForAll((ext) => !String.IsNullOrEmpty(ext) && !_languageExtensions.ContainsKey(ext)), paramName ?? "fileExtensions", "File extension should not be null, empty or duplicated between languages" ); ContractUtils.RequiresNotNull(displayName, paramName ?? "displayName"); if (string.IsNullOrEmpty(displayName)) { ContractUtils.Requires(names.Count > 0, paramName ?? "displayName", "Must have a non-empty display name or a a non-empty list of language names"); displayName = names[0]; } var aqtn = AssemblyQualifiedTypeName.ParseArgument(languageTypeName, paramName ?? "languageTypeName"); if (_languageConfigurations.ContainsKey(aqtn)) { throw new ArgumentException(string.Format("Duplicate language with type name '{0}'", aqtn), "languageTypeName"); } // Add global language options first, they can be rewritten by language specific ones: var mergedOptions = new Dictionary <string, object>(_options); // Replace global options with language-specific options foreach (var option in options) { mergedOptions[option.Key] = option.Value; } var config = new LanguageConfiguration(aqtn, displayName, mergedOptions); _languageConfigurations.Add(aqtn, config); // allow duplicate ids in identifiers and extensions lists: foreach (var name in names) { _languageNames[name] = config; } foreach (var ext in fileExtensions) { _languageExtensions[NormalizeExtension(ext)] = config; } }
public ClassEntry(string extends, string className, string entityName, string assembly, string @namespace) { fullExtends = string.IsNullOrEmpty(extends) ? null : TypeNameParser.Parse(extends, @namespace, assembly); fullClassName = string.IsNullOrEmpty(className) ? null : TypeNameParser.Parse(className, @namespace, assembly); this.entityName = entityName; extendsEntityName = string.IsNullOrEmpty(extends) ? null : extends; unchecked { hashCode = (entityName != null ? entityName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (fullExtends != null ? fullExtends.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (fullClassName != null ? fullClassName.GetHashCode() : 0); } }
public TypeGraphNode GetNode(AssemblyQualifiedTypeName typeName) { TypeGraphNode node; if (dict.TryGetValue(typeName, out node)) { return(node); } else { return(null); } }
internal bool TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, out LanguageContext language) { Assert.NotNull(manager); if (_languageConfigurations.TryGetValue(providerName, out LanguageConfiguration config)) { language = LoadLanguageContext(manager, config); return(true); } language = null; return(false); }
internal AssemblyQualifiedTypeName( string topLevelType, string[] nestedTypes, AssemblyQualifiedTypeName[] typeArguments, int[] arrayRanks, string assemblyName) { this.TopLevelType = topLevelType; this.NestedTypes = nestedTypes; this.TypeArguments = typeArguments; this.ArrayRanks = arrayRanks; this.AssemblyName = assemblyName; }
private static Attribute ConvertToRule(XmlNhvmRuleConverterArgs rule) { NhvmRule ruleRule = (NhvmRule)rule.schemaRule; string attribute = ruleRule.attribute; AssemblyQualifiedTypeName fullClassName = TypeNameParser.Parse(attribute, rule.defaultNameSpace, rule.defaultAssembly); System.Type type = ReflectHelper.ClassForFullName(fullClassName.ToString()); log.Info("The type found for ruleRule = " + type.FullName); Attribute thisattribute = (Attribute)Activator.CreateInstance(type); log.Info("Attribute found = " + thisattribute); var tr = thisattribute as ITagableRule; if (tr != null) { AssignTagsFromString(tr, ruleRule.tags); } if (ruleRule.param == null) { return(thisattribute); //eager return } foreach (NhvmParam parameter in ruleRule.param) { PropertyInfo propInfo = type.GetProperty(parameter.name); if (propInfo != null) { log.Info("propInfo value = " + parameter.value); object value = propInfo.PropertyType != typeof(string) ? Convert.ChangeType(parameter.value, propInfo.PropertyType) : parameter.value; propInfo.SetValue(thisattribute, value, null); } else { throw new InvalidPropertyNameException( string.Format("The custom attribute '{0}' don't have the property '{1}'; Check for typo.", type.FullName, parameter.name), parameter.name, type); } } return(thisattribute); }
private AssemblyQualifiedTypeName DecodeTypeArgument() { bool isTypeArgumentWithAssemblyName = false; if (Current == '[') { isTypeArgumentWithAssemblyName = true; Advance(); } AssemblyQualifiedTypeName result = DecodeTypeName(isTypeArgument: true, isTypeArgumentWithAssemblyName: isTypeArgumentWithAssemblyName); if (isTypeArgumentWithAssemblyName) { if (!EndOfInput && Current == ']') { Advance(); } } return(result); }
// // Main routine to resolve a typeReference. // private static RuntimeType TryResolveTypeReference(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeReferenceHandle typeReferenceHandle, ref Exception exception) { { ExecutionDomain executionDomain = reflectionDomain as ExecutionDomain; if (executionDomain != null) { RuntimeTypeHandle resolvedRuntimeTypeHandle; if (executionDomain.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle)) { return(ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(resolvedRuntimeTypeHandle)); } } } TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader); String name = typeReference.TypeName.GetString(reader); Handle parent = typeReference.ParentNamespaceOrType; HandleType parentType = parent.HandleType; TypeInfo outerTypeInfo = null; // Check if this is a reference to a nested type. if (parentType == HandleType.TypeDefinition) { outerTypeInfo = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, parent.ToTypeDefinitionHandle(reader)); } else if (parentType == HandleType.TypeReference) { RuntimeType outerType = reflectionDomain.TryResolveTypeReference(reader, parent.ToTypeReferenceHandle(reader), ref exception); if (outerType == null) { return(null); } outerTypeInfo = outerType.GetTypeInfo(); // Since we got to outerType via a metadata reference, we're assured GetTypeInfo() won't throw a MissingMetadataException. } if (outerTypeInfo != null) { // It was a nested type. We've already resolved the containing type recursively - just find the nested among its direct children. TypeInfo resolvedTypeInfo = outerTypeInfo.GetDeclaredNestedType(name); if (resolvedTypeInfo == null) { exception = reflectionDomain.CreateMissingMetadataException(outerTypeInfo, name); return(null); } return((RuntimeType)(resolvedTypeInfo.AsType())); } // If we got here, the typeReference was to a non-nested type. if (parentType == HandleType.NamespaceReference) { AssemblyQualifiedTypeName assemblyQualifiedTypeName = parent.ToNamespaceReferenceHandle(reader).ToAssemblyQualifiedTypeName(name, reader); RuntimeType runtimeType; exception = assemblyQualifiedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out runtimeType); if (exception != null) { return(null); } return(runtimeType); } throw new BadImageFormatException(); // Expected TypeReference parent to be typeRef, typeDef or namespaceRef. }
public LanguageConfiguration(AssemblyQualifiedTypeName providerName, string displayName, IDictionary<string, object> options) { _providerName = providerName; _displayName = displayName; _options = options; }
internal bool TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, out LanguageContext language) { Assert.NotNull(manager); LanguageConfiguration config; if (_languageConfigurations.TryGetValue(providerName, out config)) { language = LoadLanguageContext(manager, config); return true; } language = null; return false; }
public void ToStringSimple() { AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("MyType", null); Assert.AreEqual("MyType", tn.ToString()); }
/// <summary> /// Initializes a new instance of a <see cref="ReflectionBasedDriver"/> with /// type names that are loaded from the specified assembly. /// </summary> /// <param name="driverAssemblyName"> Assembly to load the driver Type from. </param> /// <param name="connectionTypeName"> Name of the driver Type. </param> protected ReflectionBasedDriver(string driverAssemblyName, string connectionTypeName) { DriverTypeName = new AssemblyQualifiedTypeName(Check.NotNullOrEmpty(connectionTypeName, nameof(connectionTypeName)), Check.NotNullOrEmpty(driverAssemblyName, nameof(driverAssemblyName))); }
public LanguageConfiguration(AssemblyQualifiedTypeName providerName, string displayName, IDictionary <string, object> options) { _providerName = providerName; _displayName = displayName; _options = options; }
public void ToStringComplex() { AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("MyType", "MyAssembly"); Assert.AreEqual("MyType, MyAssembly", tn.ToString()); }
public void ToStringEscaped() { AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("Escaped\\,Type", "Escaped\\,Assembly"); Assert.AreEqual(tn.Type + ", " + tn.Assembly, tn.ToString()); }
static Value InvokeGetType(Thread evalThread, AssemblyQualifiedTypeName name) { var sysType = evalThread.AppDomain.Compilation.FindType(KnownTypeCode.Type); var getType = sysType.GetMethods(m => m.Name == "GetType" && m.Parameters.Count == 2).FirstOrDefault(); return InvokeMethod(evalThread, getType, null, new[] { NewString(evalThread, name.ToString()), CreateValue(evalThread, false) }); }