Exemple #1
0
        private static void ResolveViewModelName(MemberDefinition member,
                                                 ViewModelSettings viewModel, RenderSettings settings)
        {
            var namespaces = member.Dependencies();

            // if we don't have specific namespaces to search, we search them all
            if (namespaces == null || namespaces.Length == 0)
            {
                namespaces = settings.namespaces.Select(n => n.Key).ToArray();
            }

            foreach (var ns in namespaces)
            {
                var vms = FindViewModelSettingsInNamespace(ns, member.PropertyType(), settings);
                if (vms != null)
                {
                    // we are using the discovered view model's namespace
                    viewModel.usings.Add(vms.ViewModelNamespace());
                    if (member is CollectionDefinition)
                    {
                        (member as CollectionDefinition).typeParam = vms.type;
                    }
                    else
                    {
                        (member as PropertyDefinition).type = vms.type;
                    }

                    return; // success - we stop right here
                }
            }

            // if we get here, a view model was never found, so we are not emitting as view model
            member.EmitAsViewModel(false);
        }
Exemple #2
0
        private static void ConfigureEntityProperty(PropertyInfo propInfo, ViewModelSettings vm, List <Type> entities, MemberDefinition propDef)
        {
            var doNotEmitAsViewModel =
                propInfo.GetCustomAttribute <DoNotEmitAsViewModelAttribute>() != null;
            var emitAsViewModel = propInfo.GetCustomAttribute <EmitAsViewModelAttribute>() != null;

            var prop = propDef as PropertyDefinition;

            // if not explicitly restricted from emitting this as a view model,
            // and we are implicitly emitting entity properties as view models or there is a explicit
            // instruction to emit this property as a view model, make it so
            propDef.EmitAsViewModel(doNotEmitAsViewModel == false &&
                                    (vm.emitEntityPropertiesAsViewModels == true || emitAsViewModel == true) &&
                                    entities.Any(e => e.Name == prop.type));
        }