public XamlMember(string attachableEventName, MethodInfo adder, XamlSchemaContext schemaContext, XamlMemberInvoker invoker) : this(schemaContext, invoker) { if (attachableEventName == null) { throw new ArgumentNullException("attachableEventName"); } if (adder == null) { throw new ArgumentNullException("adder"); } Name = attachableEventName; VerifyAdderSetter(adder); underlying_member = adder; DeclaringType = schemaContext.GetXamlType(adder.DeclaringType); target_type = schemaContext.GetXamlType(typeof(object)); UnderlyingSetter = adder; is_event = true; is_attachable = true; }
public XamlMember(string attachablePropertyName, MethodInfo getter, MethodInfo setter, XamlSchemaContext schemaContext, XamlMemberInvoker invoker) : this(schemaContext, invoker) { if (attachablePropertyName == null) { throw new ArgumentNullException("attachablePropertyName"); } if (getter == null && setter == null) { throw new ArgumentNullException("getter", "Either property getter or setter must be non-null."); } Name = attachablePropertyName; VerifyGetter(getter); VerifyAdderSetter(setter); underlying_member = getter ?? setter; DeclaringType = schemaContext.GetXamlType(underlying_member.DeclaringType); target_type = schemaContext.GetXamlType(typeof(object)); underlying_getter = getter; underlying_setter = setter; flags.Set(MemberFlags.IsAttachable, true); }
public XamlMember(PropertyInfo propertyInfo, XamlSchemaContext schemaContext, XamlMemberInvoker invoker) : this(schemaContext, invoker) { if (propertyInfo == null) { throw new ArgumentNullException("propertyInfo"); } Name = propertyInfo.Name; underlying_member = propertyInfo; DeclaringType = schemaContext.GetXamlType(propertyInfo.DeclaringType); target_type = DeclaringType; underlying_getter = propertyInfo.GetPrivateGetMethod(); underlying_setter = propertyInfo.GetPrivateSetMethod(); }
public XamlMember(EventInfo eventInfo, XamlSchemaContext schemaContext, XamlMemberInvoker invoker) : this(schemaContext, invoker) { if (eventInfo == null) { throw new ArgumentNullException("eventInfo"); } Name = eventInfo.Name; underlying_member = eventInfo; DeclaringType = schemaContext.GetXamlType(eventInfo.DeclaringType); target_type = DeclaringType; underlying_setter = eventInfo.GetAddMethod(); flags.Set(MemberFlags.IsDefaultEvent, true); }
public void Parse() { //Get all inside brackets if (value.Length > 1 && (value[0] != '{' || value[value.Length - 1] != '}')) { throw new XamlParseException("Invalid markup extension attribute. It should begin with '{{' and end with '}}'"); } value = value.Substring(1, value.Length - 2); Name = ReadUntil(' ', true); XamlTypeName xtn; if (!XamlTypeName.TryParse(Name, nsResolver, out xtn)) { throw Error("Failed to parse type name '{0}'", Name); } var xtnFirst = new XamlTypeName(xtn.Namespace, xtn.Name + "Extension", xtn.TypeArguments); Type = sctx.GetXamlType(xtnFirst) ?? sctx.GetXamlType(xtn) ?? new XamlType(xtn.Namespace, xtn.Name, null, sctx); ParseArgument(); }
// static readonly Type [] predefined_types = { // typeof (XData), typeof (Uri), typeof (TimeSpan), typeof (PropertyDefinition), typeof (MemberDefinition), typeof (Reference) // }; public XamlType(Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker) : this(schemaContext, invoker) { if (underlyingType == null) { throw new ArgumentNullException("underlyingType"); } type = underlyingType; underlying_type = type; XamlType xt; if (XamlLanguage.InitializingTypes) { // These are special. Only XamlLanguage members are with shorthand name. if (type == typeof(PropertyDefinition)) { Name = "Property"; } else if (type == typeof(MemberDefinition)) { Name = "Member"; } else { Name = GetXamlName(type); } PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace; } else if ((xt = XamlLanguage.AllTypes.FirstOrDefault(t => t.UnderlyingType == type)) != null) { Name = xt.Name; PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace; } else { Name = GetXamlName(type); PreferredXamlNamespace = schemaContext.GetXamlNamespace(type.Namespace) ?? String.Format("clr-namespace:{0};assembly={1}", type.Namespace, type.GetTypeInfo().Assembly.GetName().Name); } if (type.GetTypeInfo().IsGenericType) { TypeArguments = new List <XamlType> (); foreach (var gta in type.GetTypeInfo().GetGenericArguments()) { TypeArguments.Add(schemaContext.GetXamlType(gta)); } } }
/*mscorlib_types.Where(r => r != null) * .Select(r => r.GetTypeInfo().Assembly) * .Distinct() * .ToArray();*/ // static readonly Type [] predefined_types = { // typeof (XData), typeof (Uri), typeof (TimeSpan), typeof (PropertyDefinition), typeof (MemberDefinition), typeof (Reference) // }; public XamlType(Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker) : this(schemaContext, invoker) { if (underlyingType == null) { throw new ArgumentNullException("underlyingType"); } type = underlyingType; underlying_type = type; XamlType xt; if (XamlLanguage.InitializingTypes) { // These are special. Only XamlLanguage members are with shorthand name. if (type == typeof(PropertyDefinition)) { Name = "Property"; } else if (type == typeof(MemberDefinition)) { Name = "Member"; } else { Name = GetXamlName(type); } preferredXamlNamespace = XamlLanguage.Xaml2006Namespace; } else if (!ReferenceEquals(xt = XamlLanguage.AllTypes.FirstOrDefault(t => t.UnderlyingType == type), null)) { Name = xt.Name; preferredXamlNamespace = XamlLanguage.Xaml2006Namespace; } else { Name = GetXamlName(type); } if (type.GetTypeInfo().IsGenericType) { TypeArguments = type.GetTypeInfo().GetGenericArguments().Select(r => schemaContext.GetXamlType(r)).ToReadOnly(); } }
public void Parse() { if (!Read('{')) { throw Error("Invalid markup extension attribute. It should begin with '{{', but was {0}", value); } Name = ReadUntil(' ', true); XamlTypeName xtn; if (!XamlTypeName.TryParse(Name, nsResolver, out xtn)) { throw Error("Failed to parse type name '{0}'", Name); } Type = sctx.GetXamlType(xtn); ParseArgument(); if (!Read('}')) { throw Error("Expected '}}' in the markup extension attribute: '{0}'", value); } }
static XamlType XT <T> () { return(sctx.GetXamlType(typeof(T))); }
XamlType GetType(object obj) { return(obj == null ? XamlLanguage.Null : ctx.GetXamlType(obj.GetType())); }
protected virtual XamlType LookupType() { return(context.GetXamlType(DoGetType())); }
public static ParsedMarkupExtensionInfo Parse(string raw, IXamlNamespaceResolver nsResolver, XamlSchemaContext sctx) { if (raw == null) { throw new ArgumentNullException("raw"); } if (raw.Length == 0 || raw [0] != '{') { throw Error("Invalid markup extension attribute. It should begin with '{{', but was {0}", raw); } var ret = new ParsedMarkupExtensionInfo(); int idx = raw.IndexOf('}'); if (idx < 0) { throw Error("Expected '}}' in the markup extension attribute: '{0}'", raw); } raw = raw.Substring(1, idx - 1); idx = raw.IndexOf(' '); string name = idx < 0 ? raw : raw.Substring(0, idx); XamlTypeName xtn; if (!XamlTypeName.TryParse(name, nsResolver, out xtn)) { throw Error("Failed to parse type name '{0}'", name); } var xt = sctx.GetXamlType(xtn); ret.Type = xt; if (idx < 0) { return(ret); } string [] vpairs = raw.Substring(idx + 1, raw.Length - idx - 1).Split(','); List <string> posPrms = null; foreach (string vpair in vpairs) { idx = vpair.IndexOf('='); // FIXME: unescape string (e.g. comma) if (idx < 0) { if (posPrms == null) { posPrms = new List <string> (); ret.Arguments.Add(XamlLanguage.PositionalParameters, posPrms); } posPrms.Add(UnescapeValue(vpair.Trim())); } else { var key = vpair.Substring(0, idx).Trim(); // FIXME: is unknown member always isAttacheable = false? var xm = xt.GetMember(key) ?? new XamlMember(key, xt, false); ret.Arguments.Add(xm, UnescapeValue(vpair.Substring(idx + 1).Trim())); } } return(ret); }
static XamlType XT <T> () => sctx.GetXamlType(typeof(T));