IXamlType EmitTypeDescriptorContextStub(IXamlTypeSystem typeSystem, IXamlTypeBuilder <IXamlILEmitter> builder, XamlLanguageTypeMappings mappings) { if (mappings.TypeDescriptorContext == null) { return(null); } var tdc = mappings.TypeDescriptorContext; var tdcPrefix = tdc.Namespace + "." + tdc.Name + "."; builder.AddInterfaceImplementation(mappings.TypeDescriptorContext); void PropertyStub(string name) => ImplementInterfacePropertyGetter(builder, tdc, name).Generator.Ldnull().Ret(); PropertyStub("Container"); PropertyStub("Instance"); PropertyStub("PropertyDescriptor"); void MethodStub(string name) { var original = tdc.FindMethod(m => m.Name == name); builder.DefineMethod(original.ReturnType, original.Parameters, tdcPrefix + name, false, false, true, original) .Generator .Emit(OpCodes.Newobj, typeSystem.FindType("System.NotSupportedException").FindConstructor(new List <IXamlType>())) .Emit(OpCodes.Throw); } MethodStub("OnComponentChanging"); MethodStub("OnComponentChanged"); return(mappings.TypeDescriptorContext); }
public static IXamlType GetType(this IXamlTypeSystem sys, string type) { var f = sys.FindType(type); if (f == null) { throw new XamlTypeSystemException("Unable to resolve type " + type); } return(f); }
private static void EmitNameScopeField(XamlLanguageTypeMappings mappings, IXamlTypeSystem typeSystem, IXamlTypeBuilder <IXamlILEmitter> typebuilder, IXamlILEmitter constructor) { var nameScopeType = typeSystem.FindType("Avalonia.Controls.INameScope"); var field = typebuilder.DefineField(nameScopeType, ContextNameScopeFieldName, true, false); constructor .Ldarg_0() .Ldarg(1) .Ldtype(nameScopeType) .EmitCall(mappings.ServiceProvider.GetMethod(new FindMethodMethodSignature("GetService", typeSystem.FindType("System.Object"), typeSystem.FindType("System.Type")))) .Stfld(field); }