当前位置: 首页>>代码示例>>C#>>正文


C# XamlType.CanAssignTo方法代码示例

本文整理汇总了C#中XamlType.CanAssignTo方法的典型用法代码示例。如果您正苦于以下问题:C# XamlType.CanAssignTo方法的具体用法?C# XamlType.CanAssignTo怎么用?C# XamlType.CanAssignTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XamlType的用法示例。


在下文中一共展示了XamlType.CanAssignTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDottedProperty

 public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot)
 {
     if (tagType == null)
     {
         throw new XamlInternalException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { propName.ScopedName }));
     }
     XamlMember xamlAttachableProperty = null;
     XamlType xamlType = null;
     string propNs = this.ResolveXamlNameNS(propName);
     if (propNs == null)
     {
         throw new XamlParseException(System.Xaml.SR.Get("PrefixNotFound", new object[] { propName.Prefix }));
     }
     XamlType rootTagType = tagIsRoot ? tagType : null;
     bool flag = false;
     if (tagType.IsGeneric)
     {
         flag = this.PropertyTypeMatchesGenericTagType(tagType, tagNamespace, propNs, propName.OwnerName);
         if (flag)
         {
             xamlAttachableProperty = this.GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType);
             if (xamlAttachableProperty != null)
             {
                 return xamlAttachableProperty;
             }
         }
     }
     XamlTypeName typeName = new XamlTypeName(propNs, propName.Owner.Name);
     xamlType = this.GetXamlType(typeName, true);
     bool flag2 = tagType.CanAssignTo(xamlType);
     if (flag2)
     {
         xamlAttachableProperty = this.GetInstanceOrAttachableProperty(xamlType, propName.Name, rootTagType);
     }
     else
     {
         xamlAttachableProperty = this.GetXamlAttachableProperty(xamlType, propName.Name);
     }
     if (xamlAttachableProperty != null)
     {
         return xamlAttachableProperty;
     }
     XamlType declaringType = flag ? tagType : xamlType;
     if (flag || flag2)
     {
         return this.CreateUnknownMember(declaringType, propName.Name);
     }
     return this.CreateUnknownAttachableMember(declaringType, propName.Name);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:49,代码来源:XamlContext.cs

