Skip to content

Commit 64867dd

Browse files
authored
Merge pull request #2 from yisoft/dev
code initial
2 parents 82f7c69 + 893f17e commit 64867dd

File tree

82 files changed

+7544
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+7544
-2
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.vs/
2+
tools/nuget/
3+
bin/
4+
obj/
5+
6+
*.lock.json
7+
*.user
8+
*.nupkg

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2017 Yi.Team
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

NuGet.Config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<configuration>
4+
<packageSources>
5+
<clear />
6+
<add key="nuget.cnblogs.com" value="https://nuget.cnblogs.com/v3/index.json" protocolVersion="3" />
7+
<add key="Yisoft" value="https://www.myget.org/F/yiteam/api/v3/index.json" />
8+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
9+
</packageSources>
10+
</configuration>

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
# framework
1+
# Yisoft.Framework
2+
[![Build status](https://ci.appveyor.com/api/projects/status/6ye29gat7c4rjxiu?svg=true)](https://ci.appveyor.com/project/yiteam/framework-8h9tr)
3+
[![NuGet](https://img.shields.io/nuget/v/Yisoft.Framework.svg?style=flat&label=nuget)](https://www.nuget.org/packages/Yisoft.Framework/)
4+
25
dotnet convenient development framework.
6+
7+
If you have any problems, make sure to file an issue here on Github.
8+
9+
## Related community projects
10+
* [Newtonsoft.Json](http://www.newtonsoft.com/json)
11+
12+
# License
13+
Released under the [Apache License](LICENSE).

framework.sln

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26403.7
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B7A6F3B1-5A1F-481F-AF8D-E27BF73D5A49}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{506B9CDF-EED7-4D70-9B61-F07DDDB55D2C}"
9+
ProjectSection(SolutionItems) = preProject
10+
.gitignore = .gitignore
11+
LICENSE = LICENSE
12+
NuGet.Config = NuGet.Config
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yisoft.Framework", "src\Yisoft.Framework\Yisoft.Framework.csproj", "{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3F46BBC-5065-472A-9A67-2A9C3995B4C7}"
19+
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yisoft.Framework.XUnitTest", "test\Yisoft.Framework.XUnitTest\Yisoft.Framework.XUnitTest.csproj", "{9304CEEF-A9F4-4E44-88BC-5B42DD125461}"
21+
EndProject
22+
Global
23+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
24+
Debug|Any CPU = Debug|Any CPU
25+
Release|Any CPU = Release|Any CPU
26+
EndGlobalSection
27+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
28+
{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{9304CEEF-A9F4-4E44-88BC-5B42DD125461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{9304CEEF-A9F4-4E44-88BC-5B42DD125461}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{9304CEEF-A9F4-4E44-88BC-5B42DD125461}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{9304CEEF-A9F4-4E44-88BC-5B42DD125461}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(NestedProjects) = preSolution
41+
{1A3BA719-CD2F-4C96-A3CA-F46C5AB5D84B} = {B7A6F3B1-5A1F-481F-AF8D-E27BF73D5A49}
42+
{9304CEEF-A9F4-4E44-88BC-5B42DD125461} = {D3F46BBC-5065-472A-9A67-2A9C3995B4C7}
43+
EndGlobalSection
44+
EndGlobal

framework.sln.DotSettings

Lines changed: 166 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// ) *
2+
// ( /( * ) ( ( `
3+
// )\()) ( ` ) /( ( )\ )\))(
4+
// ((_)\ )\ ( )(_)))\ ((((_)( ((_)()\
5+
// __ ((_)((_) (_(_())((_) )\ _ )\ (_()((_)
6+
// \ \ / / (_) |_ _|| __|(_)_\(_)| \/ |
7+
// \ V / | | _ | | | _| / _ \ | |\/| |
8+
// |_| |_|(_)|_| |___|/_/ \_\ |_| |_|
9+
//
10+
// This file is subject to the terms and conditions defined in
11+
// file 'License.txt', which is part of this source code package.
12+
//
13+
// Copyright © Yi.TEAM. All rights reserved.
14+
// -------------------------------------------------------------------------------
15+
16+
namespace Yisoft.Framework
17+
{
18+
/// <summary>
19+
/// 表示十二生肖的枚举值。
20+
/// </summary>
21+
public enum ChineseZodiac
22+
{
23+
/// <summary>
24+
/// 未知或未指定。
25+
/// </summary>
26+
[EnumExtra]
27+
Unknown = 0,
28+
29+
/// <summary>
30+
/// 鼠。
31+
/// </summary>
32+
[EnumExtra("鼠")]
33+
Rat = 1,
34+
35+
/// <summary>
36+
/// 牛。
37+
/// </summary>
38+
[EnumExtra("牛")]
39+
Ox = 2,
40+
41+
/// <summary>
42+
/// 虎。
43+
/// </summary>
44+
[EnumExtra("虎")]
45+
Tiger = 3,
46+
47+
/// <summary>
48+
/// 兔。
49+
/// </summary>
50+
[EnumExtra("兔")]
51+
Hare = 4,
52+
53+
/// <summary>
54+
/// 龙。
55+
/// </summary>
56+
[EnumExtra("龙")]
57+
Dragon = 5,
58+
59+
/// <summary>
60+
/// 蛇。
61+
/// </summary>
62+
[EnumExtra("蛇")]
63+
Snake = 6,
64+
65+
/// <summary>
66+
/// 马。
67+
/// </summary>
68+
[EnumExtra("马")]
69+
Horse = 7,
70+
71+
/// <summary>
72+
/// 羊。
73+
/// </summary>
74+
[EnumExtra("羊")]
75+
Sheep = 8,
76+
77+
/// <summary>
78+
/// 猴。
79+
/// </summary>
80+
[EnumExtra("猴")]
81+
Monkey = 9,
82+
83+
/// <summary>
84+
/// 鸡。
85+
/// </summary>
86+
[EnumExtra("鸡")]
87+
Cock = 10,
88+
89+
/// <summary>
90+
/// 狗。
91+
/// </summary>
92+
[EnumExtra("狗")]
93+
Dog = 11,
94+
95+
/// <summary>
96+
/// 猪。
97+
/// </summary>
98+
[EnumExtra("猪")]
99+
Boar = 12
100+
}
101+
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// ) *
2+
// ( /( * ) ( ( `
3+
// )\()) ( ` ) /( ( )\ )\))(
4+
// ((_)\ )\ ( )(_)))\ ((((_)( ((_)()\
5+
// __ ((_)((_) (_(_())((_) )\ _ )\ (_()((_)
6+
// \ \ / / (_) |_ _|| __|(_)_\(_)| \/ |
7+
// \ V / | | _ | | | _| / _ \ | |\/| |
8+
// |_| |_|(_)|_| |___|/_/ \_\ |_| |_|
9+
//
10+
// This file is subject to the terms and conditions defined in
11+
// file 'License.txt', which is part of this source code package.
12+
//
13+
// Copyright © Yi.TEAM. All rights reserved.
14+
// -------------------------------------------------------------------------------
15+
16+
using System;
17+
using System.Collections;
18+
using System.Collections.Generic;
19+
20+
namespace Yisoft.Framework.Collections.Generic
21+
{
22+
public class BidirectionalDictionary<TKey, TValue> : IDictionary<TKey, TValue>
23+
{
24+
private readonly IEqualityComparer<TKey> _keyComparer;
25+
private readonly Dictionary<TKey, TValue> _keysToValues;
26+
private readonly IEqualityComparer<TValue> _valueComparer;
27+
private readonly Dictionary<TValue, TKey> _valuesToKeys;
28+
29+
public BidirectionalDictionary() : this(10, null, null) { }
30+
31+
public BidirectionalDictionary(int capacity) : this(capacity, null, null) { }
32+
33+
public BidirectionalDictionary(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
34+
: this(10, keyComparer, valueComparer)
35+
{
36+
}
37+
38+
public BidirectionalDictionary(int capacity, IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
39+
{
40+
if (capacity < 0) throw new ArgumentOutOfRangeException(nameof(capacity), capacity, "capacity cannot be less than 0");
41+
42+
_keyComparer = keyComparer ?? EqualityComparer<TKey>.Default;
43+
_valueComparer = valueComparer ?? EqualityComparer<TValue>.Default;
44+
45+
_keysToValues = new Dictionary<TKey, TValue>(capacity, _keyComparer);
46+
_valuesToKeys = new Dictionary<TValue, TKey>(capacity, _valueComparer);
47+
48+
Inverse = new BidirectionalDictionary<TValue, TKey>(this);
49+
}
50+
51+
private BidirectionalDictionary(BidirectionalDictionary<TValue, TKey> inverse)
52+
{
53+
Inverse = inverse ?? throw new ArgumentNullException(nameof(inverse));
54+
_keyComparer = inverse._valueComparer;
55+
_valueComparer = inverse._keyComparer;
56+
_valuesToKeys = inverse._keysToValues;
57+
_keysToValues = inverse._valuesToKeys;
58+
}
59+
60+
public BidirectionalDictionary<TValue, TKey> Inverse { get; }
61+
62+
public ICollection<TKey> Keys => _keysToValues.Keys;
63+
64+
public ICollection<TValue> Values => _keysToValues.Values;
65+
66+
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() { return _keysToValues.GetEnumerator(); }
67+
68+
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
69+
70+
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
71+
{
72+
((ICollection<KeyValuePair<TKey, TValue>>) _keysToValues).CopyTo(array, arrayIndex);
73+
}
74+
75+
public bool ContainsKey(TKey key)
76+
{
77+
return key == null
78+
? throw new ArgumentNullException(nameof(key))
79+
: _keysToValues.ContainsKey(key);
80+
}
81+
82+
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
83+
{
84+
return ((ICollection<KeyValuePair<TKey, TValue>>) _keysToValues).Contains(item);
85+
}
86+
87+
public bool TryGetValue(TKey key, out TValue value)
88+
{
89+
return key == null
90+
? throw new ArgumentNullException(nameof(key))
91+
: _keysToValues.TryGetValue(key, out value);
92+
}
93+
94+
public TValue this[TKey key]
95+
{
96+
get => _keysToValues[key];
97+
set
98+
{
99+
if (key == null) throw new ArgumentNullException(nameof(key));
100+
if (value == null) throw new ArgumentNullException(nameof(value));
101+
102+
if (_ValueBelongsToOtherKey(key, value)) throw new ArgumentException("Value already exists", nameof(value));
103+
104+
105+
if (_keysToValues.TryGetValue(key, out TValue oldValue))
106+
{
107+
var oldKey = _valuesToKeys[oldValue];
108+
109+
_keysToValues[oldKey] = value;
110+
_valuesToKeys.Remove(oldValue);
111+
_valuesToKeys[value] = oldKey;
112+
}
113+
else
114+
{
115+
_keysToValues[key] = value;
116+
_valuesToKeys[value] = key;
117+
}
118+
}
119+
}
120+
121+
public int Count => _keysToValues.Count;
122+
123+
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => false;
124+
125+
public void Add(TKey key, TValue value)
126+
{
127+
if (key == null) throw new ArgumentNullException(nameof(key));
128+
if (value == null) throw new ArgumentNullException(nameof(value));
129+
130+
if (_keysToValues.ContainsKey(key)) throw new ArgumentException("Key already exists", nameof(key));
131+
if (_valuesToKeys.ContainsKey(value)) throw new ArgumentException("Value already exists", nameof(value));
132+
133+
_keysToValues.Add(key, value);
134+
_valuesToKeys.Add(value, key);
135+
}
136+
137+
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) { Add(item.Key, item.Value); }
138+
139+
public bool Remove(TKey key)
140+
{
141+
if (key == null) throw new ArgumentNullException("ke" + "y");
142+
143+
if (!_keysToValues.TryGetValue(key, out TValue value)) return false;
144+
145+
_keysToValues.Remove(key);
146+
_valuesToKeys.Remove(value);
147+
148+
return true;
149+
}
150+
151+
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
152+
{
153+
var removed = ((ICollection<KeyValuePair<TKey, TValue>>) _keysToValues).Remove(item);
154+
155+
if (removed) _valuesToKeys.Remove(item.Value);
156+
157+
return removed;
158+
}
159+
160+
public void Clear()
161+
{
162+
_keysToValues.Clear();
163+
_valuesToKeys.Clear();
164+
}
165+
166+
public TValue GetValue(TKey key) { return TryGetValue(key, out TValue value) ? value : default(TValue); }
167+
168+
public bool ContainsValue(TValue value)
169+
{
170+
return value == null
171+
? throw new ArgumentNullException(nameof(value))
172+
: _valuesToKeys.ContainsKey(value);
173+
}
174+
175+
public TKey GetKey(TValue value) { return TryGetKey(value, out TKey key) ? key : default(TKey); }
176+
177+
public bool TryGetKey(TValue value, out TKey key)
178+
{
179+
return value == null
180+
? throw new ArgumentNullException(nameof(value))
181+
: _valuesToKeys.TryGetValue(value, out key);
182+
}
183+
184+
public void Replace(TKey key, TValue value)
185+
{
186+
if (key == null) throw new ArgumentNullException(nameof(key));
187+
if (value == null) throw new ArgumentNullException(nameof(value));
188+
189+
Remove(key);
190+
191+
Inverse.Remove(value);
192+
193+
Add(key, value);
194+
}
195+
196+
private bool _ValueBelongsToOtherKey(TKey key, TValue value)
197+
{
198+
return _valuesToKeys.TryGetValue(value, out TKey otherKey) && !_keyComparer.Equals(key, otherKey);
199+
}
200+
}
201+
}

0 commit comments

Comments
 (0)