Пример #1
0
        public object GetValue(ObtainMode obtainMode, Builders.BuilderSettings settings = null)
        {
            switch (obtainMode)
            {
            case ObtainMode.Alway:
                //注意:当获取方式为始终创建新的实例时,必须忽略后续的追加操作,
                //以避免将重复新建的实例追加到所有者集合中可能导致的集合项键冲突的错误。

                if (settings == null)
                {
                    settings = Builders.BuilderSettings.Ignores(Builders.BuilderSettingsFlags.IgnoreAppending);
                }
                else
                {
                    settings.SetFlags(Builders.BuilderSettingsFlags.IgnoreAppending);
                }

                return(this.Build(settings));

            case ObtainMode.Auto:
                if (_value == null)
                {
                    lock (_syncRoot)
                    {
                        if (_value == null)
                        {
                            return(this.Build(settings));
                        }
                    }
                }
                break;
            }

            return(_value);
        }
Пример #2
0
        public static object BuildBuiltin(Builtin builtin, Builders.BuilderSettings settings, IEnumerable <string> ignoredProperties)
        {
            if (builtin == null)
            {
                throw new ArgumentNullException(nameof(builtin));
            }

            object result = null;

            if (builtin.BuiltinType != null)
            {
                result = BuildType(builtin.BuiltinType);
            }
            else
            {
                //获取所有者元素的类型,如果所有者不是泛型集合则返回空
                var type = GetOwnerElementType(builtin.Node) ?? settings?.TargetType;

                if (type == null)
                {
                    throw new PluginException($"Unable to determine the target type of the '{builtin.ToString()}' builtin.");
                }

                result = BuildType(type, builtin);
            }

            //设置更新目标对象的属性集
            if (result != null)
            {
                UpdateProperties(result, builtin, ignoredProperties);
            }

            return(result);
        }
Пример #3
0
        public object UnwrapValue(ObtainMode obtainMode, Builders.BuilderSettings settings = null)
        {
            if (_nodeType == PluginTreeNodeType.Builtin)
            {
                return(((Builtin)_value).GetValue(obtainMode, settings));
            }

            return(_value);
        }
Пример #4
0
 public object Build(Builders.BuilderSettings settings = null)
 {
     return(Builders.BuilderManager.Current.Build(this, settings));
 }
Пример #5
0
 internal static BuilderContext CreateContext(IBuilder builder, Builtin builtin, BuilderSettings settings = null, int depth = 0, object owner = null, PluginTreeNode ownerNode = null)
 {
     return(new BuilderContext(builder, builtin, settings, depth, owner, ownerNode));
 }