Posts
.NET 4.0 New Feature - System.Device.Location
GeoCoordinate location = watcher.Position.Location; if (location.IsUnknown) return; Console.WriteLine("Time: {0}", e.Position.Timestamp); Console.WriteLine("Longitude: {0}", location.Longitude); //經度 Console.WriteLine("Latitude: {0}", location.Latitude); //緯度 Console.WriteLine("Altitude: {0}", location.Altitude); //高度 Console.WriteLine("Course: {0}", location.Course); //角度 Console.WriteLine("Speed: {0}", location.Speed); //速度 CivicAddressResolver resolver = new CivicAddressResolver(); CivicAddress realLocation = m_addressResolver.ResolveAddress(location); if (realLocation.IsUnknown) return; Console.WriteLine("Address1: {0}", realLocation.AddressLine1); //實際地址 Console.WriteLine("Address2: {0}", realLocation.AddressLine2); Console.WriteLine("Building: {0}", realLocation.Building); //門牌號碼 Console.WriteLine("City: {0}", realLocation.City); //縣市 Console.WriteLine("CountryRegion: {0}", realLocation.CountryRegion); //國家 Console.WriteLine("PostalCode: {0}", realLocation.PostalCode); //郵遞區號 Console.WriteLine("StateProvince: {0}", realLocation.StateProvince); //省份 Console.
read morePosts
使用反射(Reflection)實現應用程式擴充元件機制
public IHost Host { get { return _host; } set { _host = value; } } public PlugInController(IHost host) { this.Host = host; } IModule GetModule(Assembly asm, string fullTypeName) { Type t = asm.GetType(fullTypeName); IModule module = null; if (!(t.IsNotPublic || t.IsAbstract)) { object objInterface = t.GetInterface("IModule", true); if (objInterface != null) { module = asm.CreateInstance(t.FullName) as IModule; module.Host = Host; return module; } } return null; } IModule GetModule(Assembly asm, Type moduleType) { return GetModule(asm, moduleType.
read morePosts
.Net 4.0 New Feature - SortedSet
int[] array = new int[setData1.Count]; setData1.CopyTo(array); foreach (var value in array) setData1.Add(value); System.Console.WriteLine("setData1"); System.Console.WriteLine(string.Join(",", setData1)); System.Console.WriteLine("setData2"); System.Console.WriteLine(string.Join(",", setData2)); System.Console.WriteLine("setData1 IsSubsetOf setData2"); System.Console.WriteLine(string.Join(",", setData1.IsSubsetOf(setData2))); System.Console.WriteLine("setData1 Overlaps setData2"); System.Console.WriteLine(string.Join(",", setData1.Overlaps(setData2))); System.Console.WriteLine("setData1 UnionWith setData2"); var setUnion = new SortedSet<int>(setData1); setUnion.UnionWith(setData2); System.Console.WriteLine(string.Join(",", setUnion)); System.Console.WriteLine("(setData1 UnionWith setData2) Reverse"); System.Console.WriteLine(string.Join(",", setUnion.Reverse())); System.Console.WriteLine("(setData1 UnionWith setData2) Min"); System.Console.WriteLine(string.Join(",", setUnion.Min)); System.Console.WriteLine("(setData1 UnionWith setData2) Max"); System.Console.WriteLine(string.Join(",", setUnion.Max)); System.Console.WriteLine("(setData1 UnionWith setData2) GetViewBetween({0},{1})", (setUnion.Min + setUnion.Max) / 2, setUnion.Max); System.Console.WriteLine(string.Join(",", setUnion.GetViewBetween((setUnion.Min + setUnion.
read more