protected virtual IList <XamlType> LookupPositionalParameters(int parameterCount) { if (UnderlyingType == null /* || !IsMarkupExtension*/) // see nunit tests... { return(null); } // check if there is applicable ConstructorArgumentAttribute. // If there is, then return its type. if (parameterCount == 1) { foreach (var xm in GetAllMembers()) { var ca = xm.CustomAttributeProvider.GetCustomAttribute <ConstructorArgumentAttribute>(false); if (ca != null) { return new XamlType[] { xm.Type } } ; } } var methods = (from m in UnderlyingType.GetTypeInfo().GetConstructors() where m.GetParameters().Length == parameterCount select m).ToList(); if (methods.Count == 1) { return((from p in methods[0].GetParameters() select SchemaContext.GetXamlType(p.ParameterType)).ToList()); } if (SchemaContext.SupportMarkupExtensionsWithDuplicateArity) { throw new NotSupportedException("The default LookupPositionalParameters implementation does not allow duplicate arity of markup extensions"); } return(null); }
void ReadStartMember() { var xt = types.Peek(); var name = r.LocalName; int idx = name.IndexOf('.'); if (idx >= 0) { string tname = name.Substring(0, idx); var xtn = new XamlTypeName(r.NamespaceURI, tname, null); xt = SchemaContext.GetXamlType(xtn) ?? new XamlType(xtn.Namespace, xtn.Name, null, SchemaContext); name = name.Substring(idx + 1); } var xm = (XamlMember)FindStandardDirective(name, AllowedMemberLocations.MemberElement) ?? xt.GetAttachableMember(name) ?? xt.GetMember(name); if (xm == null) { // create unknown member. xm = new XamlMember(name, xt, false); // FIXME: not sure if isAttachable is always false. } current = current_member = xm; members.Push(xm); node_type = XamlNodeType.StartMember; inside_object_not_member = false; r.Read(); }
protected override XamlType LookupItemType() { if (EtoEnvironment.Platform.IsMono) { // mono doesn't use SchemaContext.GetXamlType here, which we need to override the type converter. var underlyingType = UnderlyingType; Type type; if (IsArray) { type = underlyingType.GetElementType(); } else if (IsDictionary) { type = !IsGeneric ? typeof(object) : underlyingType.GetGenericArguments()[1]; } else if (!IsCollection) { type = null; } else if (!IsGeneric) { type = typeof(object); } else { type = underlyingType.GetGenericArguments()[0]; } return(type != null?SchemaContext.GetXamlType(type) : null); } return(base.LookupItemType()); }
private readonly StringBuilder textBuffer = new StringBuilder(); // current text buffer to collect all words #region -- Ctor/Dtor ---------------------------------------------------------- /// <summary>Initializes a new instance of the <see cref="XamlMarkdownWriter"/> class.</summary> /// <param name="writer">Target for the xaml content.</param> public XamlMarkdownWriter(XamlWriter writer) { this.writer = writer ?? throw new ArgumentNullException(nameof(writer)); this.runType = SchemaContext.GetXamlType(typeof(Run)) ?? throw new ArgumentNullException(nameof(Run)); this.runTextMember = runType.GetMember(nameof(Run.Text)) ?? throw new ArgumentNullException(nameof(Run.Text)); // Default block renderers ObjectRenderers.Add(new CodeBlockRenderer()); ObjectRenderers.Add(new ListRenderer()); ObjectRenderers.Add(new HeadingRenderer()); ObjectRenderers.Add(new ParagraphRenderer()); ObjectRenderers.Add(new QuoteBlockRenderer()); ObjectRenderers.Add(new ThematicBreakRenderer()); // Default inline renderers ObjectRenderers.Add(new AutolinkInlineRenderer()); ObjectRenderers.Add(new CodeInlineRenderer()); ObjectRenderers.Add(new DelimiterInlineRenderer()); ObjectRenderers.Add(new EmphasisInlineRenderer()); ObjectRenderers.Add(new EntityInlineRenderer()); ObjectRenderers.Add(new LineBreakInlineRenderer()); ObjectRenderers.Add(new LinkInlineRenderer()); ObjectRenderers.Add(new LiteralInlineRenderer()); // Extension renderers ObjectRenderers.Add(new TableRenderer()); ObjectRenderers.Add(new TaskListRenderer()); } // ctor
bool IsCollectionType(Type type) { if (type == null) { return(false); } var xt = SchemaContext.GetXamlType(type); return(xt.LookupCollectionKind() != XamlCollectionKind.None); }
protected virtual XamlType LookupBaseType() { if (UnderlyingType == null) { return(SchemaContext.GetXamlType(typeof(object))); } else { return(type.GetTypeInfo().BaseType == null || type.GetTypeInfo().BaseType == typeof(object) ? null : SchemaContext.GetXamlType(type.GetTypeInfo().BaseType)); } }
protected virtual XamlType LookupKeyType() { if (!IsDictionary) { return(null); } if (!IsGeneric) { return(SchemaContext.GetXamlType(typeof(object))); } return(SchemaContext.GetXamlType(type.GetTypeInfo().GetGenericArguments()[0])); }
private void ValidateUnknown(XamlMember member) { if (member == XamlLanguage.UnknownContent) { ValidationError(SR.MemberUnknownContect(GetXamlTypeName(_stack.TopFrame.Type))); } else if (member.IsUnknown) { bool retryAttachable = false; XamlType declaringType = member.DeclaringType; if (_stack.Depth == 1 && declaringType.IsUnknown && !string.IsNullOrEmpty(this.rootNamespace) && this.definedType != null && declaringType.Name == this.definedType.Name) { // Need to handle the case where the namespace of a member on the document root // is missing the project root namespace string clrNs; if (XamlBuildTaskServices.TryExtractClrNs(declaringType.PreferredXamlNamespace, out clrNs)) { clrNs = string.IsNullOrEmpty(clrNs) ? this.rootNamespace : this.rootNamespace + "." + clrNs; if (clrNs == this.definedType.Namespace) { declaringType = SchemaContext.GetXamlType(this.definedType); retryAttachable = true; } } } XamlMember typeMember = declaringType.GetMember(member.Name); if (typeMember == null && retryAttachable) { typeMember = declaringType.GetAttachableMember(member.Name); } if (typeMember == null || typeMember.IsUnknown) { if (member.IsAttachable) { ValidationError(SR.UnresolvedAttachableMember(GetXamlTypeName(member.DeclaringType) + "." + member.Name)); } else if (member.IsDirective) { ValidationError(SR.UnresolvedDirective(member.PreferredXamlNamespace + ":" + member.Name)); } else { // Skip if declaring type is unknown as the member unknown error messages become redundant. if (declaringType != null && !declaringType.IsUnknown) { ValidationError(SR.UnresolvedMember(member.Name, GetXamlTypeName(declaringType))); } } } } }
protected override XamlType LookupTargetType() { MethodInfo mi = (ClrBindingGetterMethodInfo != null) ? ClrBindingGetterMethodInfo : ClrBindingSetterMethodInfo; ParameterInfo[] parameters = mi.GetParameters(); Type paramType = parameters[0].ParameterType; XamlType targetType = SchemaContext.GetXamlType(paramType); return(targetType); }
protected virtual XamlType LookupBaseType() { if (base_type == null) { if (UnderlyingType == null) { base_type = SchemaContext.GetXamlType(typeof(object)); } else { base_type = type.BaseType == null || type.BaseType == typeof(object) ? null : SchemaContext.GetXamlType(type.BaseType); } } return(base_type); }
protected virtual XamlType LookupItemType() { if (itemType != null) { return(itemType); } var kind = LookupCollectionKind(); if (kind == XamlCollectionKind.Array) { itemType = SchemaContext.GetXamlType(type.GetElementType()); } else if (kind == XamlCollectionKind.Dictionary) { if (!IsGeneric) { itemType = SchemaContext.GetXamlType(typeof(object)); } else { itemType = SchemaContext.GetXamlType(type.GetTypeInfo().GetGenericArguments()[1]); } } else if (kind != XamlCollectionKind.Collection) { return(null); } else if (!IsGeneric) { // support custom collections that inherit ICollection<T> var collectionType = type.GetTypeInfo().GetInterfaces().FirstOrDefault(r => r.GetTypeInfo().IsGenericType&& r.GetGenericTypeDefinition() == typeof(ICollection <>)); if (collectionType != null) { itemType = SchemaContext.GetXamlType(collectionType.GetTypeInfo().GetGenericArguments()[0]); } else { itemType = SchemaContext.GetXamlType(typeof(object)); } } else { itemType = SchemaContext.GetXamlType(type.GetTypeInfo().GetGenericArguments()[0]); } return(itemType); }
protected virtual XamlType LookupTargetType() { if (IsAttachable) { MethodInfo accessor = UnderlyingMember as MethodInfo; if (accessor != null) { ParameterInfo[] parameters = accessor.GetParameters(); if (parameters.Length > 0) { Type result = parameters[0].ParameterType; return(SchemaContext.GetXamlType(result)); } } return(XamlLanguage.Object); } return(_declaringType); }
protected virtual IList <XamlType> LookupContentWrappers() { if (GetCustomAttributeProvider() == null) { return(null); } var arr = GetCustomAttributeProvider().GetCustomAttributes(typeof(ContentWrapperAttribute), false); if (arr == null || arr.Length == 0) { return(null); } var l = new XamlType [arr.Length]; for (int i = 0; i < l.Length; i++) { l [i] = SchemaContext.GetXamlType(((ContentWrapperAttribute)arr [i]).ContentWrapper); } return(l); }
protected override IList <XamlType> LookupPositionalParameters(int paramCount) { if (this.IsMarkupExtension) { List <XamlType> xTypes = null; Baml6ConstructorInfo info = Constructors[paramCount]; if (Constructors.TryGetValue(paramCount, out info)) { xTypes = new List <XamlType>(); foreach (Type type in info.Types) { xTypes.Add(SchemaContext.GetXamlType(type)); } } return(xTypes); } else { return(base.LookupPositionalParameters(paramCount)); } }
private XamlMember CreateXamlProperty(PropertyDescriptor property, bool skipReadOnlyCheck) { XamlType declaringType = this; if (property.IsReadOnly) { if (!skipReadOnlyCheck && !AllowAsReadOnly(property)) { return(null); } // The property might actually be defined on a base type, but not returned by // GetInheritedMember because it is read-only. // If so, we should set its declaringType to the base type. if (skipReadOnlyCheck && property.ComponentType != UnderlyingType && TypeDescriptor.GetProperties(property.ComponentType)[property.Name] == property) { declaringType = SchemaContext.GetXamlType(property.ComponentType); } } return(new PropertyDescriptorXamlMember(property, declaringType)); }
public XamlObjectReader(object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings) { if (schemaContext == null) { throw new ArgumentNullException("schemaContext"); } // FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array. if (instance is Type) { instance = new TypeExtension((Type)instance); } // See also Instance property for this weirdness. this.root_raw = instance; instance = TypeExtensionMethods.GetExtensionWrapped(instance); this.root = instance; sctx = schemaContext; this.settings = settings ?? new XamlObjectReaderSettings(); // check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:) if (instance != null) { var type = new InstanceContext(instance).GetRawValue().GetType(); if (!type.GetTypeInfo().IsPublic) { throw new XamlObjectReaderException(String.Format("instance type '{0}' must be public and non-nested.", type)); } var xt = SchemaContext.GetXamlType(type); if (xt.ConstructionRequiresArguments && xt.GetConstructorArguments().Count == 0 && xt.TypeConverter == null) { throw new XamlObjectReaderException(String.Format("instance type '{0}' has no default constructor.", type)); } } value_serializer_context = new ValueSerializerContext(new PrefixLookup(sctx), sctx, null, null, null, null); new XamlObjectNodeIterator(instance, sctx, value_serializer_context, this.settings).PrepareReading(); }
protected virtual bool LookupIsXData() { return(ReflectionHelpers.IXmlSerializableType != null && CanAssignTo(SchemaContext.GetXamlType(ReflectionHelpers.IXmlSerializableType))); }
protected override XamlType LookupBaseType() { return(SchemaContext.GetXamlType(Descriptor.GetType())); }
private void ValidateValueToMemberOnStack(object value) { XamlMember member = _stack.TopFrame.Member; if (member.IsUnknown) { return; } if (value != null) { if (member.IsEvent) { if (this.definedType != null && this.definedType.GetMethod(value as string, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) == null) { ValidationError(SR.UnexpectedXamlEventHandlerNotFound(value, definedType.FullName)); } return; } else if (member == XamlLanguage.Class) { string className = value as string; Fx.Assert(!string.IsNullOrEmpty(className), "ClassName cannot be null"); if (!string.IsNullOrEmpty(this.rootNamespace)) { className = this.rootNamespace + "." + className; } if (this.assembly != null) { this.definedType = this.assembly.GetType(className); } return; } else if (member.TypeConverter != null) { return; } XamlType typeOfValue = SchemaContext.GetXamlType(value.GetType()); ValidateTypeToMemberOnStack(typeOfValue); } else { if (member == XamlLanguage.PositionalParameters) { return; } if (member == XamlLanguage.Items) { XamlType collectionType = GetCollectionTypeOnStack(); if (collectionType == null || collectionType.IsUnknown || collectionType.AllowedContentTypes == null) { return; } if (!collectionType.AllowedContentTypes.Any(contentType => contentType.IsNullable)) { ValidationError(SR.UnassignableCollection("(null)", GetXamlTypeName(collectionType.ItemType), GetXamlTypeName(collectionType))); } } else { if (!member.Type.IsNullable) { ValidationError(SR.UnassignableTypes("(null)", GetXamlTypeName(member.Type), member.Name)); } } } }
protected virtual XamlType LookupType() { Type systemType = LookupSystemType(); return((systemType != null) ? SchemaContext.GetXamlType(systemType) : null); }
protected virtual XamlType LookupMarkupExtensionReturnType() { var a = this.GetCustomAttribute <MarkupExtensionReturnTypeAttribute>(); return(a != null?SchemaContext.GetXamlType(a.ReturnType) : null); }
protected virtual bool LookupIsXData() { return(CanAssignTo(SchemaContext.GetXamlType(typeof(IXmlSerializable)))); }
private bool AllowAsReadOnly(PropertyDescriptor property) { XamlType propertyType = SchemaContext.GetXamlType(property.PropertyType); return(propertyType.IsCollection || propertyType.IsDictionary || propertyType.IsXData); }