Пример #1
0
 /// <summary>Get implicit key property name: TargetType for Style, DataType for DataTemplate etc.</summary>
 private static string GetObjectImplicitKeyPropName (TokenTypeInfo objInfo)
 {
     if (DictionaryKeyProps.ContainsKey(objInfo.Type))
         return DictionaryKeyProps[objInfo.Type];
     else {
         var attrDictKey = objInfo.Type.GetCustomAttributes<DictionaryKeyPropertyAttribute>().FirstOrDefault();
         if (attrDictKey != null)
             return attrDictKey.Name;
     }
     return null;
 }
Пример #2
0
 private TokenTypeInfo GetTypeInfo (JToken token)
 {
     if (token == null)
         return new TokenTypeInfo(this);
     if (token.Type == JTokenType.Array)
         token = token.Parent;
     TokenTypeInfo typeInfo;
     if (_typeInfos.TryGetValue(token, out typeInfo))
         return typeInfo;
     else
         return _typeInfos[token] = new TokenTypeInfo(this);
 }
Пример #3
0
        /// <summary>Get XAttributes for object identifiers: x:Name/x:Key="objIdExplicit" ImplicitKey="objKeyImplicit".</summary>
        private IEnumerable<XAttribute> GetXAttrsObjectIds (string objId, TokenTypeInfo objInfo)
        {
            if (objId == null)
                yield break;
            string objIdExplicit = objId, objIdImplicit = null, propKey = GetObjectImplicitKeyPropName(objInfo), typeName = null;

            if (propKey != null) {
                int spacePos = objId.IndexOf(' ');
                if (spacePos != -1) {
                    objIdExplicit = objId.Substring(0, spacePos);
                    objIdImplicit = objId.Substring(spacePos + 1);
                }
                else {
                    objIdExplicit = null;
                    objIdImplicit = objId;
                }
                Type propKeyType = GetPropertyType(objInfo.Type, propKey);
                if (propKeyType == typeof(Type)) {
                    typeName = objIdImplicit;
                    objIdImplicit = String.Format("{{x:Type {0}}}", objIdImplicit);
                }
            }

            if (typeName != null)
                objInfo.TargetType = GetTypeByName(typeName);

            bool isContDict = objInfo.PropertyContainerType != null && IsTypeDictionary(objInfo.PropertyContainerType);
            if (objIdExplicit != null)
                yield return new XAttribute(
                    NsX + (isContDict ? XamlLanguage.Key.Name : XamlLanguage.Name.Name),
                    objIdExplicit);
            if (objIdImplicit != null)
                yield return new XAttribute(propKey, FormatScalarPropertyValue(objIdImplicit));
        }