示例2: ValidateTypeToMemberOnStack

 private void ValidateTypeToMemberOnStack(XamlType type)
 {
     if (type.IsUnknown)
     {
         return;
     }
     if (type == this.xNull)
     {
         ValidateValueToMemberOnStack(null);
     }
     XamlMember member = _stack.TopFrame.Member;
     if (member == XamlLanguage.PositionalParameters || type.IsMarkupExtension || member.IsUnknown)
     {
         return;
     }
     if (member == XamlLanguage.Items)
     {
         XamlType collectionType = GetCollectionTypeOnStack();
         if (collectionType == null || collectionType.IsUnknown || collectionType.AllowedContentTypes == null)
         {
             return;
         }
         if (!collectionType.AllowedContentTypes.Any(contentType => type.CanAssignTo(contentType)))
         {
             ValidationError(SR.UnassignableCollection(GetXamlTypeName(type), GetXamlTypeName(collectionType.ItemType), GetXamlTypeName(collectionType)));
         }
     }
     else if (member.IsDirective && (member.Type.IsCollection || member.Type.IsDictionary))
     {
         XamlType collectionType = member.Type;
         if (collectionType == null || collectionType.IsUnknown || collectionType.AllowedContentTypes == null)
         {
             return;
         }
         if (!collectionType.AllowedContentTypes.Any(contentType => type.CanAssignTo(contentType)))
         {
             ValidationError(SR.UnassignableCollection(GetXamlTypeName(type), GetXamlTypeName(collectionType.ItemType), GetXamlTypeName(collectionType)));
         }
     }
     else if (!type.CanAssignTo(member.Type))
     {
         if (member.DeferringLoader != null)
         {
             return;
         }
         if (NodeType == XamlNodeType.Value)
         {
             ValidationError(SR.UnassignableTypes(GetXamlTypeName(type), GetXamlTypeName(member.Type), member.Name));
         }
         else
         {
             ValidationError(SR.UnassignableTypesObject(GetXamlTypeName(type), GetXamlTypeName(member.Type), member.Name));
         }
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:55,代码来源:XamlValidatingReader.cs

示例3: ValidateMemberOnType

 private void ValidateMemberOnType(XamlMember member, XamlType type)
 {
     if (member.IsUnknown || type.IsUnknown)
     {
         return;
     }
     if (member.IsDirective)
     {
         if (member == XamlLanguage.Items)
         {
             if (!type.IsCollection && !type.IsDictionary)
             {
                 ValidationError(SR.UnexpectedXamlDictionary(member.Name, GetXamlTypeName(_stack.TopFrame.Type)));
             }
         }
         if (member == XamlLanguage.Class && _stack.Depth > 1)
         {
             ValidationError(SR.UnexpectedXamlClass);
         }
     }
     else if (member.IsAttachable)
     {
         if (!type.CanAssignTo(member.TargetType))
         {
             ValidationError(SR.UnexpectedXamlAttachableMember(member.Name, GetXamlTypeName(member.TargetType)));
         }
     }
     else if (!member.IsDirective && !type.CanAssignTo(member.DeclaringType))
     {
         ValidationError(SR.UnexpectedXamlMemberNotAssignable(member.Name, GetXamlTypeName(type)));
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:32,代码来源:XamlValidatingReader.cs

示例4: GetProperty

        internal XamlMember GetProperty(Int16 propertyId, XamlType parentType)
        {
            BamlProperty bamlProperty;
            XamlMember xamlMember;

            if (TryGetBamlProperty(propertyId, out bamlProperty, out xamlMember))
            {
                if (xamlMember != null)
                {
                    return xamlMember;
                }
                XamlType declaringType = GetXamlType(bamlProperty.DeclaringTypeId);

                // If the parent type & declaring type are assignable, then it could
                // be either a regular property or attachable.
                if (parentType.CanAssignTo(declaringType))
                {
                    xamlMember = declaringType.GetMember(bamlProperty.Name);
                    if (xamlMember == null)
                    {
                        xamlMember = declaringType.GetAttachableMember(bamlProperty.Name);
                    }
                }
                else
                {
                    //If not assignable, it has to be an attachable member
                    xamlMember = declaringType.GetAttachableMember(bamlProperty.Name);
                }
                lock (_syncObject)
                {
                    _bamlProperty[propertyId] = xamlMember;
                }
                return xamlMember;
            }

            throw new KeyNotFoundException();
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:37,代码来源:Baml2006SchemaContext.cs

示例5: GetAddMethod

 public virtual MethodInfo GetAddMethod(XamlType contentType)
 {
     if (contentType == null)
     {
         throw new ArgumentNullException("contentType");
     }
     if (!this.IsUnknown && (this._xamlType.ItemType != null))
     {
         MethodInfo addMethod;
         if ((contentType == this._xamlType.ItemType) || ((this._xamlType.AllowedContentTypes.Count == 1) && contentType.CanAssignTo(this._xamlType.ItemType)))
         {
             return this._xamlType.AddMethod;
         }
         if (!this._xamlType.IsCollection)
         {
             return null;
         }
         if (this._addMethods == null)
         {
             Dictionary<XamlType, MethodInfo> dictionary = new Dictionary<XamlType, MethodInfo>();
             dictionary.Add(this._xamlType.ItemType, this._xamlType.AddMethod);
             foreach (XamlType type in this._xamlType.AllowedContentTypes)
             {
                 addMethod = CollectionReflector.GetAddMethod(this._xamlType.UnderlyingType, type.UnderlyingType);
                 if (addMethod != null)
                 {
                     dictionary.Add(type, addMethod);
                 }
             }
             this._addMethods = dictionary;
         }
         if (this._addMethods.TryGetValue(contentType, out addMethod))
         {
             return addMethod;
         }
         foreach (KeyValuePair<XamlType, MethodInfo> pair in this._addMethods)
         {
             if (contentType.CanAssignTo(pair.Key))
             {
                 return pair.Value;
             }
         }
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:45,代码来源:XamlTypeInvoker.cs

示例6: InjectPropertyAndFrameIfNeeded

        private void InjectPropertyAndFrameIfNeeded(XamlType elementType, SByte flags)
        {
            // If we saved the Node stream for the first ME element of a dictionary to 
            // check if it had a key then process that now.
            if (_lookingForAKeyOnAMarkupExtensionInADictionaryDepth == _context.CurrentFrame.Depth) 
            { 
                RestoreSavedFirstItemInDictionary();
            } 

            XamlType parentType = _context.CurrentFrame.XamlType;
            XamlMember parentProperty = _context.CurrentFrame.Member;
 
            if (parentType != null)
            { 
                if (parentProperty == null) 
                {
                    // We have got two consecutive ElementStart records 
                    // We must insert an implicit content property between them
                    if (_context.CurrentFrame.ContentProperty != null)
                    {
                        _context.CurrentFrame.Member = parentProperty = _context.CurrentFrame.ContentProperty; 
                    }
                    else if (parentType.ContentProperty != null) 
                    { 
                        _context.CurrentFrame.Member = parentProperty = parentType.ContentProperty;
                    } 
                    else
                    {
                        if (parentType.IsCollection || parentType.IsDictionary)
                        { 
                            _context.CurrentFrame.Member = parentProperty = XamlLanguage.Items;
                        } 
                        else if (parentType.TypeConverter != null) 
                        {
                            _context.CurrentFrame.Member = parentProperty = XamlLanguage.Initialization; 
                        }
                        else
                        {
                            throw new XamlParseException(SR.Get(SRID.RecordOutOfOrder, parentType.Name)); 
                        }
                    } 
                    _context.CurrentFrame.Flags = Baml2006ReaderFrameFlags.HasImplicitProperty; 
                    _xamlNodesWriter.WriteStartMember(parentProperty);
 
                    // if we are NOT already spooling a template
                    if (_context.TemplateStartDepth < 0 && _isBinaryProvider)
                    {
                        if (parentProperty == BamlSchemaContext.FrameworkTemplateTemplateProperty) 
                        {
                            // If this is a template then spool the template into a Node List. 
                            _context.TemplateStartDepth = _context.CurrentFrame.Depth; 
                            _xamlTemplateNodeList = new XamlNodeList(_xamlNodesWriter.SchemaContext);
 
                            _xamlWriterStack.Push(_xamlNodesWriter);
                            _xamlNodesWriter = _xamlTemplateNodeList.Writer;
                        }
                    } 
                }
 
                XamlType parentPropertyType = parentProperty.Type; 
                // Normally an error except for collections
                if (parentPropertyType != null && (parentPropertyType.IsCollection || parentPropertyType.IsDictionary) && 
                    !parentProperty.IsDirective && (flags & ReaderFlags_AddedToTree) == 0)
                {
                    bool emitPreamble = false;
 
                    // If the collection property is Readonly then "retrieve" the collection.
                    if (parentProperty.IsReadOnly) 
                    { 
                        emitPreamble = true;
                    } 
                    // OR if the Value isn't assignable to the Collection emit the preable.
                    else if (!elementType.CanAssignTo(parentPropertyType))
                    {
                        // UNLESS: the Value is a Markup extension, then it is assumed that 
                        // the ProvidValue type will be AssignableFrom.
                        if (!elementType.IsMarkupExtension) 
                        { 
                            emitPreamble = true;
                        } 
                        // EXCEPT: if the BAML said it was Retrived
                        else if (_context.CurrentFrame.Flags == Baml2006ReaderFrameFlags.HasImplicitProperty)
                        {
                            emitPreamble = true; 
                        }
                        // OR: the ME is Array 
                        else if (elementType == XamlLanguage.Array) 
                        {
                            emitPreamble = true; 
                        }
                    }
                    if (emitPreamble)
                    { 
                        EmitGoItemsPreamble(parentPropertyType);
                    } 
 
                    // We may need to look for an x:Key on the ME in a dictionary.
                    // so save up the node stream for the whole element definition and check it 
                    // for an x:Key later.
                    if (!emitPreamble && parentPropertyType.IsDictionary && elementType.IsMarkupExtension)
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:Baml2006Reader.cs


注:本文中的XamlType.CanAssignTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。