2 using System.Collections.Generic;
8 using System.Xml.Serialization;
21 set { _Type = value; }
29 string N =
"{0}.{1}".Build(
Type.Namespace,
Type.Name);
30 if (VSXmlDocu.TypeSummary.ContainsKey(N))
32 return VSXmlDocu.TypeSummary[N];
45 S +=
"\\section use_{0}_{1} {1}\n\n".Build(
NamespaceName.Replace(
".",
"_"),
Name);
47 if (!
Summary.IsNullOrWhiteSpace())
49 S +=
"\\subsection use_{0}_{1}_summary Summary\n\n".Build(
NamespaceName.Replace(
".",
"_"),
Name);
55 if (!Xml.IsNullOrWhiteSpace())
57 S +=
"\\subsection use_{0}_{1}_samplexml Sample XML\n\n".Build(
NamespaceName.Replace(
".",
"_"),
Name);
58 S +=
"A configuration section for {0} might resemble the following structure:\n\n".Build(
Name);
59 S +=
"~~~~~~~~~~~~~{.xml}\n";
61 S +=
"\n~~~~~~~~~~~~~\n";
65 PDL.Sort((PDD1, PDD2) => PDD1.Name.CompareTo(PDD2.Name));
68 S +=
"\\subsection use_{0}_{1}_properties Properties\n\n".Build(
NamespaceName.Replace(
".",
"_"),
Name);
69 S +=
"{0} has the following {1} configurable properties:\n\n".Build(
Name, PDL.Count);
86 public string Name {
get {
return Type.Name; } }
95 object O = GetSampleReferenceType(
Type);
100 using (MemoryStream ms =
new MemoryStream())
103 XmlSerializerNamespaces Namespaces =
new XmlSerializerNamespaces();
104 Namespaces.Add(
string.Empty,
string.Empty);
105 new XmlSerializer(
Type).Serialize(ms, O, Namespaces);
107 using (StreamReader sr =
new StreamReader(ms, Encoding.Default))
109 Xml = sr.ReadToEnd();
114 Xml = Xml.Substring(Xml.IndexOf(
"\n") + 1);
124 List<PropertyDocuData> L =
new List<PropertyDocuData>();
125 foreach (PropertyInfo PI
in Type.GetXMLSerializableProperties())
139 private object GetSampleReferenceType(
Type RefType)
156 Object O = Activator.CreateInstance(T);
159 foreach (PropertyInfo PI
in O.GetType().GetXMLSerializableProperties())
161 if (PI.PropertyType.IsGenericList())
164 IList EN = GetSampleGenericList(PI.PropertyType);
165 PI.SetValue(O, EN, null);
167 else if (PI.PropertyType == typeof(
string))
170 if (PI.ReflectedType.IsGenericList())
172 PI.ReflectedType.GetMethod(
"Add").Invoke(O,
new[] {
"Item" });
173 PI.ReflectedType.GetMethod(
"Add").Invoke(O,
new[] {
"Item" });
177 string V = (string)PI.GetValue(O, null);
180 if (V.IsNullOrWhiteSpace())
182 if (PI.Name.ToUpper() ==
"NAME")
184 PI.SetValue(O,
"Name of {0}".Build(O.GetType().Name), null);
186 else if (PI.Name.ToUpper().EndsWith(
"NAME"))
188 PI.SetValue(O,
"Name of {0}".Build(PI.Name.Substring(0, PI.Name.Length - 4)), null);
192 PI.SetValue(O,
"{0} string".Build(PI.Name), null);
197 else if (PI.PropertyType.IsArray)
199 object A = PI.GetValue(O, null);
202 object[] SampleArray = GetSampleArray(PI.PropertyType);
203 PI.SetValue(O, SampleArray, null);
207 else if (typeof(IDictionary).IsAssignableFrom(PI.PropertyType) && PI.PropertyType.IsGenericType)
209 IDictionary EN = GetSampleGenericDictionary(PI.PropertyType);
210 PI.SetValue(O, EN, null);
212 else if (PI.PropertyType.IsValueType)
214 if (PI.PropertyType == typeof(
char))
216 PI.SetValue(O, GetSampleValueType(PI.PropertyType), null);
219 else if (PI.PropertyType == typeof(DateTime))
221 PI.SetValue(O, DateTime.Now, null);
223 else if (PI.PropertyType == typeof(TimeSpan))
225 PI.SetValue(O, TimeSpan.Zero, null);
227 else if (!PI.PropertyType.IsValueType)
229 PI.SetValue(O, GetSampleReferenceType(PI.PropertyType), null);
233 throw new Exception(
"Unknow type {0}".Build(PI.PropertyType.Name));
241 private object[] GetSampleArray(
System.Type type)
246 object[] A = (
object[])Array.CreateInstance(typeof(
object), 3);
248 Type GT = type.GetElementType();
250 for (
int i = 0; i < 3; i++)
255 G = GetSampleValueType(GT);
259 G = GetSampleReferenceType(GT);
273 private IDictionary GetSampleGenericDictionary(
System.Type T)
275 if (!(typeof(IDictionary).IsAssignableFrom(T) && T.IsGenericType))
return null;
276 IDictionary C = (IDictionary)Activator.CreateInstance(T);
277 if (T.GetGenericArguments().Length == 2)
279 Type KT = T.GetGenericArguments()[0];
280 Type VT = T.GetGenericArguments()[1];
283 for (
int i = 0; i < 3; i++)
285 if (KT == typeof(
string))
287 K =
"Key {0}".Build(i);
289 else if (KT.IsValueType)
291 K = GetSampleValueType(KT);
294 K = Convert.ChangeType(i, KT);
299 K = GetSampleReferenceType(KT);
301 if (VT == typeof(
string))
303 V =
"Value {0}".Build(i);
305 else if (KT.IsValueType)
307 V = GetSampleValueType(KT);
310 K = Convert.ChangeType(i, KT);
315 V = GetSampleReferenceType(KT);
328 private IList GetSampleGenericList(
Type T)
330 if (!(typeof(IList).IsAssignableFrom(T)))
return null;
331 IList C = (IList)Activator.CreateInstance(T);
336 Type GT = T.GetGetGenericCollectionTypeArguments()[0];
338 for (
int i = 0; i < 3; i++)
343 G = GetSampleValueType(GT);
347 G = GetSampleReferenceType(GT);
356 private object GetSampleValueType(
Type T)
358 if (!T.IsValueType)
return null;
360 object O = Activator.CreateInstance(T);
361 if (T == typeof(
char))
List< PropertyDocuData > GetPropertyDocuDataList()
The namespace DirectOutput.General contains classes for general use.