示例#1
0
 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;
 }
示例#2
0
 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);
 }
示例#3
0
 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();
 }
示例#4
0
 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);
 }
示例#5
0
        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();
        }
示例#6
0
//		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));
                }
            }
        }
示例#7
0
        /*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();
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
 static XamlType XT <T> ()
 {
     return(sctx.GetXamlType(typeof(T)));
 }
示例#10
0
 XamlType GetType(object obj)
 {
     return(obj == null ? XamlLanguage.Null : ctx.GetXamlType(obj.GetType()));
 }
示例#11
0
 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);
        }
示例#13
0
 static XamlType XT <T> () => sctx.GetXamlType(typeof(T));