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


C# IRepository.GetOrAdd方法代码示例

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


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

示例1: CreateProperty

        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jObject.GetDomPath(_factory), _jObject.Properties().Any());

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
                {
                    var userDefinedClassPropertyDefinition = _factory.CreatePropertyDefinition(repository.GetOrAdd(_jObject.GetDomPath(_factory)), _name, true, true, AttributeProxy.DataMember(_name));
                    propertyDefinitions.Append(userDefinedClassPropertyDefinition);
                });

            return property;
        }
开发者ID:sethkontny,项目名称:CSharpinator,代码行数:13,代码来源:JObjectDomElement.cs

示例2: ToClass

        public IClass ToClass(IRepository repository, IFactory factory)
        {
            var userDefinedClassProxy = this as UserDefinedClassProxy;
            if (userDefinedClassProxy != null)
            {
                return repository.GetOrAdd(userDefinedClassProxy.GetDomPath(factory));
            }

            var bclClassProxy = this as BclClassProxy;
            if (bclClassProxy != null)
            {
                return BclClassProxy.ToBclClass(bclClassProxy, factory);
            }

            return ListClassProxy.ToListClass((ListClassProxy)this, repository, factory);
        }
开发者ID:sethkontny,项目名称:CSharpinator,代码行数:16,代码来源:ClassProxy.cs

示例3: CreateProperty

        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_element.GetDomPath(_factory), _element.HasElements || _element.HasAttributes || !string.IsNullOrEmpty(_element.Value));

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
                {
                    if (!_element.HasElements && !_element.HasAttributes)
                    {
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                                .Select(bclClass =>
                                    _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), bclClass.IsLegalStringValue(_element.Value), true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                    }
                    else
                    {
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                                .Select(bclClass =>
                                    _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), false, true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                    }

                    var userDefinedClassPropertyDefinition =
                        _factory.CreatePropertyDefinition(repository.GetOrAdd(_element.GetDomPath(_factory)), _element.Name.ToString(), true, true, AttributeProxy.XmlElement(_element.Name.ToString()));

                    if (_element.HasElements || _element.HasAttributes)
                    {
                        propertyDefinitions.Prepend(userDefinedClassPropertyDefinition);
                    }
                    else
                    {
                        propertyDefinitions.Append(userDefinedClassPropertyDefinition);
                    }

                    if (!_element.HasAttributes && _element.HasElements)
                    {
                        var first = _element.Elements().First();

                        if (_element.Elements().Skip(1).All(x => x.Name == first.Name))
                        {
                            var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                            xmlArraySet.IsEnabled = true;

                            var xmlArrayListPropertyDefinition =
                                    _factory.CreatePropertyDefinition(
                                        ListClass.FromClass(repository.GetOrAdd(first.GetDomPath(_factory))),
                                        first.Name.ToString(),
                                        true,
                                        true,
                                        AttributeProxy.XmlArray(_element.Name.ToString()),
                                        AttributeProxy.XmlArrayItem(first.Name.ToString()));

                            xmlArraySet.PropertyDefinitions = new List<PropertyDefinition> { xmlArrayListPropertyDefinition };

                            if (_element.Elements().Count() > 1)
                            {
                                xmlArraySet.Order = -1;
                            }
                            else
                            {
                                xmlArraySet.Order = 2;
                            }
                        }
                        else
                        {
                            if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                            {
                                var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                                xmlArraySet.IsEnabled = false;
                            }
                        }
                    }
                    else
                    {
                        if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                        {
                            var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                            xmlArraySet.IsEnabled = false;
                        }
                    }

                    var xmlElementSet = property.GetOrAddExtraPropertyDefinitionSet("xml_element_list");

                    var xmlElementListPropertyDefinitions = propertyDefinitions
                        .Where(x => !(x.Class is ListClass))
                        .Select(x =>
                            _factory.CreatePropertyDefinition(
                                ListClass.FromClass(x.Class),
                                _element.Name.ToString(),
                                x.IsLegal,
                                x.IsEnabled,
                                AttributeProxy.XmlElement(_element.Name.ToString()))
                        ).ToList();

                    xmlElementSet.PropertyDefinitions = xmlElementListPropertyDefinitions;

                    if (_element.Parent != null)
                    {
                        xmlElementSet.IsEnabled = true;

//.........这里部分代码省略.........
开发者ID:sethkontny,项目名称:CSharpinator,代码行数:101,代码来源:XmlDomElement.cs

示例4: CreateProperty

        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

            var bestFitType = GetBestFitType();

            // If JTokenType.None, then there weren't any elements.
            // If JTokenType.Null, then no JTokenType is able to contain the values of all the other elements.
            // Else, we have a JTokenType that can contain all the values of the other elements.

            // The 'else' condition is the happy path. We'll want to create a property custom tailored for
            // bestFitType. When (or if) it gets merged, the merge mechanism will ensure that we end up with
            // the best type for the property. This should be relatively easy to implement.

            // As for the sad paths, which won't be as easy to implement...

            // There's a strong possibility that we'll need to be able to determine whether a property should
            // even be added to its parent class. If there were no elements in the json array, should we
            // do anything with that array? I don't think so. And what about if no single type exists that
            // could hold all the elements? Should we do anything with *that* array? Or throw an exception?
            // Questions to ponder...

            switch (bestFitType)
            {
                case JTokenType.Null:
                case JTokenType.None:
                {
                    throw new NotImplementedException();
                }
                case JTokenType.Object:
                {
                    property.InitializeDefaultPropertyDefinitionSet(
                        propertyDefinitions =>
                        propertyDefinitions.Append(
                            _factory.CreatePropertyDefinition(
                                ListClass.FromClass(repository.GetOrAdd(_jArray.GetDomPath(_factory))),
                                _name,
                                true,
                                true,
                                AttributeProxy.DataMember(_name))));
                    break;
                }
                case JTokenType.Array:
                {
                    throw new NotImplementedException();
                }
                case JTokenType.Integer:
                case JTokenType.Float:
                case JTokenType.String:
                case JTokenType.Boolean:
                case JTokenType.Date:
                case JTokenType.Guid:
                case JTokenType.Uri:
                case JTokenType.TimeSpan:
                {
                    property.InitializeDefaultPropertyDefinitionSet(propertyDefinitions => {});

                    foreach (var item in _jArray.OfType<JValue>())
                    {
                        var mergeProperty = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

                        mergeProperty.InitializeDefaultPropertyDefinitionSet(
                            propertyDefinitions =>
                            propertyDefinitions.Append(
                                _factory.GetAllBclClasses()
                                        .Select(
                                            bclClass =>
                                            _factory.CreatePropertyDefinition(
                                                ListClass.FromClass(bclClass),
                                                _name,
                                                bclClass.IsLegalObjectValue(item.Value),
                                                true,
                                                AttributeProxy.DataMember(_name)))));

                        property.MergeWith(mergeProperty);
                    }
                    break;
                }
                default:
                {
                    throw new InvalidOperationException("Unsupported item in json array: " + bestFitType);
                }
            }

            return property;
        }
开发者ID:sethkontny,项目名称:CSharpinator,代码行数:86,代码来源:JArrayDomElement.cs


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