예제 #1
0
        public UnionContext(TypeInfo rootType)
        {
            var unionKeyAttribute = rootType.GetCustomAttribute <UnionKeyAttribute>();

            _propertyName           = unionKeyAttribute.Key;
            _camelCasePropertyName  = Inflector.Camelize(_propertyName);
            _pascalCasePropertyName = Inflector.Pascalize(_propertyName);
            _dashCasePropertyName   = Inflector.Kebaberize(_propertyName);
            _enumType     = UnionHelper.GetUnionEnumType(rootType);
            _enumTypeList = UnionHelper.GetUnion(rootType);
        }
예제 #2
0
        private UnionContext GetContext(Type type)
        {
            if (!_contexts.TryGetValue(type, out var context))
            {
                var rootType = UnionHelper.GetRootType(type);
                if (rootType != null)
                {
                    if (!_contexts.TryGetValue(rootType.AsType(), out var rootContext))
                    {
                        rootContext = _contexts[rootType.AsType()] = new UnionContext(rootType);
                    }
                    context = _contexts[type] = rootContext;
                }
            }

            return(context);
        }