コード例 #1
0
 private static void CopyToCustomMetadata(ModelMetadata baseMetadata, ArtifyModelMetadata customMetadata)
 {
     foreach (Tuple <FieldInfo, FieldInfo> t in _fieldsMap)
     {
         t.Item1.SetValue(customMetadata, t.Item2.GetValue(baseMetadata));
     }
 }
コード例 #2
0
    protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
    {
        ArtifyModelMetadata modelMetadata = new ArtifyModelMetadata(this, containerType, modelAccessor, modelType, propertyName);

        CopyToCustomMetadata(base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName), modelMetadata);

        ModelMetadataAttribute      mma;
        Dictionary <string, string> htmlAttributes;
        object tmp;

        foreach (Attribute a in attributes)
        {
            mma = a as ModelMetadataAttribute;
            if (mma != null)
            {
                mma.Process(modelMetadata);
                htmlAttributes = mma.GetAdditionnalHtmlAttributes();
                if (htmlAttributes != null)
                {
                    foreach (KeyValuePair <string, string> p in htmlAttributes)
                    {
                        tmp = null;
                        tmp = modelMetadata.AdditionnalHtmlAttributes.TryGetValue(p.Key, out tmp);
                        if (tmp == null)
                        {
                            modelMetadata.AdditionnalHtmlAttributes.Add(p.Key, p.Value);
                        }
                        else
                        {
                            modelMetadata.AdditionnalHtmlAttributes[p.Key] = tmp.ToString() + " " + p.Value;
                        }
                    }
                }
            }
            if (mma is TooltipAttribute)
            {
                modelMetadata.HasToolTip = true;
            }
        }

        return(modelMetadata);
    }